Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Training Resnet50 with grayscale images:ValueError: Error when checking input: expected input_2 to have shape (256, 256, 3) but got array with shape (256, 256, 1) #9739

Closed
2 of 4 tasks
mohapatras opened this issue Mar 23, 2018 · 2 comments

Comments

@mohapatras
Copy link

Please make sure that the boxes below are checked before you submit your issue. If your issue is an implementation question, please ask your question on StackOverflow or join the Keras Slack channel and ask there instead of filing a GitHub issue.

Thank you!

  • Check that you are up-to-date with the master branch of Keras. You can update with:
    pip install git+git://github.com/keras-team/keras.git --upgrade --no-deps

  • If running on TensorFlow, check that you are up-to-date with the latest version. The installation instructions can be found here.

  • If running on Theano, check that you are up-to-date with the master branch of Theano. You can update with:
    pip install git+git://github.com/Theano/Theano.git --upgrade --no-deps

  • Provide a link to a GitHub Gist of a Python script that can reproduce your issue (or just copy the script here if it is short).

I am trying to use resnet50 with grayscale images from scratch. However it is unclear why the network is expecting channels of 3 while in Input channel 1 is passed. Below is the error I am facing and the reproducible code is in the gist.

Configurations:
Tensorflow : 1.5.0
Keras : 2.1.5
Python : 3.6

Link provided: https://gist.github.com/mohapatras/5d720cb19014ed573bcd3ed36c5929f5

Epoch 1/10
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-15-b715f267337b> in <module>()
      3                            steps_per_epoch=steps_per_epoch,
      4                            validation_data = generator_test,
----> 5                            validation_steps = steps_test)

~/keras/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

~/keras/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)
   2225                     outs = self.train_on_batch(x, y,
   2226                                                sample_weight=sample_weight,
-> 2227                                                class_weight=class_weight)
   2228 
   2229                     if not isinstance(outs, list):

~/keras/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.]

~/keras/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,

~/keras/keras/engine/training.py in _standardize_input_data(data, names, shapes, check_batch_axis, exception_prefix)
    121                             ': expected ' + names[i] + ' to have shape ' +
    122                             str(shape) + ' but got array with shape ' +
--> 123                             str(data_shape))
    124     return data
    125 

ValueError: Error when checking input: expected input_2 to have shape (256, 256, 3) but got array with shape (256, 256, 1)


Any suggestion and fix is highly welcome.

@Dref360
Copy link
Contributor

Dref360 commented Mar 23, 2018

Hi!
This issue isn't related to a bug/enhancement/feature request or other accepted types of issue.

To ask questions, please see the following resources :

Thanks!

If you think I made an error, please re-open this issue.

@Dref360 Dref360 closed this as completed Mar 23, 2018
@kevinkit
Copy link

@mohapatras you need to specify weights=None when loading the application

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants