Mir*_*dil 5 machine-learning shape reshape tensorflow
我一直在尝试使用tensorflow tf.estimator
,但是关于输入/输出数据的形状却遇到了以下错误。
ValueError:尺寸大小必须被9整除,但对于'linear / linear_model / x / Reshape'(op:'Reshape'),输入形状为[4,3],[2],且输入张量计算为部分时,尺寸为12形状:输入[1] = [?,9]。
这是代码:
data_size = 3
iterations = 10
learn_rate = 0.005
# generate test data
input = np.random.rand(data_size,3)
output = np.dot(input, [2, 3 ,7]) + 4
output = np.transpose([output])
feature_columns = [tf.feature_column.numeric_column("x", shape=(data_size, 3))]
estimator = tf.estimator.LinearRegressor(feature_columns=feature_columns)
input_fn = tf.estimator.inputs.numpy_input_fn({"x":input}, output, batch_size=4, num_epochs=None, shuffle=True)
estimator.train(input_fn=input_fn, steps=iterations)
Run Code Online (Sandbox Code Playgroud)
输入数据的形状为shape=(3, 3)
:
[[ 0.06525168 0.3171153 0.61675511]
[ 0.35166298 0.71816544 0.62770994]
[ 0.77846666 0.20930611 0.1710842 ]]
Run Code Online (Sandbox Code Playgroud)
输出数据形状为 shape=(3, 1)
[[ 9.399135 ]
[ 11.25179188]
[ 7.38244104]]
Run Code Online (Sandbox Code Playgroud)
我知道它与input
数据,output
数据和有关batch_size
,因为当input
数据更改为1行时,它可以工作。当input
数据行计数等于batch_size
(data_size = 10
和batch_size=10
)时,它将引发其他错误:
ValueError:形状(1,1)和(10,1)不兼容
任何与错误的帮助将不胜感激。
归档时间: |
|
查看次数: |
4459 次 |
最近记录: |