简体   繁体   English

ValueError:“顺序”层的输入 0 与该层不兼容:预期形状=(无,128,128,3),找到形状=(32,128,3)

[英]ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 128, 128, 3), found shape=(32, 128, 3)

i have the following code portion where i used the vit_b16 model.我有以下代码部分,其中我使用了 vit_b16 model。 The input to the model is a 128x128x3 Multi-spectral image. model 的输入是 128x128x3 多光谱图像。

!pip install vit-keras
!pip install tensorflow_addons
from vit_keras import vit, utils
IMG_SIZE = (128,128)
vit_base_model =  vit.vit_b16(image_size=IMG_SIZE,pretrained=True,include_top=False,pretrained_top=False)
vit_model = Model(inputs=vit_base_model.input, outputs=vit_base_model.layers[18].output)
model=keras.models.Sequential()
model.add(vit_model)
model.add(Flatten())
model.add(Dense(226))
model.add(Dropout(0.5))
model.add(Dense(226))
model.summary()
model.compile(
     optimizer=keras.optimizers.Adam(),
     loss=keras.losses.BinaryCrossentropy(from_logits=True), 
     metrics=[keras.metrics.BinaryAccuracy()],
)
epochs = 20
model.fit(Ref_L7,hyp_patches,epochs=epochs, validation_data=0.1)

I am getting this error from the model.compile part.我从 model.compile 部分收到此错误。

在此处输入图像描述

The problem is with your size of data, and you can try with this, also your shape of data in fit should be (numberofImages,128,128,3) .问题在于您的数据大小,您可以尝试这样做,您的数据fit也应该是(numberofImages,128,128,3)

IMG_SIZE = (128,128,3)
vit_base_model =  vit.vit_b16(image_size=IMG_SIZE,pretrained=True,include_top=False,pretrained_top=False)
vit_model = Model(inputs=vit_base_model.input, outputs=vit_base_model.layers[18].output)
model=keras.models.Sequential()
model.add(vit_model)
model.add(Flatten())
model.add(Dense(226))
model.add(Dropout(0.5))
model.add(Dense(226))
model.summary()
model.compile(
     optimizer=keras.optimizers.Adam(),
     loss=keras.losses.BinaryCrossentropy(from_logits=True), 
     metrics=[keras.metrics.BinaryAccuracy()],
)
epochs = 20
model.fit(Ref_L7,hyp_patches,epochs=epochs, validation_data=0.1)

Changed the IMAGE_SIZE as channel 3 is added.添加频道 3 时更改了 IMAGE_SIZE。 also print your shape of Ref_L7,hyp_patches This will give you more information on what's wrong.还打印您的Ref_L7,hyp_patches的形状这将为您提供有关问题的更多信息。

暂无
暂无

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

相关问题 ValueError: 层 max_pooling1d 的输入 0 与层不兼容:预期 ndim=3,发现 ndim=4。 收到的完整形状:(无、128、1、32) - ValueError: Input 0 of layer max_pooling1d is incompatible with the layer: expected ndim=3, found ndim=4. Full shape received: (None, 128, 1, 32) ValueError:层“顺序”的输入 0 与层不兼容:预期形状=(无,32,32,3),找到形状=(32,32,3) - ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 32, 32, 3), found shape=(32, 32, 3) ValueError:global_average_pooling2d 层的输入 0 与该层不兼容:预期 ndim=4,发现 ndim=2。 收到的完整形状:[无,128] - ValueError: Input 0 of layer global_average_pooling2d is incompatible with the layer: expected ndim=4, found ndim=2. Full shape received: [None, 128] ValueError: 层 lstm_17 的输入 0 与层不兼容:预期 ndim=3,发现 ndim=2。 收到的完整形状:[无,128] - ValueError: Input 0 of layer lstm_17 is incompatible with the layer: expected ndim=3, found ndim=2. Full shape received: [None, 128] ValueError: 层“sequential_32”的输入 0 与层不兼容:预期形状=(None, 3, 1),发现形状=(32, 0, 1) - ValueError: Input 0 of layer "sequential_32" is incompatible with the layer: expected shape=(None, 3, 1), found shape=(32, 0, 1) ValueError:“顺序”层的输入 0 与层不兼容:预期形状 =(无,223461,5),找到形状 =(无,5) - ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 223461, 5), found shape=(None, 5) ValueError:“顺序”层的输入 0 与该层不兼容:预期形状 =(None, 455, 30),找到的形状 =(None, 30) - ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 455, 30), found shape=(None, 30) ValueError: 层“sequential_1”的输入 0 与层不兼容:预期形状=(None, 60, 1),发现形状=(None, 59, 1) - ValueError: Input 0 of layer "sequential_1" is incompatible with the layer: expected shape=(None, 60, 1), found shape=(None, 59, 1) ValueError:层“顺序”的输入0与层不兼容:预期形状=(无,90),发现形状=(无,2,90) - ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 90), found shape=(None, 2, 90) ValueError:“顺序”层的输入 0 与该层不兼容:预期形状 =(无,33714,12),找到形状 =(无,12) - ValueError: Input 0 of layer "sequential" is incompatible with the layer: expected shape=(None, 33714, 12), found shape=(None, 12)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM