ValueError: Error when checking input: expected conv2d_13_input to have shape (3, 150, 150) but got array with shape (150, 150, 3) Unicorn Meta Zoo #1: Why another podcast? Announcing the arrival of Valued Associate #679: Cesar Manara 2019 Moderator Election Q&A - Questionnaire 2019 Community Moderator Election ResultsError when checking : expected dense_1_input to have shape (None, 5) but got array with shape (200, 1)ValueError: Error when checking input: expected lstm_41_input to have 3 dimensions, but got array with shape (40000,100)ValueError: Error when checking target: expected dense_1 to have shape (7,) but got array with shape (1,)ValueError: Error when checking target: expected dense_2 to have shape (1,) but got array with shape (0,)Keras exception: ValueError: Error when checking input: expected conv2d_1_input to have shape (150, 150, 3) but got array with shape (256, 256, 3)Value error in Merging two different models in kerasSteps taking too long to completewhen checking input: expected dense_1_input to have shape (13328,) but got array with shape (317,)ValueError: Error when checking target: expected dense_3 to have shape (None, 1) but got array with shape (7715, 40000)Keras exception: Error when checking input: expected dense_input to have shape (2,) but got array with shape (1,)

What's the difference between using dependency injection with a container and using a service locator?

How does the mezzoloth's teleportation work?

My bank got bought out, am I now going to have to start filing tax returns in a different state?

What does a straight horizontal line above a few notes, after a changed tempo mean?

Has a Nobel Peace laureate ever been accused of war crimes?

Implementing 3DES algorithm in Java: is my code secure?

What is purpose of DB Browser(dbbrowser.aspx) under admin tool?

Air bladders in bat-like skin wings for better lift?

How to have a sharp product image?

Raising a bilingual kid. When should we introduce the majority language?

Does Mathematica have an implementation of the Poisson binomial distribution?

Why didn't the Space Shuttle bounce back into space as many times as possible so as to lose a lot of kinetic energy up there?

Protagonist's race is hidden - should I reveal it?

Is there metaphorical meaning of "aus der Haft entlassen"?

Character Optimization: Shillelagh Whirlwind

What is this word supposed to be?

Was Dennis Ritchie being too modest in this quote about C and Pascal?

Multiple fireplaces in an apartment building?

Co-worker works way more than he should

A faster way to compute the largest prime factor

Long vowel quality before R

I preordered a game on my Xbox while on the home screen of my friend's account. Which of us owns the game?

Putting Ant-Man on house arrest

A strange hotel



ValueError: Error when checking input: expected conv2d_13_input to have shape (3, 150, 150) but got array with shape (150, 150, 3)



Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar Manara
2019 Moderator Election Q&A - Questionnaire
2019 Community Moderator Election ResultsError when checking : expected dense_1_input to have shape (None, 5) but got array with shape (200, 1)ValueError: Error when checking input: expected lstm_41_input to have 3 dimensions, but got array with shape (40000,100)ValueError: Error when checking target: expected dense_1 to have shape (7,) but got array with shape (1,)ValueError: Error when checking target: expected dense_2 to have shape (1,) but got array with shape (0,)Keras exception: ValueError: Error when checking input: expected conv2d_1_input to have shape (150, 150, 3) but got array with shape (256, 256, 3)Value error in Merging two different models in kerasSteps taking too long to completewhen checking input: expected dense_1_input to have shape (13328,) but got array with shape (317,)ValueError: Error when checking target: expected dense_3 to have shape (None, 1) but got array with shape (7715, 40000)Keras exception: Error when checking input: expected dense_input to have shape (2,) but got array with shape (1,)










0












$begingroup$


I am trying to train the model, I keep ending up with this ValueError:




ValueError: Error when checking input: expected conv2d_13_input to have shape (3, 150, 150) but got array with shape (150, 150, 3)




How can I fix this? Should I use numpy.resize or cv2.resize to change the dimensions to (3,150,150). If so, how would I resize it in the generator?



Here is my code:



train_datagen = ImageDataGenerator(
rescale=1./255,
shear_range=0.2,
zoom_range=0.2)

