parameters: (im, target, result, info, masker)
docstring: Visualize gt and predicted box, tag, mask, and RECIST
docstring_summary: Visualize gt and predicted box, tag, mask, and RECIST
docstring_tokens: Visualize gt and predicted box tag mask and RECIST
function: def visualize(im, target, result, info, masker):
      """Visualize gt and predicted box, tag, mask, and RECIST"""
      print('\n lesion_idxs', info['lesion_idxs'], ':', info['image_fn'])
      if 'tags' in info.keys():
          print('gt tags:')
          for tags in target.get_field('tags'):
              idx = torch.nonzero(tags > 0)
              msg = ', '.join([cfg.runtime_info.tag_list[idx1] for idx1 in idx])
              print(msg)
      if 'diameters' in info.keys():
          print('gt diameters:')
          print(info['diameters'])
  
      im = windowing_rev(im + cfg.INPUT.PIXEL_MEAN, cfg.INPUT.WINDOWING)
      im = windowing(im, info['window']).astype('uint8')
      im = cv2.cvtColor(im, cv2.COLOR_GRAY2RGB)
  
      gt = target.bbox.cpu().numpy()
      gt_recists = info['recists']
  
      scale = cfg.TEST.VISUALIZE.SHOW_SCALE
      im = cv2.resize(im, None, None, fx=scale, fy=scale, interpolation=cv2.INTER_LINEAR)
      gt *= scale
      gt_recists *= scale
      overlay, msgs = draw_results(im, gt, recists=gt_recists, colors=(0, 255, 0), thickness=(2,1,1))
  
      pred = result.bbox.cpu().numpy()
      labels = result.get_field('labels').cpu().numpy()
      scores = result.get_field('scores').cpu().numpy()
      tag_scores = result.get_field('tag_scores').cpu().numpy()
      tag_predictions = result.get_field('tag_predictions').cpu().numpy()
  
      # if cfg.MODEL.MASK_ON and len(result.get_field('contour_mm')) > 0:
      mm2pix = info['im_scale'] / info['spacing'] * scale
      contours = result.get_field('contour_mm').cpu().numpy() * mm2pix
      contours = [c[c[:,0]>0, :] for c in contours]
      contours = [c+1*scale for c in contours]  # there seems to be a small offset in the mask?
      recists = result.get_field('recist_mm').cpu().numpy() * mm2pix
      recists += 1*scale   # there seems to be a small offset in the mask?
      diameters = result.get_field('diameter_mm').cpu().numpy()
  
      pred *= scale
      overlay, msgs = draw_results(overlay, pred, labels, scores, tag_predictions=tag_predictions, tag_scores=tag_scores,
                             contours=contours, recists=recists, diameters=diameters)
      plt.figure(1)
      plt.imshow(overlay)
      for msg in msgs:
          print(msg)
  
      if cfg.TEST.VISUALIZE.SHOW_MASK_HEATMAPS and 'mask' in result.extra_fields.keys():
          plt.figure(2)
          mask = result.get_field('mask')
          mask = masker([mask], [result])[0]
          mask = mask.numpy()
          mask0 = cv2.resize(mask[0, 0], None, None, fx=scale, fy=scale)
          mask1 = np.empty((mask.shape[0], mask.shape[1], mask0.shape[0], mask0.shape[1]), dtype=mask.dtype)
          for i1 in range(mask.shape[0]):
              for i2 in range(mask.shape[1]):
                  mask1[i1, i2] = cv2.resize(mask[i1, i2], None, None, fx=scale, fy=scale,
                                             interpolation=cv2.INTER_NEAREST)
  
          pred *= scale
          heatmap = np.sum(mask1, (0, 1)).astype('uint8')
          # heatmap = cv2.applyColorMap(heatmap, cv2.COLORMAP_JET)
          plt.imshow(heatmap, cmap='gray')
      plt.show()
