将POLY-YOLO代码跑起来的环境配置,poly-yolo训练自己的数据集

系统:ubuntu16.04和ubuntu18.04

显卡驱动:网上很多教程,百度一下安装就可以。(最简单直接在软件更新里面安装)

cuda安装:下载安装cuda10.0,下载地址:https://developer.nvidia.com/cuda-toolkit-archive 百度网上很多安装教程。

cudnn安装:下载安装cudnn7.6.5-for-cuda10,下载地址:https://developer.nvidia.com/rdp/cudnn-archive 需要注册,百度网上很多教程。

cuda和cudnn的版本要使用10.0和7.6.5不然会出现一些bug。

1. 安装anaconda。https://www.anaconda.com/

2. 创建虚拟环境:poly-yolo推荐的python=3.5,但是测试发现python=3.6也可以。

conda create -n test python=3.6

3. 安装tensorflow-gpu和keras。

conda activate test
pip install tensorflow-gpu==1.15.0
pip install keras==2.3.0

Notice:使用pip安装可能很慢,把pip的源换成阿里云的源速度就快了。教程 https://www.cnblogs.com/FlyerBird/p/10953790.html

4. 安装其他安装包

conda install pillow
conda install matplotlib
pip install opencv-python
conda install jupyter

5. 运行demo

#打开jupyter ,找到poly-yolo/poly-yolo/poly-yolo-inference.ipynb运行demo
jupyter notebook

6.训练网络结构。

6.1 首先需要准备数据集。我们将coco的 val2014数据集转成poly-yolo需要的数据集,脚本如下。将val2014的coco数据集通过下面数据集转换之后就可以得到一个train.txt存储这我们需要的训练标签。标签格式(path_to\image1.jpg x1,y1,x2,y2,class,p1x,p1y,pnx,pny x1,y1,x2,y2,class,p1x,p1y,pnx,pny

import json
from collections import defaultdict

name_box_id = defaultdict(list)
name_segmentation_id = defaultdict(list)
id_name = dict()
f = open(
    "instances_val2014.json",
    encoding='utf-8')
data = json.load(f)

annotations = data['annotations']
for ant in annotations:
    id = ant['image_id']
    name = 'coco/train2014/COCO_val2014_%012d.jpg' % id
    cat = ant['category_id']

    if cat >= 1 and cat <= 11:
        cat = cat - 1
    elif cat >= 13 and cat <= 25:
        cat = cat - 2
    elif cat >= 27 and cat <= 28:
        cat = cat - 3
    elif cat >= 31 and cat <= 44:
        cat = cat - 5
    elif cat >= 46 and cat <= 65:
        cat = cat - 6
    elif cat == 67:
        cat = cat - 7
    elif cat == 70:
        cat = cat - 9
    elif cat >= 72 and cat <= 82:
        cat = cat - 10
    elif cat >= 84 and cat <= 90:
        cat = cat - 11

    name_box_id[name].append([ant['bbox'], cat,ant['segmentation']])

f = open('train.txt', 'w')
for key in name_box_id.keys():
    f.write(key)
    box_infos = name_box_id[key]

    for info in box_infos:
        x_min = int(info[0][0])
        y_min = int(info[0][1])
        x_max = x_min + int(info[0][2])
        y_max = y_min + int(info[0][3])
        box_info = " %d,%d,%d,%d,%d," % (
            x_min, y_min, x_max, y_max, int(info[1]))
        #print(info[2])
        #print('*********************************')
        if isinstance(info[2],list):
            if len(info[2])==1:
                f.write(box_info)
                lista = []
                for i in info[2][0]:
                    i = int(i)
                    lista.append(i)
                f.write(str(lista))      
    f.write('\n')
f.close()

6.2将calss类别修改成coco的80类别,运行训练模型。网络就开始训练了。

python poly-yolo.py

 

你可能感兴趣的:(深度学习,人工智能,tensorflow,深度学习,python)