@wkcn 
我是一开始定义了自己的softmax层后,出现了这个issue的报错src/io/image_io.cc:186: Check failed: 
inputs[0].ctx().dev_mask() == Context::kCPU (2 vs. 1) Only supports cpu input,
然后根据这个issue改了之后,就是修改Imge.py之后,在AccMetric里面就出现了src/ndarray/ndarray_function.cu:43:
 Check failed: to->type_flag == from.type_flag_ (0 vs. 3) Source and target 
must have the same data type when copying across devices.这个问题
这个问题具体是在pred_label = 
pred_label.asnumpy().astype('int32').flatten()的时候出现的,然后当我尝试在这句话前面(某些地方,有些地方可以,有些地方也会报错)将pred_label直接print输出的时候,他是有时会正常运行不会报错,但是每次当pred_label调用到asnumpy()的时候就会报这个错
class GenderAccMetric(mx.metric.EvalMetric):
  def __init__(self):
    self.axis = 1
    super(GenderAccMetric, self).__init__(
        'acc', axis=self.axis,
        output_names=None, label_names=None)
    self.losses = []
    self.count = 0

  def update(self, _labels, preds):
    self.count+=1
    #print("in gender AccMetric\n")
    #print("label is {}\n".format(_labels[2])) 
    #print("preds is {}\n".format(preds[3]))  当输出label和preds时,有时会正常运行
    labels = [_labels[2]]
    _preds = [preds[3]] #use softmax output
    for label, pred_label in zip(labels, _preds):
        #print("pred_label before if is {}\n".format(pred_label)) 在这里输出也会报错
        pred_label = pred_label.as_in_context(label.context) 加上了这句话还是不行
        if pred_label.shape != label.shape:
            #pred_label = mx.ndarray.array(_pred_label, 
ctx=mx.current_context())其中一个AccMetric在这里进行转换就解决了问题,但剩下的两个不行
            pred_label = mx.ndarray.argmax(pred_label, axis=self.axis)
        pred_label = pred_label.asnumpy().astype('int32').flatten()
        label = label.asnumpy()
        if label.ndim==2:
          label = label[:,0]
        label = label.astype('int32').flatten()
        assert label.shape==pred_label.shape
        self.sum_metric += (pred_label.flat == label.flat).sum()
        self.num_inst += len(pred_label.flat)

所以总的来说,我感到非常奇怪和困扰,按照你说的方法改了还是不行,我感觉是只要是pred调用了asnumpy()就会报错


[ Full content available at: 
https://github.com/apache/incubator-mxnet/issues/9920 ]
This message was relayed via gitbox.apache.org for [email protected]

Reply via email to