function_tokens: def visualize ( im , target , result , info , masker ) : print ( '\n lesion_idxs' , info [ 'lesion_idxs' ] , ':' , info [ 'image_fn' ] ) if 'tags' in info . keys ( ) : print ( 'gt tags:' ) for tags in target . get_field ( 'tags' ) : idx = torch . nonzero ( tags > 0 ) msg = ', ' . join ( [ cfg . runtime_info . tag_list [ idx1 ] for idx1 in idx ] ) print ( msg ) if 'diameters' in info . keys ( ) : print ( 'gt diameters:' ) print ( info [ 'diameters' ] ) im = windowing_rev ( im + cfg . INPUT . PIXEL_MEAN , cfg . INPUT . WINDOWING ) im = windowing ( im , info [ 'window' ] ) . astype ( 'uint8' ) im = cv2 . cvtColor ( im , cv2 . COLOR_GRAY2RGB ) gt = target . bbox . cpu ( ) . numpy ( ) gt_recists = info [ 'recists' ] scale = cfg . TEST . VISUALIZE . SHOW_SCALE im = cv2 . resize ( im , None , None , fx = scale , fy = scale , interpolation = cv2 . INTER_LINEAR ) gt *= scale gt_recists *= scale overlay , msgs = draw_results ( im , gt , recists = gt_recists , colors = ( 0 , 255 , 0 ) , thickness = ( 2 , 1 , 1 ) ) pred = result . bbox . cpu ( ) . numpy ( ) labels = result . get_field ( 'labels' ) . cpu ( ) . numpy ( ) scores = result . get_field ( 'scores' ) . cpu ( ) . numpy ( ) tag_scores = result . get_field ( 'tag_scores' ) . cpu ( ) . numpy ( ) tag_predictions = result . get_field ( 'tag_predictions' ) . cpu ( ) . numpy ( ) # if cfg.MODEL.MASK_ON and len(result.get_field('contour_mm')) > 0: mm2pix = info [ 'im_scale' ] / info [ 'spacing' ] * scale contours = result . get_field ( 'contour_mm' ) . cpu ( ) . numpy ( ) * mm2pix contours = [ c [ c [ : , 0 ] > 0 , : ] for c in contours ] contours = [ c + 1 * scale for c in contours ] # there seems to be a small offset in the mask? recists = result . get_field ( 'recist_mm' ) . cpu ( ) . numpy ( ) * mm2pix recists += 1 * scale # there seems to be a small offset in the mask? diameters = result . get_field ( 'diameter_mm' ) . cpu ( ) . numpy ( ) pred *= scale overlay , msgs = draw_results ( overlay , pred , labels , scores , tag_predictions = tag_predictions , tag_scores = tag_scores , contours = contours , recists = recists , diameters = diameters ) plt . figure ( 1 ) plt . imshow ( overlay ) for msg in msgs : print ( msg ) if cfg . TEST . VISUALIZE . SHOW_MASK_HEATMAPS and 'mask' in result . extra_fields . keys ( ) : plt . figure ( 2 ) mask = result . get_field ( 'mask' ) mask = masker ( [ mask ] , [ result ] ) [ 0 ] mask = mask . numpy ( ) mask0 = cv2 . resize ( mask [ 0 , 0 ] , None , None , fx = scale , fy = scale ) mask1 = np . empty ( ( mask . shape [ 0 ] , mask . shape [ 1 ] , mask0 . shape [ 0 ] , mask0 . shape [ 1 ] ) , dtype = mask . dtype ) for i1 in range ( mask . shape [ 0 ] ) : for i2 in range ( mask . shape [ 1 ] ) : mask1 [ i1 , i2 ] = cv2 . resize ( mask [ i1 , i2 ] , None , None , fx = scale , fy = scale , interpolation = cv2 . INTER_NEAREST ) pred *= scale heatmap = np . sum ( mask1 , ( 0 , 1 ) ) . astype ( 'uint8' ) # heatmap = cv2.applyColorMap(heatmap, cv2.COLORMAP_JET) plt . imshow ( heatmap , cmap = 'gray' ) plt . show ( )