记第一次Faster RCNN调试过程

本文记录了使用Faster RCNN进行光学镜片疵病质检项目的调试过程,包括解决CUDA编译问题,制作自定义数据集,调整pytorch环境,以及在训练中遇到的问题和解决方案。数据来源于'飞粤云端2018'比赛,经过处理生成XML文件,最终在GPU服务器上成功训练并得到64%左右的mAP。
摘要由CSDN通过智能技术生成

本文仅做记录,供本人私下查阅。

调试Faster RCNN的初衷是进行光学镜片表面疵病质检项目,找到了一个Faster RCNN开源代码,github地址:https://github.com/jwyang/faster-rcnn.pytorch,master分支使用的是pythorc0.4.0,与GPU服务器上的环境不匹配导致CUDA编译失败。最后选择的是pytorch-1.0分支,在GPU服务器上调试成功,项目位于根目录下,项目名称为faster-rcnn.pytorch-pytorch-1.0,使用的是anaconda虚拟环境lvcai(位于~/anaconda2/envs)。

在环境匹配之后,根据readme教程调试Faster RCNN的过程比较顺利,后面换成自己的数据集训练的过程中,存在一些问题,此处简要记录以便后续查阅。
问题1: 前期使用master分支时,因为torch版本较高,导致CUDA编译不通过,另外还会导致torch.cuda.is_available() 是False,导致代码跑不起来。

记录制作自己数据集的过程

此处使用的是 [飞粤云端2018]广东工业智造大数据创新大赛—智能算法赛 的数据,因为比赛已经结束,数据无法下载,在自己的百度网盘中存有这份数据‘lvcaidata’, 百度云链接: https://pan.baidu.com/s/17ZqPss30HnktdEKdYF7gkg 提取码: ji7g

使用的数据为赛制第二阶段的数据,数据格式为:
在这里插入图片描述
在这里插入图片描述

每种瑕疵中均包含图片和其对应的json文件。其中单瑕疵图片中是分类别的,多瑕疵图片没有分类别(上面的截图中没有图片)。

第一步: 新建一个voc2007文件夹,并有这样的结构。
在这里插入图片描述
第二步: 将自己数据集中的图片都移动到VOC2007/JPEGImages/目录下,将所有json汇总到一起,汇总到一个临时文件夹中

import os
import shutil
import sys
reload(sys)
sys.setdefaultencoding('utf8')

# 将图片都移动到 VOC2007/JPEGImages/目录下
path = "/guangdong_round2_train_20181011/单瑕疵图片/"
dst_path = "voc2007/JPEGImages/"

files = os.listdir(path)
for f in files:
    print(f.decode('utf-8'))
    path2 = path + f.decode('utf-8') + '/'
    print(path2)
    if os.path.isdir(path2):
        all_files = os.listdir(path2)
        for af in all_files:
            if af.endswith('.jpg'):
                print(af.decode('utf-8'))
                print(path2+af.decode('utf-8'))

                shutil.move(path2+af.decode('utf-8'), dst_path)


path = "lvcaidata/guangdong_round2_train_20181011/多瑕疵图片/"
dst_path = "/voc2007/JPEGImages/"

files = os.listdir(path)
for f in files:
    print(f.decode('utf-8'))
    path2 = path + f.decode('utf-8')
    print(path2)
    if path2.endswith('.jpg'):
        shutil.move(path2, dst_path)

# 将所有json汇总到一起,汇总到一个临时文件夹中
path = "guangdong_round2_train_20181011/单瑕疵图片/"
dst_path = "guangdong_round2_train_20181011/json/"

files = os.listdir(path)
for f in files:
    print(f.decode('utf-8'))
    path2 = path + f.decode('utf-8') + '/'
    print(path2)
    if os.path.isdir(path2):
        all_files = os.listdir(path2)
        for af in all_files:
            if af.endswith('.json'):
                print(af.decode('utf-8'))
                print(path2+af.decode('utf-8'))

                shutil.move(path2+af.decode('utf-8'), dst_path)


path = "guangdong_round2_train_20181011/多瑕疵图片/"
dst_path = "guangdong_round2_train_20181011/json"

files = os.listdir(path)
for f in files:
    print(f.decode('utf-8'))
    path2 = path + f.decode('utf-8')
    print(path2)
    if path2.endswith('.json'):
        shutil.move(path2, dst_path)

第三步: 处理json文件,生成xml文件,并生成训练集、验证集和测试集

# -*- coding=utf-8-*-
import os
import numpy as np
import codecs
import json
from glob import glob
import cv2
import shutil
from sklearn.model_selection import train_test_split

label_warp = <
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值