【发布时间】:2021-01-08 13:40:25
【问题描述】:
我正在制作一个张量流模型,它采用一组 6 个值并输出一个。(测试和学习目的) 代码如下:
import tensorflow as tf
import numpy as np
from tensorflow import keras
import pandas as pd
a=0
model = keras.Sequential()
model.add(keras.layers.Dense(units=6, input_shape=(6,)))
model.compile(optimizer='sgd',loss='mean_squared_error')
x=np.array(((1.0,1.0,1.0,1.0,1.0,1.0),(2.0,2.0,2.0,2.0,2.0,2.0),(3.0,3.0,3.0,3.0,3.0,3.0),(4.0,4.0,4.0,4.0,4.0,4.0)))
y=np.array((1.0,2.0,3.0,4.0))
print(x)
model.fit(x,y,epochs=100)
while True:
a=float(input())
print(model.predict(np.array((a,a,a,a,a,a))))
我收到以下错误:
ValueError: Input 0 of layer sequential is incompatible with the layer: expected axis -1 of input shape to have value 6 but received input with shape [None, 1]
当我找到输入给模块的形状时,我得到了正确的形状,即 (6,0)。 任何形式的帮助表示赞赏。谢谢。
【问题讨论】:
标签: python pandas numpy tensorflow keras