[英]Tensorflow model was constructed with shape for input Tensor but it was called on an input with incompatible shape (Neural Network)
Basically I'm trying to build a model that uses embedded words as the input, but I keep getting this warning.基本上,我正在尝试构建一个使用嵌入词作为输入的模型,但我不断收到此警告。 I've tried to change the shape of the input according to the training data for my model various times but it does not have any effect on the model building.
我曾多次尝试根据模型的训练数据更改输入的形状,但它对模型构建没有任何影响。 I'm trying to predict temperature values for my input, a range from 0 - 100
我正在尝试为我的输入预测温度值,范围为 0 - 100
During training, the loss scores some times change and other times they do not,.在训练期间,损失分数有时会改变,有时不会。 I'm not really sure what is going on here.
我不确定这里发生了什么。
x_train shape: (17405, 3840)
y_train shape: (17405,)
x_valid shape: (4352, 3840)
y_valid shape: (4352,)
# Initializing the ANN
model = Sequential()
# Adding the input layer and the first hidden layer
model.add(Dense(units=1, activation='relu', input_shape = x_train.shape))
# Adding the second hidden layer
model.add(Dense(units=1, activation='relu'))
# Adding the output layer
model.add(Dense(units=1, activation='linear'))
#Global Variables for Model
optimizer = tf.keras.optimizers.Adam(learning_rate=0.0001) #methods used to change the attributes of the nn
# tf.keras.optimizers.SGD(learning_rate=0.001)
batch_size = 100 # Defines the number of samples that will be propagated through the network.
loss = 'mean_squared_error' #Cmpute the quantity that a model should seek to minimize during training
EPOCHS = 20 # How many times to go through the training set.
# Compiling the Model
model.compile(optimizer = optimizer, loss = loss, metrics=['mae'])
# Training/Fitting the Model on the Training set
model.fit(x_train, y_train, batch_size = batch_size,
epochs = EPOCHS, verbose = 1)
#Model Summary
model.summary()
#Model Evaluation
score = model.evaluate(x_valid, y_valid, verbose=1)
As mentioned, the model runs but I get the following error:如上所述,模型运行但我收到以下错误:
WARNING:tensorflow:Model was constructed with shape (None, 17405, 3840) for input Tensor("dense_73_input:0", shape=(None, 17405, 3840), dtype=float32), but it was called on an input with incompatible shape (None, 3840).
Your data shape is in fact (None, 3840)
because 17405
in the shape means the number of elements in your data, which you don't have to pass to the model.您的数据形状实际上是
(None, 3840)
因为17405
中的17405
表示数据中的元素数量,您不必将其传递给模型。
So you should use this instead:所以你应该改用这个:
model = Sequential()
model.add(Dense(units=1, activation='relu', input_shape = x_train.shape[1]))
model.add(Dense(units=1, activation='relu'))
model.add(Dense(units=1, activation='linear'))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.