pierluigiferrari / ssd_keras

A Keras port of Single Shot MultiBox Detector
Apache License 2.0
1.86k stars 935 forks source link

ValueError when fit_generator: Error when checking input: expected input_1 to have 4 dimensions, but got array with shape (16, 1) #306

Closed altomanscott closed 4 years ago

altomanscott commented 4 years ago

Please help me, I ran the ssd7_training.ipynb. I have preprocessed to parse the label_train.csv and label_test.csv which have 327 and 141 rows respectively, but the HDF5 dataset generation is 171 and 95. I think I have followed the input format which is 'image_name', 'xmin', 'xmax', 'ymin', 'ymax', 'class_id'. After that when I ran model.fit_generator(), it says the array shape is not correct. I have looked around the DataGenerator and tried different version of Keras and Tensorflow still I could not figured out what is wrong, please help me!

WARNING:tensorflow:From /Users/ivexu/opt/anaconda3/envs/ocr/lib/python3.6/site-packages/tensorflow/python/ops/math_grad.py:102: div (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Deprecated in favor of operator or tf.math.divide.
Epoch 1/20
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-7-c43c96b01be4> in <module>
     11                               validation_data=val_generator,
     12                               validation_steps=ceil(val_dataset_size/batch_size),
---> 13                               initial_epoch=initial_epoch)

~/opt/anaconda3/envs/ocr/lib/python3.6/site-packages/keras/legacy/interfaces.py in wrapper(*args, **kwargs)
     89                 warnings.warn('Update your `' + object_name +
     90                               '` call to the Keras 2 API: ' + signature, stacklevel=2)
---> 91             return func(*args, **kwargs)
     92         wrapper._original_function = func
     93         return wrapper

~/opt/anaconda3/envs/ocr/lib/python3.6/site-packages/keras/engine/training.py in fit_generator(self, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch)
   2222                     outs = self.train_on_batch(x, y,
   2223                                                sample_weight=sample_weight,
-> 2224                                                class_weight=class_weight)
   2225 
   2226                     if not isinstance(outs, list):

~/opt/anaconda3/envs/ocr/lib/python3.6/site-packages/keras/engine/training.py in train_on_batch(self, x, y, sample_weight, class_weight)
   1875             x, y,
   1876             sample_weight=sample_weight,
-> 1877             class_weight=class_weight)
   1878         if self.uses_learning_phase and not isinstance(K.learning_phase(), int):
   1879             ins = x + y + sample_weights + [1.]

~/opt/anaconda3/envs/ocr/lib/python3.6/site-packages/keras/engine/training.py in _standardize_user_data(self, x, y, sample_weight, class_weight, check_array_lengths, batch_size)
   1474                                     self._feed_input_shapes,
   1475                                     check_batch_axis=False,
-> 1476                                     exception_prefix='input')
   1477         y = _standardize_input_data(y, self._feed_output_names,
   1478                                     output_shapes,

~/opt/anaconda3/envs/ocr/lib/python3.6/site-packages/keras/engine/training.py in _standardize_input_data(data, names, shapes, check_batch_axis, exception_prefix)
    111                         ': expected ' + names[i] + ' to have ' +
    112                         str(len(shape)) + ' dimensions, but got array '
--> 113                         'with shape ' + str(data_shape))
    114                 if not check_batch_axis:
    115                     data_shape = data_shape[1:]

ValueError: Error when checking input: expected input_1 to have 4 dimensions, but got array with shape (16, 1)
dsnsabari commented 4 years ago

how did u resolve it?