AI识虫的工具代码
189******30 发布于2020-02 浏览:2412 回复:0
0
收藏

notebook直接运行可查看数据标注,和数据增广后图片的效果。

#查看数据增广augment test

%cd  /home/aistudio/work
from insects_reader import get_insect_names, get_annotations
from reader import get_img_data_from_file
from image_utils import image_augment
import matplotlib.patches as patches
import matplotlib.pyplot as plt

#print(get_insect_names())
#records = get_annotations(get_insect_names(), 'insects/train')
records = get_annotations(get_insect_names(), 'insects/val')
#print(records[0])
num = 100
img, gt_bbox, gt_labels, im_shape = get_img_data_from_file(records[num])
original_bbox_num = records[num]['gt_bbox'].shape[0]
#print(original_bbox_num)
#print(gt_bbox[0:10,:])
#img, gt_boxes, gt_labels = image_augment(img, gt_bbox, gt_labels, img.shape[0])
img, gt_boxes, gt_labels = image_augment(img, gt_bbox, gt_labels, 640)
img = img.astype('int32')
#print(gt_boxes[0:10,:])

plt.figure("Object Detection", figsize=(10, 10))
#for i in range(original_bbox_num):
for i in range(50):
    #print(gt_boxes[i])
    gt_boxes[i] = gt_boxes[i] * img.shape[0]
    #print(gt_boxes[i])
    gt_boxes[i][0] = gt_boxes[i][0] - gt_boxes[i][2] * 0.5
    gt_boxes[i][1] = gt_boxes[i][1] - gt_boxes[i][3] * 0.5
    plt.gca().add_patch(plt.Rectangle(xy=(gt_boxes[i][0], gt_boxes[i][1]),
                                  width=gt_boxes[i][2], 
                                  height=gt_boxes[i][3],
                                  edgecolor='b',
                                  fill=False, linewidth=1))


plt.imshow(img)
收藏
点赞
0
个赞
TOP
切换版块