简体   繁体   English

Tensorflow 模型是用输入 Tensor 的形状构建的,但它在形状不兼容的输入(神经网络)上被调用

[英]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.我不确定这里发生了什么。

Raw Shape of the Data:数据的原始形状:

x_train shape: (17405, 3840)
y_train shape: (17405,)
x_valid shape: (4352, 3840)
y_valid shape: (4352,)

Building the Model构建模型

# 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'))

Compiling and Training编译与训练

#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.

相关问题 警告:tensorflow:Model 是用输入 Tensor() 的形状构建的。 但它是在形状不兼容的输入上调用的 - WARNING:tensorflow:Model was constructed with shape for input Tensor(). but it was called on an input with incompatible shape tensorflow:Model 是用形状 (None, None, 6) 构造的,但它是在形状不兼容的输入上调用的 - tensorflow:Model was constructed with shape (None, None, 6), but it was called on an input with incompatible shape python 中的神经网络:警告:tensorflow:Model 是用形状(无,7)构建的 - Neural Network in python: WARNING:tensorflow:Model was constructed with shape (None, 7) for input WARNING:tensorflow:Model 是用形状 (None, 188) 构造的输入,但它是在形状不兼容的输入上调用的 (188,) - WARNING:tensorflow:Model was constructed with shape (None, 188) for input, but it was called on an input with incompatible shape (188,) 警告:警告:tensorflow:Model 是用形状(无,150)构造的,但它是在形状不兼容的输入上调用的(无,1) - WARNING: WARNING:tensorflow:Model was constructed with shape (None, 150) , but it was called on an input with incompatible shape (None, 1) Tensorflow:Model 是用形状 (None, 28, 28) 构造的,但它是在形状不兼容的输入上调用的 (None, 28) - Tensorflow:Model was constructed with shape (None, 28, 28) , but it was called on an input with incompatible shape (None, 28) 模型是用形状 (None, 180, 180, 3) 构建的用于输入,但它在形状不兼容的输入 (None, 180, 3) 上被调用? - Model was constructed with shape (None, 180, 180, 3) for input, but it was called on an input with incompatible shape (None, 180, 3)? Model 是用形状(无,65536)构造的,但它是在形状不兼容的输入上调用的(无,65536,无) - Model was constructed with shape (None, 65536) but it was called on an input with incompatible shape (None, 65536, None) 警告:tensorflow:模型是用形状 (20, 37, 42) 构建的,用于输入 Tensor(“input_5:0”, shape=(20, 37, 42), dtype=float32),但是 - WARNING:tensorflow:Model was constructed with shape (20, 37, 42) for input Tensor(“input_5:0”, shape=(20, 37, 42), dtype=float32), but 神经网络的输入形状 - Input shape of a neural network
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM