首页 Paddle框架 帖子详情
想尝试CTR算法,照着现成代码改了一个,把新的数据放进去预测,报错
收藏
快速回复
Paddle框架 问答炼丹技巧模型训练 441 4
想尝试CTR算法,照着现成代码改了一个,把新的数据放进去预测,报错
收藏
快速回复
Paddle框架 问答炼丹技巧模型训练 441 4

https://aistudio.baidu.com/aistudio/projectdetail/2390780

尝试上面的代码,在它训练完成后,我希望放入1条新数据进行预测,已经照着前面数据的清洗和特征化做好了。

最后再预测的时候,就报错了

predict_dataset = BuildDataSet(df_data_test_copy, dense_features, is_test=True)

predict_loader = DataLoader(predict_dataset,
batch_size=1,
shuffle=False)


for (userid, docid, network, device_t, os, province, city, age, gender, category1st, category2nd, dense_features, keywords, click) in predict_loader():
     predict, loss = model(userid, docid, network, device_t, os,
                           province, city, age, gender, category1st,
                           category2nd, dense_features, keywords, click)

错误如下:

 

---------------------------------------------------------------------------ValueError Traceback (most recent call last) in
17 predict, loss = model(userid, docid, network, device_t, os,
18 province, city, age, gender, category1st,
---> 19 category2nd, dense_features, keywords, click)
20
21
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/layers.py in __call__(self, *inputs, **kwargs)
900 self._built = True
901
--> 902 outputs = self.forward(*inputs, **kwargs)
903
904 for forward_post_hook in self._forward_post_hooks.values():
in forward(self, userid, docid, network, device_t, os, province, city, age, gender, category1st, category2nd, dense_features, keywords, click)
211 pred = paddle.cast(pred, 'float32')
212 click = paddle.cast(click, 'float32')
--> 213 loss = F.binary_cross_entropy(pred, click)
214
215 return pred, loss
/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/nn/functional/loss.py in binary_cross_entropy(input, label, weight, reduction, name)
116
117 if in_dygraph_mode():
--> 118 out = core.ops.bce_loss(input, label)
119 if weight is not None:
120 out = core.ops.elementwise_mul(out, weight, 'axis', -1)
ValueError: (InvalidArgument) Input(X) and Input(Label) shall have the same rank.But received: the rank of Input(X) is [0], the rank of Input(Label) is [1].
[Hint: Expected rank == labels_dims.size(), but received rank:0 != labels_dims.size():1.] (at /paddle/paddle/fluid/operators/bce_loss_op.cc:43)
[operator < bce_loss > error]

我对比我传入的特征数据和 现有代码验证模型时传入的特征数据,shape 都一样,现在有点不知道是什么问题了; 请大佬帮助指点一下,应该去哪里找问题

0
收藏
回复
全部评论(4)
时间顺序
三岁
#2 回复于2021-10

你看看输入的数据报错上说的很清楚了啊

 

0
回复
w
wangyjx01
#3 回复于2021-10
三岁 #2
你看看输入的数据报错上说的很清楚了啊  

我对比了一下模型验证时输入的 各个Tensor的shape, 和我后面输入的Tensor的shape,就是一样的,所以我才懵了。 

0
回复
FutureSI
#4 回复于2021-10

报错就是算bce loss时标签的维度没对齐,再检查下标签的维度

0
回复
膳蘸彝癱吻目轎
#5 回复于2021-10

http://ccfdap.wikidot.com/
http://xmadw.wikidot.com/
http://szhen88.wikidot.com/
http://hzp66.wikidot.com/
http://tjfap9.wikidot.com/
http://tjkap6.wikidot.com
http://tianj20.wikidot.com
http://xmazx.wikidot.com/
http://xmcsw.wikidot.com
http://xmaer.wikidot.com
http://xmkdp.wikidot.com
http://xadp.wikidot.com/
http://wuhpp.wikidot.com/
http://xadkpp.wikidot.com/
http://xahakp.wikidot.com/
http://wuhakp.wikidot.com/
http://31kjw.wikidot.com/
http://32kjw.wikidot.com/
http://34kjw.wikidot.com/
http://35kjw.wikidot.com/
http://33kjw.wikidot.com/
http://suz16.wikidot.com/
http://xafaa.wikidot.com/
http://syfwe.wikidot.com/
http://fuziap.wikidot.com/
http://sjz00.wikidot.com/
http://xad213.wikidot.com/
http://wuha63.wikidot.com/
http://sza3.wikidot.com/
http://sjzf9.wikidot.com/
http://sjzsa4.wikidot.com/
http://sjz65.wikidot.com/
http://zzziap.wikidot.com/
http://cskip.wikidot.com/
http://zzjiap.wikidot.com/
http://ccaip.wikidot.com/
http://fo11.wikidot.com/start
http://suz88.wikidot.com/
http://sz06.wikidot.com/
http://fos9.wikidot.com/
http://hnhjnrb579zg2.wikidot.com/
http://hnhjnrb579zg1.wikidot.com/
http://hnhjnrb579zg3.wikidot.com/
http://hnhjnrb579zg4.wikidot.com/
http://hnhjnrb579zg5.wikidot.com/
http://fplvdlh115zg1.wikidot.com/
http://fplvdlh115zg2.wikidot.com/
http://fplvdlh115zg3.wikidot.com/
http://fplvdlh115zg4.wikidot.com/
http://fplvdlh115zg5.wikidot.com/
http://icscooy628zg1.wikidot.com/
http://icscooy628zg2.wikidot.com/
http://icscooy628zg3.wikidot.com/
http://icscooy628zg4.wikidot.com/
http://icscooy628zg5.wikidot.com/
http://xrtvtth195zg1.wikidot.com/
http://xrtvtth195zg2.wikidot.com/
http://xrtvtth195zg3.wikidot.com/
http://xrtvtth195zg4.wikidot.com/
http://xrtvtth195zg5.wikidot.com/
http://ucissso486zg1.wikidot.com/
http://ucissso486zg2.wikidot.com/
http://ucissso486zg3.wikidot.com/
http://ucissso486zg4.wikidot.com/
http://ucissso486zg5.wikidot.com/
http://jbbtlht151zg1.wikidot.com/
http://jbbtlht151zg2.wikidot.com/
http://jbbtlht151zg3.wikidot.com/
http://jbbtlht151zg4.wikidot.com/
http://jbbtlht151zg5.wikidot.com/

0
回复
需求/bug反馈?一键提issue告诉我们
发现bug?如果您知道修复办法,欢迎提pr直接参与建设飞桨~
在@后输入用户全名并按空格结束,可艾特全站任一用户