0

I have a model defined as such:

model = Model(inputs=[inputs, y_true, is_weight], outputs=[y_pred])

I want to specify the training and validation data, since I am performing k-fold cross-validation and I have predefined the splits beforehand. I fit the model as follows:

model.fit([X_train,  Y_train, wgt_map_train], batch_size=1, epochs=200,
              validation_data = [X_val, Y_val, wgt_map_val],
                    callbacks = [checkpointer, earlystopper])

The shapes of the input both for training and validation are the same, except for the first dimension:

X_train.shape = (6732, 12, 86, 98, 1)
X_val.shape = (765, 12, 86, 98, 1)
etc.

However, when I run the code, I get the following error:

~/miniconda3/envs/segment/lib/python3.7/site-packages/keras/engine/training.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, **kwargs)
    970                 val_x, val_y,
    971                 sample_weight=val_sample_weight,
--> 972                 batch_size=batch_size)
    973             if self._uses_dynamic_learning_phase():
    974                 val_ins = val_x + val_y + val_sample_weights + [0.]

~/miniconda3/envs/segment/lib/python3.7/site-packages/keras/engine/training.py in _standardize_user_data(self, x, y, sample_weight, class_weight, check_array_lengths, batch_size)
    749             feed_input_shapes,
    750             check_batch_axis=False,  # Don't enforce the batch size.
--> 751             exception_prefix='input')
    752 
    753         if y is not None:

~/miniconda3/envs/segment/lib/python3.7/site-packages/keras/engine/training_utils.py in standardize_input_data(data, names, shapes, check_batch_axis, exception_prefix)
    100                 'Expected to see ' + str(len(names)) + ' array(s), '
    101                 'but instead got the following list of ' +
--> 102                 str(len(data)) + ' arrays: ' + str(data)[:200] + '...')
    103         elif len(names) > 1:
    104             raise ValueError(

ValueError: Error when checking model input: the list of Numpy arrays that you are passing to your model is not the size the model expected. Expected to see 3 array(s), but instead got the following list of 1 arrays: [array([[[[[0.        ],
          [0.        ],
          [0.        ],
          ...,
          [0.        ],
          [0.        ],
          [0.        ]],

         [[0.        ],
          [0. ...

If I remove validation_data and I replace it for validation_split = 0.1 works, but then this would not be an adequate way of doing k-fold CV. Thanks!

EDIT I have also tried adding 'validation_batch_size = 1' in model.fit, but then I get prompted with:

TypeError                                 Traceback (most recent call last)
<ipython-input-46-eefd2297c992> in <module>
     42               validation_data = [X_val, Y_val, wgt_map_val],
     43               validation_batch_size = 1,
---> 44                     callbacks = [checkpointer, earlystopper,tb])
     45     time2=time()
     46 

~/miniconda3/envs/segment/lib/python3.7/site-packages/keras/engine/training.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, **kwargs)
    940             epochs = kwargs.pop('nb_epoch')
    941         if kwargs:
--> 942             raise TypeError('Unrecognized keyword arguments: ' + str(kwargs))
    943         if x is None and y is None and steps_per_epoch is None:
    944             raise ValueError('If fitting from data tensors, '

TypeError: Unrecognized keyword arguments: {'validation_batch_size': 1}

I have checked similar posts like: Deep Learning fit error (the list of Numpy arrays that you are passing to your model is not the size the model expected.) and Keras functional model with multiple inputs

Daniel
  • 471
  • 3
  • 8
  • 18

0 Answers0