下面显示的代码给出了我的值错误
model = Sequential()
model.add(Conv2D(32, (8,8),
padding='valid',
strides=1,
activation="relu", input_shape = (256,256,3)))
我得到的错误是
ValueError: `Layer conv2d_37 was called with an input that isn't a symbolic tensor.` Received type: <class 'tensorflow.python.framework.ops.Tensor'>. Full input: [<tf.Tensor 'conv2d_37_input:0' shape=(?, 256, 256, 3) dtype=float32>]. All inputs to the layer should be tensors.
我在这里使用Tensorflow 1.2.1版本和keras 2.1.5,在运行main时,我在这里收到此错误。
伙计们,请帮助解决这个问题。
完整的代码在
下面def cnn_model(X_train, y_train, kernel_size, nb_filters, channels, nb_epoch, batch_size, nb_classes, nb_gpus):
model = Sequential()
model.add(Conv2D(nb_filters, (kernel_size[0], kernel_size[1]),
padding='valid',
strides=1,
input_shape=(img_rows, img_cols, channels), activation="relu"))
model.add(Conv2D(nb_filters, (kernel_size[0], kernel_size[1]), activation="relu"))
model.add(Conv2D(nb_filters, (kernel_size[0], kernel_size[1]), activation="relu"))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Flatten())
print("Model flattened out to: ", model.output_shape)
model.add(Dense(128))
model.add(Activation('sigmoid'))
model.add(Dropout(0.25))
model.add(Dense(nb_classes))
model.add(Activation('softmax'))
model = multi_gpu_model(model, gpus=nb_gpus)
model.compile(loss='binary_crossentropy',
optimizer='adam',
metrics=['accuracy'])
stop = EarlyStopping(monitor='val_acc',
min_delta=0.001,
patience=2,
verbose=0,
mode='auto')
tensor_board = TensorBoard(log_dir='./Graph', histogram_freq=0, write_graph=True, write_images=True)
model.fit(X_train, y_train, batch_size=batch_size, epochs=nb_epoch,
verbose=1,
validation_split=0.2,
class_weight='auto',
callbacks=[stop, tensor_board])
return model
谢谢