繁体   English   中英

如何解决输入重塑是一个张量

[英]How to solve Input to reshape is a tensor with

我想解决以下错误。

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

所以我看到参考。

参考Python / Tensorflow - 重塑的输入是具有 92416 个值的张量,但请求的形状需要 2304 的倍数

但是,看着这个问题的答案,我不知道在哪里解决它。 所以,我想知道如何检查输入图像的大小。

感谢您的时间。

我的 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

我的 model 通话

# 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()

我的图像尺寸:96×96 像素

我的 tensorflow。 图像数据生成器

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

您已将输入形状指定为 (150, 150, 3),而您的图像形状为 (96, 96, 3),这些是不兼容的。

您可以将图像大小调整为 (150, 150, 3) 或将输入形状更改为与图像形状相同。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM