2
votes

I have a working model, and I wish to begin using validation_split(=~0.1) to do my validation 'on the fly'. When I pass a validation_split other than 0.0, I get an error.

I have been tweaking the batch_size value that I pass to fit() as well as the one I pass to tf.keras.layers.Conv2D(), essentially making it proportional. No joy.

Here be how I make my model:


    def make_convnet_model(flags, shape):
        model = tf.keras.models.Sequential(
            [
                tf.keras.layers.Conv2D(32,(8,8), strides=2, activation='relu',input_shape=shape,batch_size=flags.batch_size,name='conv2d_1'),
                tf.keras.layers.Conv2D(24, (4,4), strides=1, activation='relu',name='conv2d_2'),
                tf.keras.layers.MaxPool2D(),
                tf.keras.layers.Conv2D(16, (3, 3), strides=2, activation='sigmoid', input_shape=shape,batch_size=flags.batch_size, name='conv2d_3'),
                tf.keras.layers.Conv2D(8, (3, 3), strides=1, activation='sigmoid', name='conv2d_4'),
                tf.keras.layers.MaxPool2D(),
                tf.keras.layers.Flatten(),
                tf.keras.layers.Dense(64, activation='sigmoid', name='d3'),
                tf.keras.layers.Dense(5, activation='softmax', name='softmax_d4')
            ])

        return model

Here is how I call fit():

    history = model.fit(x=X, y=Y, batch_size=flags.batch_size, epochs=flags.epochs, callbacks=[tensorboard,logger], verbose=flags.verbosity, validation_split=flags.validation_split)
     Here is my reward. I have taken out some of the spooge:
Namespace(***batch_size=20***, columns=320, csv_path='../csv/', data_path='f:/downloads/aptos2019-blindness-detection/', epochs=2,

gray=False, learning_rate=0.001, loss='mean_squared_error', metric=['accuracy'], model='conv2d', rows=320, test_path_fragment='test_images/', train_path_fragment='train_images/', validation_split=0.1, verbosity=2) Tensorflow version:1.14.0

Processed data path:f:/downloads/aptos2019-blindness-detection/train_images/color_320x320/
***Train on 18 samples, validate on 2 samples***
Epoch 1/2
Traceback (most recent call last):
  File "F:/projects/retinas/retina.py", line 212, in <module>
    main(sys.argv)
  File "F:/projects/retinas/retina.py", line 122, in main
    history = model.fit(x=X, y=Y, batch_size=flags.batch_size, epochs=flags.epochs, callbacks=[tensorboard,logger],

verbose=flags.verbosity, validation_split=flags.validation_split) File "C:\Users\WascallyWabbit\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\keras\engine\training.py", line 780, in fit steps_name='steps_per_epoch') File "C:\Users\WascallyWabbit\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\keras\engine\training_arrays.py", line 363, in model_iteration batch_outs = f(ins_batch) File "C:\Users\WascallyWabbit\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\keras\backend.py", line 3292, in call run_metadata=self.run_metadata) File "C:\Users\WascallyWabbit\AppData\Local\Programs\Python\Python36\lib\site-packages\tensorflow\python\client\session.py", line 1458, in call run_metadata_ptr) tensorflow.python.framework.errors_impl.InvalidArgumentError: Incompatible shapes: [20,5] vs. [18,5] [[{{node Adam/gradients/loss/softmax_d4_loss/SquaredDifference_grad/BroadcastGradientArgs}}]]

1

1 Answers

0
votes

The problem turns out to have stemmed from unnecessarily specifying a batch_size in my call to Conv2D(). I now accept the default for that parameter, and it is working.

Not sure why. Don't really care :-|