基于Yolact的实例分割:条形码检测

一、环境准备

 下载Yolact

GitHub - dbolya/yolact: A simple, fully convolutional model for real-time instance segmentation.https://github.com/dbolya/yolact

 安装GPU文件版本

cuda_10.2.89_441.22_win10https://developer.nvidia.com/

cudnn-10.2-windows10-x64-v8.1.0.77https://developer.nvidia.com/zh-cn/cudnn

二、数据集准备

1、标记样本

标记样本用的是labelme,最后输出的是”样本+标签“的形式

 2、转coco数据集

转coco数据集需要用到labelme源码,可以从这个位置下载:

labelme/examples/instance_segmentation at main · wkentaro/labelme · GitHubhttps://github.com/wkentaro/labelme/tree/main/examples/instance_segmentation

 训练样本拷贝到data_annotated文件夹下:

 修改/新建labels文件:

 在终端里运行以下代码:

python labelme2coco.py data_annotated train_coco --labels labels.txt

运行结束后会生成一个 train_coco文件夹,内容如下:

 3、Yolact中数据集目录结构

 三、训练与预测

1、下载预训练文件

Image SizeBackbonePPSmAPWeightsaliYun
550Resnet50-FPN42.528.2resnet50-19c8e357.pth阿里云
550Darknet53-FPN40.028.7darknet53.pth阿里云
550Resnet101-FPN33.529.8resnet101_reducedfc.pth阿里云

2、修改配置文件config.py

 训练使用默认配置,可以自行修改训练参数

 3、开始训练

# 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

 训练参数:

–batch_size:大小取决于你的显卡,报错就调小一点
–num_workers:线程数,一般都是需要设置为 “0”
–lr:学习率
–save_folder:训练完后模型保存的路径
–config:config配置文件选择,none为默认配置
–save_interval:每10000次迭代保存模型权重
–validation_epoch:每2个epoch进行一次验证计算
–dataset:数据集路径

 4、预测

# 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

# 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

# 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、效果

 

 

四、部署

关于部署到可以参考这篇文章: 使用opencv部署yolact实例分割。需要注意的是,里面的config.py需要替换成自己训练的配置。

也可直接采用修改好的Yolact版本:GitHub - Ma-Dan/yolact at onnx

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Zzzzzzzzzzzzzz---

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

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

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

打赏作者

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

抵扣说明:

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

余额充值