当前位置: 首页>>代码示例>>Python>>正文


Python visualization_utils.encode_image_array_as_png_str方法代码示例

本文整理汇总了Python中object_detection.utils.visualization_utils.encode_image_array_as_png_str方法的典型用法代码示例。如果您正苦于以下问题:Python visualization_utils.encode_image_array_as_png_str方法的具体用法?Python visualization_utils.encode_image_array_as_png_str怎么用?Python visualization_utils.encode_image_array_as_png_str使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在object_detection.utils.visualization_utils的用法示例。


在下文中一共展示了visualization_utils.encode_image_array_as_png_str方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: visualize_pr_curve

# 需要导入模块: from object_detection.utils import visualization_utils [as 别名]
# 或者: from object_detection.utils.visualization_utils import encode_image_array_as_png_str [as 别名]
def visualize_pr_curve(per_class_precisions, per_class_recalls, global_step, eval_dir,
                       nms_type, nms_iou_threshold, soft_nms_sigma):
  """Visualizes pr curve and writes visualizations to image summaries.

  Args:
    per_class_precisions: precision list of each class
    per_class_recalls: recall list of each class

  """

  subset_keys = per_class_precisions.keys()
  for key in subset_keys:
    precisions_per_class = per_class_precisions[key]
    recalls_per_class = per_class_recalls[key]
    precisions, recalls = compute_pr_curve(precisions_per_class, recalls_per_class)

    # file save
    nms_str = '_'.join(get_string_list_for_nms(nms_type,
                                               nms_iou_threshold,
                                               soft_nms_sigma))

    filename = os.path.join(eval_dir,  'pr_curve_' + key + '_' + nms_str + '.txt')
    # with open(filename, 'wb') as fp:  # Pickling
    #   pickle.dump([precisions, recalls], fp)

    with open(filename, 'w') as f:
      for p,r in zip(precisions, recalls):
        f.write('%f\t%f\n'%(p,r))


    # Unpickling & plot pr curve
    # with open(filename, 'rb') as fp:  # Unpickling
    #   [precisions, recalls] = pickle.load(fp)
    # plt.plot(recalls, precisions, ls='-', lw=1.0)

    # get the figure contents as RGB pixel values
    fig = plt.figure(figsize=[8, 8])
    plt.xlabel('Recall')
    plt.ylabel('Precision')
    plt.title('PR curve')
    plt.plot(recalls, precisions, ls='-', lw=1.0)
    fig.canvas.draw()

    width, height = fig.get_size_inches() * fig.get_dpi()
    image = np.fromstring(fig.canvas.tostring_rgb(), dtype='uint8').reshape(int(height), int(width), 3)

    tag = 'PRcurve_' + key + '_'
    summary = tf.Summary(value=[
      tf.Summary.Value(tag=tag, image=tf.Summary.Image(
        encoded_image_string=vis_utils.encode_image_array_as_png_str(image)))
    ])
    summary_writer = tf.summary.FileWriter(eval_dir)
    summary_writer.add_summary(summary, global_step)
    summary_writer.close()
    time.sleep(1) 
开发者ID:wonheeML,项目名称:mtl-ssl,代码行数:57,代码来源:eval_util.py


注:本文中的object_detection.utils.visualization_utils.encode_image_array_as_png_str方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。