test_datagen = ImageDataGenerator(rescale=1./255)

from keras.models import Sequential
from keras.layers import Conv2D, MaxPooling2D
from keras.layers import Activation, Dropout, Flatten, Dense

model = Sequential()
model.add(Conv2D(32, (3, 3), input_shape=(3, 150, 150),padding='same'))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2),padding='same'))

model.add(Conv2D(32, (3, 3),padding='same'))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2),padding='same'))

model.add(Conv2D(64, (3, 3),padding='same'))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2),padding='same'))

model.add(Flatten()) # this converts our 3D feature maps to 1D feature vectors
model.add(Dense(64))
model.add(Activation('relu'))
model.add(Dropout(0.5))
model.add(Dense(1))
model.add(Activation('sigmoid'))

model.compile(loss='binary_crossentropy',
optimizer='rmsprop',
metrics=['accuracy'])

batch_size = 64

# this is a generator that will read pictures found in
# subfolers of 'data/train', and indefinitely generate
# batches of augmented image data
train_generator = train_datagen.flow_from_directory(
'C:\Users\Zahid\Desktop\Dataset\train', # this is the target directory
target_size=(150, 150), # all images will be resized to 150x150
batch_size=batch_size,
color_mode='rgb',
class_mode='binary') # since we use binary_crossentropy loss, we need binary labels

# this is a similar generator, for validation data
validation_generator = test_datagen.flow_from_directory(
'C:\Users\Zahid\Desktop\Dataset\val',
target_size=(150, 150),
batch_size=batch_size,
color_mode='rgb',
class_mode='binary')

