简体   繁体   English

python 中的神经网络:警告:tensorflow:Model 是用形状(无,7)构建的

[英]Neural Network in python: WARNING:tensorflow:Model was constructed with shape (None, 7) for input

i have data that 60 rows and nine columns from xlsx (8 columns for x and 1 columns for y).我有来自 xlsx 的 60 行和 9 列的数据(x 为 8 列,y 为 1 列)。 i devided it to data training 80% and data testing 20%.我将其分为 80% 的数据训练和 20% 的数据测试。 so i have 12 for testing and 48 for training.所以我有 12 个用于测试,48 个用于培训。 so i have x test, y test, x train and y train.所以我有 x 测试,y 测试,x 训练和 y 训练。 i use neural network in python and i have this code我在 python 中使用神经网络,我有这个代码

import tensorflow as tf
from tensorflow.keras.optimizers import Adam
model = tf.keras.models.Sequential()
adam = Adam(learning_rate=0.01)
model.add(tf.keras.layers.Dense(units=8, activation='relu')) #input ada sembilan belas
model.add(tf.keras.layers.Dense(units=4, activation='relu')) #hidden layer 19 node
model.add(tf.keras.layers.Dense(units=1, activation='linear')) #output layer tidak menggunakan aktivasi
model.compile(loss='mae', optimizer=adam)
model.fit(x_train_CWA, y_train_CWA, epochs=1000)

then i predict x test with this code然后我用这段代码预测 x 测试

y_pred_CWA=model.predict(x_test_CWA)

After that i can predict thats data then, i want to input a new data with this code之后我可以预测那个数据,我想用这个代码输入一个新数据

A = float(input("A : "))
B = float(input("B: "))
C = float(input("C: "))
D = float(input ("D: "))
E = float(input ("E : "))
F = float(input ("F: "))
G = float(input ("G: "))
H = float(input ("H"))

then i entering new data and i want to predict the new data so i array the input data with this code然后我输入新数据,我想预测新数据,所以我用这段代码排列输入数据

Prediction_CWA = np.array([A, B, C, D, E, F, G, H])

Then i predict with this code然后我用这段代码预测

CWA_Prediction = model.predict(Prediction_CWA)

but i found an error like this但我发现了这样的错误

ValueError: Exception encountered when calling layer "sequential_11" (type Sequential).

Input 0 of layer "dense_25" is incompatible with the layer: expected min_ndim=2, found ndim=1. Full shape received: (None,)

Call arguments received:
  • inputs=tf.Tensor(shape=(None,), dtype=float32)
  • training=False
  • mask=None

when using model.predict for a SINGLE prediction you need to expand the dimensions of the array to provide for the batch dimension so try当使用 model.predict 进行 SINGLE 预测时,您需要扩展数组的维度以提供批量维度,因此请尝试

Prediction_CWA = np.expand_dims(Prediction_CWA, axis=0)

then do model.predict然后做 model.predict

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 警告:tensorflow:Model 是用形状构造的(无,...) - WARNING:tensorflow:Model was constructed with shape (None, …) 警告:警告: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 模型是用输入 Tensor 的形状构建的,但它在形状不兼容的输入(神经网络)上被调用 - Tensorflow model was constructed with shape for input Tensor but it was called on an input with incompatible shape (Neural Network) 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 是用形状 (None, None, 6) 构造的,但它是在形状不兼容的输入上调用的 - tensorflow:Model was constructed with shape (None, None, 6), but it was called on an input with incompatible shape 警告:tensorflow:Model 是按形状构造的(无、66、200、3) - WARNING:tensorflow:Model was constructed with shape (None, 66, 200, 3) 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) 警告:tensorflow:Model 是用输入 Tensor() 的形状构建的。 但它是在形状不兼容的输入上调用的 - WARNING:tensorflow:Model was constructed with shape for input Tensor(). but it was called on an input with incompatible shape 警告: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 Model 是用形状(无,65536)构造的,但它是在形状不兼容的输入上调用的(无,65536,无) - Model was constructed with shape (None, 65536) but it was called on an input with incompatible shape (None, 65536, None)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM