加入收藏 | 设为首页 | 会员中心 | 我要投稿 好传媒门户网 (https://www.haochuanmei.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 移动互联 > 正文

用PaddlePaddle 实现目标检测任务——Paddle Fluid v1.1深度测评

发布时间:2018-12-15 05:31:47 所属栏目:移动互联 来源:睿博远航
导读:【51CTO.com原创稿件】 1.前言 11月1日,百度发布了Paddle Fluid的1.1版本,作为国内首个深度学习框架,PaddlePaddle对中文社区非常友好,有完善的中文社区、项目为导向的中文教程,可以让更多中文使用者更方便地进行深度学习、机器学习相关的研究和实践。

可以看一下这个reader的核心代码:

def reader():

if mode == 'train' and shuffle:

np.random.shuffle(images)

batch_out = []

for image in images:

image_name = image['file_name']

image_path = os.path.join(settings.data_dir, image_name)

im = Image.open(image_path)

if im.mode == 'L':

im = im.convert('RGB')

im_width, im_height = im.size

im_id = image['id']

# layout: category_id | xmin | ymin | xmax | ymax | iscrowd

bbox_labels = []

annIds = coco.getAnnIds(imgIds=image['id'])

anns = coco.loadAnns(annIds)

for ann in anns:

bbox_sample = []

# start from 1, leave 0 to background

bbox_sample.append(float(ann['category_id']))

bbox = ann['bbox']

xmin, ymin, w, h = bbox

xmax = xmin + w

ymax = ymin + h

bbox_sample.append(float(xmin) / im_width)

bbox_sample.append(float(ymin) / im_height)

bbox_sample.append(float(xmax) / im_width)

bbox_sample.append(float(ymax) / im_height)

bbox_sample.append(float(ann['iscrowd']))

bbox_labels.append(bbox_sample)

im, sample_labels = preprocess(im, bbox_labels, mode, settings)

sample_labels = np.array(sample_labels)

if len(sample_labels) == 0: continue

im = im.astype('float32')

boxes = sample_labels[:, 1:5]

lbls = sample_labels[:, 0].astype('int32')

iscrowd = sample_labels[:, -1].astype('int32')

if 'cocoMAP' in settings.ap_version:

batch_out.append((im, boxes, lbls, iscrowd,

[im_id, im_width, im_height]))

else:

batch_out.append((im, boxes, lbls, iscrowd))

if len(batch_out) == batch_size:

yield batch_out

batch_out = []

可以看到,这里的reader是一个生成器,逐个batch把数据load进内存。在数据读取过程中,需要注意一下几点:

1. 数据集需要放在项目的data目录下,reader通过annotations下的instances_train2017.json文件区分训练集和验证集,不需要在data目录下用文件夹区分训练集和验证集。

(编辑:好传媒门户网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读