@错误如何解决 InvalidArgumentError: Incompatible shapes: [20000,1] vs. [256,1] [Op:Sub] name: sub/
错误显示
InvalidArgumentError Traceback (most recent call last)
in
10 for epoch in range(10):
11 for step,(x,y) in enumerate(dataset):
—> 12 loss=train_on_batch(x,y)
13
14 print(‘Epoch %d:last batch loss=%.4f’%(epoch,float(loss)))
in train_on_batch(x, y)
15 with tf.GradientTape() as tape:
16 predictions=compute_predictions(x)
—> 17 loss=compute_loss(y,predictions)
18 #tape,gradient对于多个变量求梯度也是可以的
19 dloss_w,dloss_b=tape.gradient(loss,[w,b])
in compute_loss(lables, predictions)
10 return tf.matmul(features,w)+b
11 def compute_loss(lables,predictions):
—> 12 return tf.reduce_mean(tf.square(labels-predictions))
13
14 def train_on_batch(x,y):
~\anaconda3\envs\tensorflow_gpu\lib\site-packages\tensorflow_core\pyt