【实例分割】用自己数据集复现经典论文YOLACT

YOLACT:You Only Look At CoefficienTs 

🏆论文下载:paper

🏆代码下载:code

🏆论文详解:YOLACT


目录

🍂🍂1.安装环境

🍂🍂2.数据准备

🌷🌷2.1数据下载

🌷🌷2.2数据格式解析

🍂🍂3.yolact++网络

🍂🍂4.训练yolact

🌷🌷4.1预训练模型

🌷🌷4.2训练网络代码

🌷🌷4.3Pascal SBD数据集

🍂🍂5.测试yolact

🌷🌷5.1测试单张图像并可视化结果

🌷🌷5.2测试单张图像并保存结果影像文件

🌷🌷5.3批量测试文件夹内影像并将结果把保存至指定文件夹 

🌷🌷5.4测试COCO数据集

🌷🌷5.5测试COCO数据集并将测试结果写入bbox_detection.json中

🌷🌷5.6COCO验证

🌷🌷5.7计算COCO验证集精度

整理不易,欢迎一键三连!!!

送你们一条美丽的--分割线--


🍂🍂1.安装环境

        新建安装环境命令:

conda env create -f environment.yml

        版本要求:

  • python3
  • pytorch 1.0.1 及以上版本

        安装cython、opencv、pillow等包命令:

# Cython needs to be installed before pycocotools
pip install cython
pip install opencv-python pillow pycocotools matplotlib 

🍂🍂2.数据准备

🌷🌷2.1数据下载

下载COCO2014/2017数据集,里面有label格式,可以按照这个数据格式准备自己的数据集。这里是废了很大力气的。下载数据集命令:

sh data/scripts/COCO_test.sh

        下载数据界面,过程可能比较慢。。。

🌷🌷2.2数据格式解析

        标注文件:instances_train2017.json
        以 COCO2017\annotations_train2017\annotations\instances_train2017.json
为例。这个json文件中的信息有以下5个键值所指。
        基本结构如下:

        数据集标注json文件所在目录annotations_train2017,详细文件制作过程请参考【COCO】制作自己的coco格式实例分割数据集

  • 可以在  data/config.py 文件中的dataset_base添加自己的数据集,比如:
my_custom_dataset = dataset_base.copy({
    'name': 'My Dataset',

    'train_images': 'path_to_training_images',
    'train_info':   'path_to_training_annotation',

    'valid_images': 'path_to_validation_images',
    'valid_info':   'path_to_validation_annotation',

    'has_gt': True,
    'class_names': ('my_class_id_1', 'my_class_id_2', 'my_class_id_3', ...)
})

🍂🍂3.yolact++网络

        使用yolact++网络,需要安装DCNv2网络

cd external/DCNv2
python setup.py build develop

🍂🍂4.训练yolact

        默认在coco数据集上训练,所以需要保证第2步制作的数据集是完整的coco格式,否则无法训练。

🌷🌷4.1预训练模型

  • 预训练模型应该放在 ./weights目录下
    • 下载 resnet101_reducedfc.pth—— here.
    • 下载 resnet50-19c8e357.pth —— here.
    • 下载darknet53.pth —— here.
  • 训练命令
    • 训练过程中使用ctrl+c终止训练,此时会保存一个 *_interrupt.pth 文件在当前目录.
    • 所有训练模型均存放在 ./weights 目录下,文件名命名方式为:<config>_<epoch>_<iter>.pth.

🌷🌷4.2训练网络代码

        可以通过修改config文件来修改训练参数。

# Trains using the base config with a batch size of 8 (the default).
python train.py --config=yolact_base_config

# Trains yolact_base_config with a batch_size of 5. For the 550px models, 1 batch takes up around 1.5 gigs of VRAM, so specify accordingly.
python train.py --config=yolact_base_config --batch_size=5

# Resume training yolact_base with a specific weight file and start from the iteration specified in the weight file's name.
python train.py --config=yolact_base_config --resume=weights/yolact_base_10_32100.pth --start_iter=-1

# Use the help option to see a description of all available command line arguments
python train.py --help

        多卡训练需要再以上代码前面加上一句export CUDA_VISIBLE_DEVICES=[gpus]命令来实现多卡训练。

        如果要用自己的数据集进行训练,需要修改yolact_base_config文件中的‘dataset’内容为‘my_custom_dataset’

🌷🌷4.3Pascal SBD数据集

        我们也支持Pascal SBD数据集,训练步骤如下:

  1. 从 here下载Pascal SBD数据集 下载到的数据集压缩包为benchmark.tgz
  2. 提取影像。 创建目录./data/sbd 复制 dataset/img 到 ./data/sbd/img目录下
  3. 下载COCO格式的label信息——下载地址 here.
  4. 提取label信息 ./data/sbd/.
  5. 通过 --config=yolact_resnet50_pascal_config进行PascalSBD数据集训练 

        工程支持通过 ./scripts/convert_sbd.py文件进行label格式转换。

  为验证效果,可以从 here下载 yolact_resnet50_pascal_config格式的训练模型进行比对。

🍂🍂5.测试yolact

🌷🌷5.1测试单张图像并可视化结果

# Display qualitative results on the specified image.
python eval.py --trained_model=weights/yolact_base_54_800000.pth --score_threshold=0.15 --top_k=15 --image=my_image.png

🌷🌷5.2测试单张图像并保存结果影像文件

# Process an image and save it to another file.
python eval.py --trained_model=weights/yolact_base_54_800000.pth --score_threshold=0.15 --top_k=15 --image=input_image.png:output_image.png

🌷🌷5.3批量测试文件夹内影像并将结果把保存至指定文件夹 

# Process a whole folder of images.
python eval.py --trained_model=weights/yolact_base_54_800000.pth --score_threshold=0.15 --top_k=15 --images=path/to/input/folder:path/to/output/folder

🌷🌷5.4测试COCO数据集

# This should get 29.92 validation mask mAP last time I checked.
python eval.py --trained_model=weights/yolact_base_54_800000.pth

🌷🌷5.5测试COCO数据集并将测试结果写入bbox_detection.json中

# Output a COCOEval json to submit to the website or to use the run_coco_eval.py script.
# This command will create './results/bbox_detections.json' and './results/mask_detections.json' for detection and instance segmentation respectively.

python eval.py --trained_model=weights/yolact_base_54_800000.pth --output_coco_json

🌷🌷5.6COCO验证

# You can run COCOEval on the files created in the previous command. The performance should match my implementation in eval.py.
python run_coco_eval.py

🌷🌷5.7计算COCO验证集精度

# To output a coco json file for test-dev, make sure you have test-dev downloaded from above and go
python eval.py --trained_model=weights/yolact_base_54_800000.pth --output_coco_json --dataset=coco2017_testdev_dataset

整理不易,欢迎一键三连!!!


送你们一条美丽的--分割线--

🌷🌷🍀🍀🌾🌾🍓🍓🍂🍂🙋🙋🐸🐸🙋🙋💖💖🍌🍌🔔🔔🍉🍉🍭🍭🍋🍋🍇🍇🏆🏆📸📸⛵⛵⭐⭐🍎🍎👍👍🌷🌷

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zy_destiny

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值