[英]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.