model.fit_generator(
train_generator,
steps_per_epoch=2000 // batch_size,
epochs=50,
validation_data=validation_generator,
validation_steps=800 // batch_size)
model.save_weights('first_try.h5')









share|improve this question











$endgroup$
















    0












    $begingroup$


    I am trying to train the model, I keep ending up with this ValueError:




    ValueError: Error when checking input: expected conv2d_13_input to have shape (3, 150, 150) but got array with shape (150, 150, 3)




    How can I fix this? Should I use numpy.resize or cv2.resize to change the dimensions to (3,150,150). If so, how would I resize it in the generator?



    Here is my code:



    train_datagen = ImageDataGenerator(
    rescale=1./255,
    shear_range=0.2,
    zoom_range=0.2)

    test_datagen = ImageDataGenerator(rescale=1./255)

    from keras.models import Sequential
    from keras.layers import Conv2D, MaxPooling2D
    from keras.layers import Activation, Dropout, Flatten, Dense

    model = Sequential()
    model.add(Conv2D(32, (3, 3), input_shape=(3, 150, 150),padding='same'))
    model.add(Activation('relu'))
    model.add(MaxPooling2D(pool_size=(2, 2),padding='same'))

    model.add(Conv2D(32, (3, 3),padding='same'))
    model.add(Activation('relu'))
    model.add(MaxPooling2D(pool_size=(2, 2),padding='same'))

    model.add(Conv2D(64, (3, 3),padding='same'))
    model.add(Activation('relu'))
    model.add(MaxPooling2D(pool_size=(2, 2),padding='same'))

    model.add(Flatten()) # this converts our 3D feature maps to 1D feature vectors
    model.add(Dense(64))
    model.add(Activation('relu'))
    model.add(Dropout(0.5))
    model.add(Dense(1))
    model.add(Activation('sigmoid'))

    model.compile(loss='binary_crossentropy',
    optimizer='rmsprop',
    metrics=['accuracy'])

    batch_size = 64

    # this is a generator that will read pictures found in
    # subfolers of 'data/train', and indefinitely generate
    # batches of augmented image data
    train_generator = train_datagen.flow_from_directory(
    'C:\Users\Zahid\Desktop\Dataset\train', # this is the target directory
    target_size=(150, 150), # all images will be resized to 150x150
    batch_size=batch_size,
    color_mode='rgb',
    class_mode='binary') # since we use binary_crossentropy loss, we need binary labels

    # this is a similar generator, for validation data
    validation_generator = test_datagen.flow_from_directory(
    'C:\Users\Zahid\Desktop\Dataset\val',
    target_size=(150, 150),
    batch_size=batch_size,
    color_mode='rgb',
    class_mode='binary')

    model.fit_generator(
    train_generator,
    steps_per_epoch=2000 // batch_size,
    epochs=50,
    validation_data=validation_generator,
    validation_steps=800 // batch_size)
    model.save_weights('first_try.h5')









    share|improve this question











    $endgroup$














      0












      0








      0





      $begingroup$


      I am trying to train the model, I keep ending up with this ValueError:




      ValueError: Error when checking input: expected conv2d_13_input to have shape (3, 150, 150) but got array with shape (150, 150, 3)




      How can I fix this? Should I use numpy.resize or cv2.resize to change the dimensions to (3,150,150). If so, how would I resize it in the generator?



      Here is my code:



      train_datagen = ImageDataGenerator(
      rescale=1./255,
      shear_range=0.2,
      zoom_range=0.2)

      test_datagen = ImageDataGenerator(rescale=1./255)

      from keras.models import Sequential
      from keras.layers import Conv2D, MaxPooling2D
      from keras.layers import Activation, Dropout, Flatten, Dense

      model = Sequential()
      model.add(Conv2D(32, (3, 3), input_shape=(3, 150, 150),padding='same'))
      model.add(Activation('relu'))
      model.add(MaxPooling2D(pool_size=(2, 2),padding='same'))

      model.add(Conv2D(32, (3, 3),padding='same'))
      model.add(Activation('relu'))
      model.add(MaxPooling2D(pool_size=(2, 2),padding='same'))

      model.add(Conv2D(64, (3, 3),padding='same'))
      model.add(Activation('relu'))
      model.add(MaxPooling2D(pool_size=(2, 2),padding='same'))

      model.add(Flatten()) # this converts our 3D feature maps to 1D feature vectors
      model.add(Dense(64))
      model.add(Activation('relu'))
      model.add(Dropout(0.5))
      model.add(Dense(1))
      model.add(Activation('sigmoid'))

      model.compile(loss='binary_crossentropy',
      optimizer='rmsprop',
      metrics=['accuracy'])

      batch_size = 64

      # this is a generator that will read pictures found in
      # subfolers of 'data/train', and indefinitely generate
      # batches of augmented image data
      train_generator = train_datagen.flow_from_directory(
      'C:\Users\Zahid\Desktop\Dataset\train', # this is the target directory
      target_size=(150, 150), # all images will be resized to 150x150
      batch_size=batch_size,
      color_mode='rgb',
      class_mode='binary') # since we use binary_crossentropy loss, we need binary labels

      # this is a similar generator, for validation data
      validation_generator = test_datagen.flow_from_directory(
      'C:\Users\Zahid\Desktop\Dataset\val',
      target_size=(150, 150),
      batch_size=batch_size,
      color_mode='rgb',
      class_mode='binary')

      model.fit_generator(
      train_generator,
      steps_per_epoch=2000 // batch_size,
      epochs=50,
      validation_data=validation_generator,
      validation_steps=800 // batch_size)
      model.save_weights('first_try.h5')









      share|improve this question











      $endgroup$




      I am trying to train the model, I keep ending up with this ValueError:




      ValueError: Error when checking input: expected conv2d_13_input to have shape (3, 150, 150) but got array with shape (150, 150, 3)




      How can I fix this? Should I use numpy.resize or cv2.resize to change the dimensions to (3,150,150). If so, how would I resize it in the generator?



      Here is my code:



      train_datagen = ImageDataGenerator(
      rescale=1./255,
      shear_range=0.2,
      zoom_range=0.2)

      test_datagen = ImageDataGenerator(rescale=1./255)

      from keras.models import Sequential
      from keras.layers import Conv2D, MaxPooling2D
      from keras.layers import Activation, Dropout, Flatten, Dense

      model = Sequential()
      model.add(Conv2D(32, (3, 3), input_shape=(3, 150, 150),padding='same'))
      model.add(Activation('relu'))
      model.add(MaxPooling2D(pool_size=(2, 2),padding='same'))

      model.add(Conv2D(32, (3, 3),padding='same'))
      model.add(Activation('relu'))
      model.add(MaxPooling2D(pool_size=(2, 2),padding='same'))

      model.add(Conv2D(64, (3, 3),padding='same'))
      model.add(Activation('relu'))
      model.add(MaxPooling2D(pool_size=(2, 2),padding='same'))

      model.add(Flatten()) # this converts our 3D feature maps to 1D feature vectors
      model.add(Dense(64))
      model.add(Activation('relu'))
      model.add(Dropout(0.5))
      model.add(Dense(1))
      model.add(Activation('sigmoid'))

      model.compile(loss='binary_crossentropy',
      optimizer='rmsprop',
      metrics=['accuracy'])

      batch_size = 64

      # this is a generator that will read pictures found in
      # subfolers of 'data/train', and indefinitely generate
      # batches of augmented image data
      train_generator = train_datagen.flow_from_directory(
      'C:\Users\Zahid\Desktop\Dataset\train', # this is the target directory
      target_size=(150, 150), # all images will be resized to 150x150
      batch_size=batch_size,
      color_mode='rgb',
      class_mode='binary') # since we use binary_crossentropy loss, we need binary labels

      # this is a similar generator, for validation data
      validation_generator = test_datagen.flow_from_directory(
      'C:\Users\Zahid\Desktop\Dataset\val',
      target_size=(150, 150),
      batch_size=batch_size,
      color_mode='rgb',
      class_mode='binary')

      model.fit_generator(
      train_generator,
      steps_per_epoch=2000 // batch_size,
      epochs=50,
      validation_data=validation_generator,
      validation_steps=800 // batch_size)
      model.save_weights('first_try.h5')






      neural-network keras dataset neural






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Apr 6 at 15:33









      Stephen Rauch

      1,52551330




      1,52551330










      asked Apr 6 at 10:24









      Zahid AhmedZahid Ahmed

      64




      64




















          1 Answer
          1






          active

          oldest

          votes


















          2












          $begingroup$

          Change this:



          model.add(Conv2D(32, (3, 3), input_shape=(3, 150, 150),padding='same'))


          to this:



          model.add(Conv2D(32, (3, 3), input_shape=(150, 150, 3),padding='same'))


          And read the doc: https://keras.io/layers/convolutional/#conv2d



          In particular the section about data_format:




          data_format: A string, one of "channels_last" or "channels_first". The ordering of the dimensions in the inputs. "channels_last" corresponds to inputs with shape (batch, height, width, channels) while "channels_first" corresponds to inputs with shape (batch, channels, height, width). It defaults to the image_data_format value found in your Keras config file at ~/.keras/keras.json. If you never set it, then it will be "channels_last".







          share|improve this answer









          $endgroup$












          • $begingroup$
            Thank you so much :)
            $endgroup$
            – Zahid Ahmed
            Apr 6 at 10:36











          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "557"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f48731%2fvalueerror-error-when-checking-input-expected-conv2d-13-input-to-have-shape-3%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2












          $begingroup$

          Change this:



          model.add(Conv2D(32, (3, 3), input_shape=(3, 150, 150),padding='same'))


          to this:



          model.add(Conv2D(32, (3, 3), input_shape=(150, 150, 3),padding='same'))


          And read the doc: https://keras.io/layers/convolutional/#conv2d



          In particular the section about data_format:




          data_format: A string, one of "channels_last" or "channels_first". The ordering of the dimensions in the inputs. "channels_last" corresponds to inputs with shape (batch, height, width, channels) while "channels_first" corresponds to inputs with shape (batch, channels, height, width). It defaults to the image_data_format value found in your Keras config file at ~/.keras/keras.json. If you never set it, then it will be "channels_last".







          share|improve this answer









          $endgroup$












          • $begingroup$
            Thank you so much :)
            $endgroup$
            – Zahid Ahmed
            Apr 6 at 10:36















          2












          $begingroup$

          Change this:



          model.add(Conv2D(32, (3, 3), input_shape=(3, 150, 150),padding='same'))


          to this:



          model.add(Conv2D(32, (3, 3), input_shape=(150, 150, 3),padding='same'))


          And read the doc: https://keras.io/layers/convolutional/#conv2d



          In particular the section about data_format:




          data_format: A string, one of "channels_last" or "channels_first". The ordering of the dimensions in the inputs. "channels_last" corresponds to inputs with shape (batch, height, width, channels) while "channels_first" corresponds to inputs with shape (batch, channels, height, width). It defaults to the image_data_format value found in your Keras config file at ~/.keras/keras.json. If you never set it, then it will be "channels_last".







          share|improve this answer









          $endgroup$












          • $begingroup$
            Thank you so much :)
            $endgroup$
            – Zahid Ahmed
            Apr 6 at 10:36













          2












          2








          2





          $begingroup$

          Change this:



          model.add(Conv2D(32, (3, 3), input_shape=(3, 150, 150),padding='same'))


          to this:



          model.add(Conv2D(32, (3, 3), input_shape=(150, 150, 3),padding='same'))


          And read the doc: https://keras.io/layers/convolutional/#conv2d



          In particular the section about data_format:




          data_format: A string, one of "channels_last" or "channels_first". The ordering of the dimensions in the inputs. "channels_last" corresponds to inputs with shape (batch, height, width, channels) while "channels_first" corresponds to inputs with shape (batch, channels, height, width). It defaults to the image_data_format value found in your Keras config file at ~/.keras/keras.json. If you never set it, then it will be "channels_last".







          share|improve this answer









          $endgroup$



          Change this:



          model.add(Conv2D(32, (3, 3), input_shape=(3, 150, 150),padding='same'))


          to this:



          model.add(Conv2D(32, (3, 3), input_shape=(150, 150, 3),padding='same'))


          And read the doc: https://keras.io/layers/convolutional/#conv2d



          In particular the section about data_format:




          data_format: A string, one of "channels_last" or "channels_first". The ordering of the dimensions in the inputs. "channels_last" corresponds to inputs with shape (batch, height, width, channels) while "channels_first" corresponds to inputs with shape (batch, channels, height, width). It defaults to the image_data_format value found in your Keras config file at ~/.keras/keras.json. If you never set it, then it will be "channels_last".








          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Apr 6 at 10:32









          qmeeusqmeeus

          30129




          30129











          • $begingroup$
            Thank you so much :)
            $endgroup$
            – Zahid Ahmed
            Apr 6 at 10:36
















          • $begingroup$
            Thank you so much :)
            $endgroup$
            – Zahid Ahmed
            Apr 6 at 10:36















          $begingroup$
          Thank you so much :)
          $endgroup$
          – Zahid Ahmed
          Apr 6 at 10:36




          $begingroup$
          Thank you so much :)
          $endgroup$
          – Zahid Ahmed
          Apr 6 at 10:36

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Data Science Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          Use MathJax to format equations. MathJax reference.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f48731%2fvalueerror-error-when-checking-input-expected-conv2d-13-input-to-have-shape-3%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Adding axes to figuresAdding axes labels to LaTeX figuresLaTeX equivalent of ConTeXt buffersRotate a node but not its content: the case of the ellipse decorationHow to define the default vertical distance between nodes?TikZ scaling graphic and adjust node position and keep font sizeNumerical conditional within tikz keys?adding axes to shapesAlign axes across subfiguresAdding figures with a certain orderLine up nested tikz enviroments or how to get rid of themAdding axes labels to LaTeX figures

          Tähtien Talli Jäsenet | Lähteet | NavigointivalikkoSuomen Hippos – Tähtien Talli

          Do these cracks on my tires look bad? The Next CEO of Stack OverflowDry rot tire should I replace?Having to replace tiresFishtailed so easily? Bad tires? ABS?Filling the tires with something other than air, to avoid puncture hassles?Used Michelin tires safe to install?Do these tyre cracks necessitate replacement?Rumbling noise: tires or mechanicalIs it possible to fix noisy feathered tires?Are bad winter tires still better than summer tires in winter?Torque converter failure - Related to replacing only 2 tires?Why use snow tires on all 4 wheels on 2-wheel-drive cars?