You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by gi...@git.apache.org on 2017/09/23 05:42:04 UTC

[GitHub] chinakook opened a new issue #8001: mx.metric.EvalMetric bug

chinakook opened a new issue #8001: mx.metric.EvalMetric bug
URL: https://github.com/apache/incubator-mxnet/issues/8001
 
 
   My ClsMetric can run tomorrow, but cannot run on the new version of today:
   
   My last layer is a group of **five** predictions
   net = mx.symbol.Group([mx.sym.BlockGrad(pred_cls, name='test'), mx.sym.BlockGrad(clsmap, name='clsmap'),mx.sym.BlockGrad(smooth_l1, name='l1'), det_loss, huber_loss])
   
   **CODE:**
   
   class ClsMetric(mx.metric.EvalMetric):
       def __init__(self, output_names=None):
           super(ClsMetric, self).__init__('MyCls')
           #print(self.output_names)
           self.output_names = output_names
           self.num = 2
           self.name = ['cls_metric', 'l1_loss']#['test_output', 'clsmap_output']
           self.reset()
       def reset(self):
           if getattr(self, 'num', None) is None:
               self.num_inst = 0
               self.sum_metric = 0.0
           else:
               self.num_inst = [0] * self.num
               self.sum_metric = [0.0] * self.num
       
       def update(self, labels, preds):
           #print(len(preds))
           pred = preds[0].asnumpy()
           label = preds[1].asnumpy()
           pred_l1 = preds[2].asnumpy()
           
           #pred = 1 / (1 + np.exp(-pred))
           
           pred[pred>=0]= 1
           pred[pred<0]= -1
           
           self.sum_metric[0] += (pred == label).sum()
           self.num_inst[0] += (label != 0).sum()
           
           self.sum_metric[1] += pred_l1.sum()
           self.num_inst[1] += (label > 0).sum()
           
       def get(self):
           if self.num is None:
               if self.num_inst == 0:
                   return (self.name, float('nan'))
               else:
                   return (self.name, self.sum_metric / self.num_inst)
           else:
               names = ['%s'%(self.name[i]) for i in range(self.num)]
               values = [x / y if y != 0 else float('nan')
                   for x, y in zip(self.sum_metric, self.num_inst)]
               return (names, values)
   
   **ERROR:**
   <ipython-input-22-210288181e31> in update(self, labels, preds)
        20         pred = preds[0].asnumpy()
        21         label = preds[1].asnumpy()
   ---> 22         pred_l1 = preds[2].asnumpy()
        23 
        24         #pred = 1 / (1 + np.exp(-pred))
   
   IndexError: list index out of range
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services