Tensorflow尺寸大小必须可以被N整除,但对于“ linear / linear_model / x / Reshape”必须为M

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_sizedata_size = 10batch_size=10)时,它将引发其他错误:

ValueError:形状(1,1)和(10,1)不兼容

任何与错误的帮助将不胜感激。