yolov3实现之coco数据集目标检测准备

coco数据集不仅可以用于做目标检测还可以用于进行语义分割,这里主要讲解基于yolov3进行目标检测的数据准备。由于coco数据集的标签信息是以.json的格式存储的,因此有必要转换为具体的格式来进行模型训练与评估。具体的实现方式如下:

# -*- coding: utf-8 -*-
"""
Created on Tue Jul  2 11:41:44 2019

@author: Administrator
"""
#from __feature__ import print_function
import os,sys,zipfile
import json
import glob


def convert(size,box):
    dw = 1. / (size[0])
    dh = 1. / (size[1])
    x = box[0] + box[2] / 2.0
    y = box[1] + box[3] / 2.0
    w = box[2]
    h = box[3]
    
    x = x * dw
    w = w * dw
    y = y * dh
    h = h * dh
    
    return (x,y,w,h)


def get_coco_data(path):
    
    data = json.load(open(path,'r'))
    imgs = data['images']
    annotations = data['annotations']
    
    print(len(imgs))
    
    
    for img in imgs:
        filename = img['file_name']
        img_w = img['width']
      
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值