当前位置: 首页> 汽车> 车展 > 实例分割-Yolact/Yolact++训练自己数据集

实例分割-Yolact/Yolact++训练自己数据集

时间:2025/7/9 15:51:23来源:https://blog.csdn.net/weixin_54678439/article/details/140869569 浏览次数: 0次

前言
本文主要用于记录实例分割模型yolact和yolact++的环境配置,以及成功训练自己数据集的整个过程~

注意:这里要重点提醒一下,DCNv2对RTX系列不友好,我第一次使用4090服务器,编译持续有问题,被迫放弃,这里使用2080TI进行操作!

源码地址:https://github.com/dbolya/yolact

目录

  • 一、Yolact环境配置
  • 二、训练准备
  • 三、yolact训练
  • 四、 数据集测试
  • 五、Yolact++环境配置

一、Yolact环境配置

基础环境:python=3.8、pytorch=1.7.0、cuda=11.0、ubuntu18.04

1、创建一个anaconda虚拟环境

conda create -n yolact python=3.8  //环境名为yolact ,python版本选择3.8
conda activate yolact              //激活yolact 环境

2.查看安装的:

nvcc --version #查看cuda版本python     #查看pytorch
>>> import torch
>>> print(torch.cuda.is_available())
True
>>> print(torch.version.cuda)
11.0

3.安装所需要的依赖:

pip install cython
pip install opencv-python
pip install pillow
pip install pycocotools#用此方式:pip install git+https://github.com/philferriere/cocoapi.git#subdirectory=PythonAPI
pip install matplotlib 

二、训练准备

1、下载预训练权重

把权重文件放到yolact-master下的weights文件夹里

下载地址:https://github.com/dbolya/yolact

在这里插入图片描述

2、数据集文件夹结构

在这里插入图片描述
coco文件夹,里面包含annotations以及images。其中annotations包含instances_train2017.json以及instances_val2017.json; images中包含train2017以及val2017用于存放训练与验证数据集。

3、参数修改

(1)coco_classes与coco_label_map

修改数据加载的位置即可,具体来说,找到./data/config.py目录,为自己的数据集格式
在这里插入图片描述

(2)dataset_base地址

在这里插入图片描述

将训练数据集和验证数据集的加载地址切换为自己的数据集地址,注意此处只要修改了images的地址就可以

(3)修改coco2014_dataset或coco2017_dataset的信息,如下:

在这里插入图片描述

(4)修改coco_base_config

此处的max_iter并不是控制训练轮数的

在这里插入图片描述

(5)修改yolact_base_config
在这里插入图片描述

(6)其他的训练参数在train.py文件处修改

parser = argparse.ArgumentParser(description='Yolact Training Script')
parser.add_argument('--batch_size', default=8, type=int,help='Batch size for training')
parser.add_argument('--resume', default=None, type=str,help='Checkpoint state_dict file to resume training from. If this is "interrupt"'\', the model will resume training from the interrupt file.')
parser.add_argument('--start_iter', default=-1, type=int,help='Resume training at this iter. If this is -1, the iteration will be'\'determined from the file name.')
parser.add_argument('--num_workers', default=4, type=int,help='Number of workers used in dataloading')
parser.add_argument('--cuda', default=True, type=str2bool,help='Use CUDA to train model')
parser.add_argument('--lr', '--learning_rate', default=None, type=float,help='Initial learning rate. Leave as None to read this from the config.')
parser.add_argument('--momentum', default=None, type=float,help='Momentum for SGD. Leave as None to read this from the config.')
parser.add_argument('--decay', '--weight_decay', default=None, type=float,help='Weight decay for SGD. Leave as None to read this from the config.')
parser.add_argument('--gamma', default=None, type=float,help='For each lr step, what to multiply the lr by. Leave as None to read this from the config.')
parser.add_argument('--save_folder', default='weights/',help='Directory for saving checkpoint models.')
parser.add_argument('--log_folder', default='logs/',help='Directory for saving logs.')
parser.add_argument('--config', default=None,help='The config object to use.')
parser.add_argument('--save_interval', default=10000, type=int,help='The number of iterations between saving the model.')
parser.add_argument('--validation_size', default=5000, type=int,help='The number of images to use for validation.')
parser.add_argument('--validation_epoch', default=2, type=int,help='Output validation information every n iterations. If -1, do no validation.')
parser.add_argument('--keep_latest', dest='keep_latest', action='store_true',help='Only keep the latest checkpoint instead of each one.')
parser.add_argument('--keep_latest_interval', default=100000, type=int,help='When --keep_latest is on, don\'t delete the latest file at these intervals. This should be a multiple of save_interval or 0.')
parser.add_argument('--dataset', default=None, type=str,help='If specified, override the dataset specified in the config with this one (example: coco2017_dataset).')
parser.add_argument('--no_log', dest='log', action='store_false',help='Don\'t log per iteration information into log_folder.')
parser.add_argument('--log_gpu', dest='log_gpu', action='store_true',help='Include GPU information in the logs. Nvidia-smi tends to be slow, so set this with caution.')
parser.add_argument('--no_interrupt', dest='interrupt', action='store_false',help='Don\'t save an interrupt when KeyboardInterrupt is caught.')
parser.add_argument('--batch_alloc', default=None, type=str,help='If using multiple GPUS, you can set this to be a comma separated list detailing which GPUs should get what local batch size (It should add up to your total batch size).')
parser.add_argument('--no_autoscale', dest='autoscale', action='store_false',help='YOLACT will automatically scale the lr and the number of iterations depending on the batch size. Set this if you want to disable that.')

三、yolact训练

python train.py --config=yolact_base_config

训练如下:

在这里插入图片描述

四、 数据集测试

python eval.py --trained_model=weights/yolact_base_0_500.pth --benchmark --max_images=1000

效果如下:

在这里插入图片描述

五、Yolact++环境配置

关键字:实例分割-Yolact/Yolact++训练自己数据集

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: