检查输入时的错误:预期input_4具有形状(299,299,3)但得到形状为(64,64,3)的数组]]

问题描述 投票:1回答:1

我有大量的腌制数据,其训练,测试,验证类似于以下形状:

(n_samples, 64, 64, 3)


[array([[[26, 16, 24],
         [36, 20, 31],
         [47, 28, 42],
         ...,
         [15,  8, 15],
         [ 8,  5, 10],
         [ 3,  2,  6]],
         ...,
        [[41, 27, 38],
         [54, 37, 51],
         [68, 47, 61],
         ...,
         [22, 14, 21],
         [16,  9, 16],
         [11,  6, 12]]], dtype=uint8),
 array([[[209, 126, 116],
         [212, 125, 117],
         [215, 135, 127],
         ...,

我将其更改为:

a=[l.tolist() for l in train_images]
   #x = np.expand_dims(a, axis=0)
train_x =np.array(a)


train_x:
array([[[[ 26,  16,  24],
         [ 36,  20,  31],
         [ 47,  28,  42],
         ...,
         [ 15,   8,  15],
         [  8,   5,  10],
         [  3,   2,   6]],

train_x= preprocess_input(train_x)

并且标签类似于:

from keras.utils.np_utils import to_categorical
train_y = to_categorical(labels, 2)
train_y :
array([[0., 1.],
       [0., 1.],
       [0., 1.],
       ...,
       [0., 1.],
       [1., 0.],
       [0., 1.]], dtype=float32)

我希望将此数据适合于像inception v3一样的keras模型:

from keras.applications.inception_v3 import InceptionV3
from keras import optimizers

base_model = InceptionV3(weights='imagenet', include_top = True)
model.compile(optimizer = optimizers.SGD(lr=1e-3, momentum=0.9),
                  loss='categorical_crossentropy', metrics=['accuracy'])

model.fit(train_x, train_y , batch_size=128, nb_epoch=1,verbose=0)

但我收到此错误:

Error when checking input:expected input_4 to have the shape (299, 299, 3) but got array with shape (64, 64, 3)

我知道此错误与尺寸有关。我该如何修改要运行的代码?可能是冻结层,微调或更改了输入尺寸(我不希望丢失特征和重要数据)。如果知道的话,请重写正确的代码。

我有大量的腌制数据,其训练,测试,验证类似于以下形状:(n_samples,64,64,3)[array([[[[26,16,24],[36,20,31],[ 47,28,42],...,...

python tensorflow keras computer-vision keras-layer
1个回答
1
投票

如下将input_tensor=Input(shape=(64, 64, 3))包括在base_model = InceptionV3(weights='imagenet', include_top = True)行中:

© www.soinside.com 2019 - 2024. All rights reserved.