I've been trying to use tensorflow's tf.estimator
, but I'm getting the following errors regarding the shape of input/output data.
ValueError: Dimension size must be evenly divisible by 9 but is 12 for 'linear/linear_model/x/Reshape' (op: 'Reshape') with input shapes: [4,3], [2] and with input tensors computed as partial shapes: input[1] = [?,9].
Here is the code:
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)
input data shape is shape=(3, 3)
:
[[ 0.06525168 0.3171153 0.61675511]
[ 0.35166298 0.71816544 0.62770994]
[ 0.77846666 0.20930611 0.1710842 ]]
output data shape is shape=(3, 1)
[[ 9.399135 ]
[ 11.25179188]
[ 7.38244104]]
I have sense it is related to input
data, output
data and batch_size
, because when input
data changed to 1 row it works. When input
data rows count equal to batch_size
(data_size = 10
and batch_size=10
) then it throws other error:
ValueError: Shapes (1, 1) and (10, 1) are incompatible
Any help with the errors would be much appreciated.
(3,3)
but it should be(3,)
, so I have made the change tofeature_columns = [tf.feature_column.numeric_column("x", shape=(3,))]
, and it works perfectly.x.shape = 10, 5
then input shape will beshape=(5,)
and so on. hope this help.