Ryotaro Harada
Ryotaro Harada

Reputation: 39

How to solve Input to reshape is a tensor with

I want to solve this below error.

 InvalidArgumentError:  Input to reshape is a tensor with 737280 values, but the requested shape requires a multiple of 184832

so I see reference.

reference Python / Tensorflow - Input to reshape is a tensor with 92416 values, but the requested shape requires a multiple of 2304

However, looking at the answers to this problem, I do not know where to fix it. So ,I would like to know how to check the size of the input image.

Thank you for your time.

my model:

# For multi_model
activationFunction='elu'
def build_multi2(main_input_shape, output_dim):
   
    inputA = Input(shape=main_input_shape)
    ch1_model = create_convolution_layers(inputA)

    inputB = Input(shape=main_input_shape)
    ch2_model = create_convolution_layers(inputB)

    inputC = Input(shape=main_input_shape)
    ch3_model = create_convolution_layers(inputC)

    inputD = Input(shape=main_input_shape)
    ch4_model = create_convolution_layers(inputD)

    conv = concatenate([ch1_model, ch2_model, ch3_model, ch4_model])

    conv = Flatten()(conv)

    dense = Dense(512)(conv)
    dense = LeakyReLU(alpha=0.1)(dense)
    dense = Dropout(0.5)(dense)

    output = Dense(N_class, activation='softmax')(dense)

    return Model(inputs=[inputA, inputB, inputC, inputD], outputs=[output])

def create_convolution_layers(input_img):
  model = Conv2D(32, (3, 3), padding='same', input_shape=main_input_shape)(input_img)
  model = LeakyReLU(alpha=0.1)(model)
  model = MaxPooling2D((2, 2),padding='same')(model)
  model = Dropout(0.25)(model)
  
  model = Conv2D(64, (3, 3), padding='same')(model)
  model = LeakyReLU(alpha=0.1)(model)
  model = MaxPooling2D(pool_size=(2, 2),padding='same')(model)
  model = Dropout(0.25)(model)
    
  model = Conv2D(128, (3, 3), padding='same')(model)
  model = LeakyReLU(alpha=0.1)(model)
  model = MaxPooling2D(pool_size=(2, 2),padding='same')(model)
  model = Dropout(0.4)(model)
    
  return model

my model call

# For model declaration

N_class = 20
main_input_shape = (150,150, 3)
output_dim = N_class

# opt = tf.keras.optimizers.RMSprop(lr=0.001)
opt = tf.keras.optimizers.Adam()

clf = build_multi2(main_input_shape, output_dim)

clf.compile(optimizer=opt, loss=['categorical_crossentropy'], metrics=['accuracy'])

clf.summary()

my image size: 96×96 pixel

my tensorflow. ImageDataGenerator

 train_imgen = ImageDataGenerator(rescale = 1./255, 
                                    # shear_range = 0.2, 
                                    # zoom_range = 0.2,
                                    # rotation_range=5.,
                                    horizontal_flip = False)
'''

Upvotes: 0

Views: 2033

Answers (1)

Ace
Ace

Reputation: 97

You have specified your input shape as (150, 150, 3) and your image shape is (96, 96, 3), these are incompatible.

You can either resize your images to (150, 150, 3) or change your input shape to be the same as your image shape.

Upvotes: 1

Related Questions