本文整理匯總了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)