请问如何只取loss的70%的数据呢?
Created by: yeyupiaoling
环境
- PaddlePaddle (develop)
- Ubuntu 16.04
- Python 3.5
问题
我通过以下得到了一个损失函数,但是我只想取前70%的数据(MTCNN模型要求的),那么该如果做呢?
loss = fluid.layers.cross_entropy(input=cls_prob, label=label_filter_invalid)
我当前这样操作,这样是错误的,
loss = fluid.layers.cross_entropy(input=cls_prob, label=label_filter_invalid)
# 选取70%的数据, batch_size * 0.7
loss, _ = fluid.layers.topk(input=loss, k=22)
return fluid.layers.reduce_sum(loss)
报错如下:
File "/media/test/5C283BCA283BA1C6/yeyupiaoling/PyCharm/TestMTCNN/train/model.py", line 108, in cls_ohem
loss, _ = fluid.layers.topk(input=loss, k=22)
File "/media/test/5C283BCA283BA1C6/yeyupiaoling/PyCharm/TestMTCNN/train/model.py", line 75, in P_Net
label_cost = cls_ohem(cls_prob=cls_prob, label=label)
File "/media/test/5C283BCA283BA1C6/yeyupiaoling/PyCharm/TestMTCNN/train/train_PNet.py", line 14, in <module>
image, label, bbox_target, landmark_target, label_cost, bbox_loss, landmark_loss, conv4_1, conv4_2, conv4_3 = P_Net()
C++ Callstacks:
Enforce failed. Expected input_dims[input_dims.size() - 1] >= k, but received input_dims[input_dims.size() - 1]:1 < k:22.
input must have >= k columns at [/paddle/paddle/fluid/operators/top_k_op.cc:40]
PaddlePaddle Call Stacks: