yolact-train su propio conjunto de datos

yolact-train su propio conjunto de datos

Introducción a yolact

Instalar labelme

pip3 install labelme

labelme

Después de abrir, coloque la imagen y márquela, como:

[Error en la transferencia de la imagen del enlace externo. El sitio de origen puede tener un mecanismo anti-hotlinking. Se recomienda guardar la imagen y subirla directamente (img-KIuYm0eW-1616588123325) (C: \ Users \ zhong \ AppData \ Roaming \ Typora \ typora-user-images \ image-20210324195647022.png)]

Busque las imágenes adecuadas y márquelas una por una. Después de guardar, se generará el archivo json correspondiente.

Descarga el código e instala los paquetes necesarios

git clone https://github.com/x0rzkov/yolact-mini-docker.git

Entrenamiento de modelos

Cambiar ... / data / config.py archivo

1. Cambiar la información relacionada personalizada

CUSTOM_CLASSES = ('smoke',)  #如果只有一样物件需要加上,

CUSTOM_LABEL_MAP = {1: 1}

custom_dataset = Config({'name': 'Custom dataset',
                         'train_images': '/home/jiang/yolact-mini-docker/results/images/output/',  # No need to add 'JPEGImages/'.
                         'train_info': '/home/jiang/yolact-mini-docker/results/images/output/annotations.json',
                         'valid_images': '/home/jiang/yolact-mini-docker/results/images/output/',
                         'valid_info': '/home/jiang/yolact-mini-docker/results/images/output/annotations.json',
                         'class_names': CUSTOM_CLASSES})
#修改路径                         
 
res101_custom_config = res101_coco_config.copy({
    'name': 'res101_custom',
    'dataset': custom_dataset,
    'num_classes': len(custom_dataset.class_names) + 1,
    'batch_size': 8,
    'img_size': 550,  # image size
    'max_iter': 800000,
    'backbone': resnet101_backbone,
    # During training, first compute the maximum gt IoU for each prior.
    # Then, for priors whose maximum IoU is over the positive threshold, marked as positive.
    # For priors whose maximum IoU is less than the negative threshold, marked as negative.
    # The rest are neutral ones and are not used to calculate the loss.
    'pos_iou_thre': 0.5,
    'neg_iou_thre': 0.4,
    # If less than 1, anchors treated as a negative that have a crowd iou over this threshold with
    # the crowd boxes will be treated as a neutral.
    'crowd_iou_threshold': 0.7,
    'conf_alpha': 1,
    'bbox_alpha': 1.5,
    'mask_alpha': 6.125,
    # Learning rate
    'lr_steps': (280000, 600000, 700000, 750000),
    #'lr_steps': (280000,360000,400000),
    'lr': 1e-3,
    'momentum': 0.9,
    'decay': 5e-4,
    # warm up setting
    'warmup_init': 1e-4,
    'warmup_until': 500,
    # The max number of masks to train for one image.
    'masks_to_train': 100,
    # anchor settings
    'scales': [24, 48, 96, 192, 384],
    'aspect_ratios': [1, 1 / 2, 2],
    'use_square_anchors': True,  # This is for backward compatability with a bug.
    # Whether to train the semantic segmentations branch, this branch is only implemented during training.
    'train_semantic': True,
    'semantic_alpha': 1,
    # postprocess hyperparameters
    'conf_thre': 0.05,
    'nms_thre': 0.5,
    'top_k': 200,
    'max_detections': 100,
    # Freeze the backbone bn layer during training, other additional bn layers after the backbone will not be frozen.
    'freeze_bn': False,
    'label_map': CUSTOM_LABEL_MAP})     
#将res101_custom_config替换成可改动的参数                       

Defina un archivo labels.txt en este directorio

__ignore__
_background_
smoke

Ejecutar en el directorio de utils

python3 labelme2coco.py your-image-and-labelme-json-path your-expected-output-folder --labels the-path-of-labels.txt

#样例
python3 labelme2coco.py /home/jiang/yolact-mini-docker/image /home/jiang/yolact-mini-docker/results/images/output --labels /home/jiang/yolact-mini-docker/labels.txt
#注意每次执行这句语句需要清空上次生成的文件夹

Después de la ejecución, se generará una carpeta y se colocarán las imágenes previamente marcadas, y se generará un archivo annotations.json correspondiente

capacitación

python3 train.py --config=res101_custom_config

Evaluación

python3 eval.py --trained_model=latest_res101_custom_801.pth --max_num=1000#注意命名的pth是刚刚自己生成的.pth文件

prueba

python3 detect.py --trained_model=latest_res101_custom_601.pth --image /home/jiang/1#路径为想要检测的图片所在文件夹

Visualización de resultados

Inserte la descripción de la imagen aquí

Link de referencia

  • https://blog.csdn.net/weixin_44878465/article/details/108149285

  • https://github.com/dbolya/yolact

  • https://github.com/x0rzkov/yolact-mini-docker

  • https://github.com/feiyuhuahuo/Yolact_minimal

Supongo que te gusta

Origin blog.csdn.net/zhonglongshen/article/details/115186352
Recomendado
Clasificación