Почему у меня появляется «Ошибка при проверке ввода: ожидалось, что input_1 будет иметь 4 измерения, но получил массив с формой (0, 1)»? Я вставил код ниже - PullRequest
0 голосов
/ 10 октября 2019

Ниже приведен код, в котором я обнаружил ошибку:

import_directory = "C:\\Users\\BATMAN\\Projects\\Database2\\"
counter = 0
data_array = np.empty((0, 2))
files = os.listdir(import_directory)
for file in files:
    print('Opening File : ', file)
    data_set = np.load(import_directory+file)
    data_array = np.vstack((data_array, data_set))

np.random.shuffle(data_array)
print("ok")
img_row = 50
img_col = 50
N = np.shape(data_array)[0]
train_test_split_percentage = 0.75
X_train = data_array[:int(N * train_test_split_percentage), 0]
X_test = data_array[int(N * train_test_split_percentage):, 0]
X_train = np.array([x.reshape(img_row, img_col, 3) for x in X_train])
X_test = np.array([x.reshape(img_row, img_col, 3) for x in X_test])
y_train = data_array[:int(N * train_test_split_percentage), 1]
y_test = data_array[int(N * train_test_split_percentage):, 1]
y_train = np.array([[x] for x in y_train])
y_test = np.array([[x] for x in y_test])

model_vgg19_conv = VGG19(include_top=False, weights='imagenet', input_shape=(img_col, img_row, 3))


for layer in model_vgg19_conv.layers:
    layer.trainable = False
    print(layer.name)
x = model_vgg19_conv.output
x = Flatten()(x)
x = Dense(128, activation='relu')(x)
x = Dense(1, activation='sigmoid', name='predictions')(x)

#building the model
my_model = Model(input=model_vgg19_conv.input, output=x)
my_model.summary()
my_model.compile(loss=keras.losses.binary_crossentropy,
              optimizer=keras.optimizers.RMSprop(),
              metrics=['accuracy'])

batch_size = 32
epochs = 2

hist = my_model.fit(X_train, y_train,
          batch_size=batch_size,
          epochs=epochs,
          verbose=1,
          validation_split=0.2)
score = my_model.evaluate(X_test, y_test, verbose=0)

После выполнения последней строки я получаю следующую ошибку: Ошибка при проверке ввода: ожидалось, что input_1 имеет 4 измерения, но полученомассив с формой (0, 1)

...