错误如何解决 InvalidArgumentError: Incompatible shapes: [20000,1] vs. [256,1]

在使用TensorFlow进行训练时遇到了`InvalidArgumentError: Incompatible shapes`错误,具体表现为[20000,1]与[256,1]的形状不匹配。错误出现在`tf.Sub`操作中。尝试遍历数据集并计算损失时,计算过程引发了该错误。寻求解决方案。" 123662211,9640242,Python绘制折线图教程,"['Python', '数据可视化']
摘要由CSDN通过智能技术生成

@错误如何解决 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

评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值