[英]Keras Error when checking input
我想探索用Keras定义的张量流模型的中间层:
input_dim = 30
input_layer = Input(shape=(input_dim, ))
encoder = Dense(encoding_dim, activation="tanh",
activity_regularizer=regularizers.l1(10e-5))(input_layer)
encoder = Dense(int(encoding_dim / 2), activation="relu")(encoder)
decoder = Dense(int(encoding_dim / 2), activation='tanh')(encoder)
decoder = Dense(input_dim, activation='relu')(decoder)
autoencoder = Model(inputs=input_layer, outputs=decoder)
####TRAINING....
#inspect layer 1
intermediate_layer_model = Model(inputs=autoencoder.layers[0].input,
outputs=autoencoder.layers[1].output)
xtest = #array of dim (30,)
intermediate_output = intermediate_layer_model.predict(xtest)
print(intermediate_output)
但是在检查时出现尺寸错误:
/usr/local/lib/python2.7/site-packages/keras/engine/training_utils.pyc in standardize_input_data(data, names, shapes, check_batch_axis, exception_prefix)
134 ': expected ' + names[i] + ' to have shape ' +
135 str(shape) + ' but got array with shape ' +
--> 136 str(data_shape))
137 return data
138
ValueError: Error when checking input: expected input_4 to have shape (30,) but got array with shape (1,)
任何帮助表示赞赏
从Keras 文档 :
shape:形状元组(整数),不包括批次大小。 例如,shape =(32,)表示预期的输入将是32维向量的批次。
指定模型时,不需要提供批次尺寸。 model.predict()
希望您的数组具有这种形状。
重塑你xtest
含有批处理尺寸: xtest = np.reshape(xtest, (1, -1))
并设置batch_size
的参数model.predict()
为1。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.