YOLOv3学习使用笔记(coco)

一、下载准备

  • 下载数据集
    在这里插入图片描述
  • 下载YOLOv3
https://github.com/ultralytics/yolov3
  • 验证训练集
    在这里插入图片描述
    在这里插入图片描述

二、JSON解析

  • 生成train-set标注txt
# 新建make_txt.py 文件
import os
import json

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)

data = json.load(open('./data/annotations/train.json', 'r'))

ana_txt_save_path = "/Users/jimmy/Desktop/jupyter/train_val/train"  # 与训练集同目录

for img in data['images']:
    filename = img["file_name"]
    img_width = img["width"]
    img_height = img["height"]
    img_id = img["id"]
    ana_txt_name = filename.split(".")[0] + ".txt"  # 对应的txt名字,与jpg一致
    f_txt = open(os.path.join(ana_txt_save_path, ana_txt_name), 'w')
    for ann in data['annotations']:
        if ann['image_id'] == img_id:
            box = convert((img_width, img_height), ann["bbox"])
            f_txt.write("%s %s %s %s %s\n" % (ann["category_id"], box[0], box[1], box[2], box[3]))
    f_txt.close()
  • 生成train、val绝对路径至txt
import os


def readFilename(path,txtpath):
    filelist = os.listdir(path)

    for filename in filelist:
        filepath = os.path.join(path, filename)
        with open(txtpath,'a') as w:
            w.write(filepath + '\n')


if __name__ == '__main__':
    imgpath = "/Users/jimmy/Desktop/jupyter/train_val/train" # 训练图片的文件夹
    txtpath = "/Users/jimmy/Downloads/yolov3-master/train_txt" # 放入的txt文件

    readFilename(imgpath,txtpath)

训练预测

  • 修改参数weights、classes,cuda等,开始训练
  • 训练后选取logs下的weights进行预测
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值