Implement your own dataset using BiSeNet

Dataset preparation

Dataset: Segmentation of remote sensing house images, divided into two times, mainly to realize the area change of the building area with time.
insert image description here

Baidu cloud: https://pan.baidu.com/s/1HlnKWToc00986jiTxhq_CA
Extraction code:RSAI

data processing

1. Dataset

datasetsThe data set is stored in a folder under the root directory , cocoalongside citythe data set. If the label of your data set is already set 0,1, you can ignore it label_255. If the label has not been 255-->1converted, you can put the label file first label_255.

—BiSeNet
---------datasets
-----------------coco
-----------------cityscapes
-----------------time
-----------------------train
------------------------------image
------------------------------label_255
------------------------------label
-----------------------val
------------------------------image
------------------------------label_255
------------------------------label

2. datasets/times/Create under the folderone.py

The purpose is to 0,255convert the label of 0,1. If it is multi-category, then the label is 0,1,2,3,...n
only the file in the code that is converted train. To convert the file in val, modify it traintoval

import os
import cv2 as cv
labels_path = './train/label_255'
labels_save_path = './train/label'
lab_names = os.listdir(labels_path)
for s in lab_names:
    label_path = os.path.join(labels_path, s)
    label_save_path = os.path.join(labels_save_path, s)
    label = cv.imread(label_path, 0)
    label[label!=0]=1
    cv.imwrite(label_save_path, label)

2. Create a file datasets/times/under the folderutil.py

The purpose is to generate train.txtfiles and val.txtfiles. To convert files, you only need to replace val.txtall of the following codes (there are three places)trainval

import os
image_path = './train/image'
label_path = './train/label'
image_names = os.listdir(image_path)
for s in image_names:
    image = os.path.join(image_path, s)
    label = os.path.join(label_path, s)
    with open('train.txt', 'a') as fin:
        fin.write(image[2:] +","+ label[2:] +"\n")
        fin.close()

network model address

model modification

1. Modify configs/bisenet_customer.pythe file

insert image description here
n_cats: The number of categories including the background, where the category is 2
max_iter: Number of trainings
im_root: Data path
train_im_anns: just generated train.txt path
val_im_anns: just generated val.txt path
cropsize: change to image size
eval_crop: change to image size (do not know the effect)
ims_per_gpu:gpuquantity

2. Modify the category

This dataset class is modified 2
if configs/bisenet_customer.pyin the filemodel_type='bisenetv2'lib/models/bisenetv2.pyn_classes=2

insert image description here
If the modification file configs/bisenet_customer.pyinmodel_type='bisenetv1'lib/models/bisenetv1.pyBiSeNetV1(2)
insert image description here

run command

--nproc_per_nodeI don't know what it means, here 2is gputhe number

CUDA_VISIBLE_DEVICES=0,1 torchrun --nproc_per_node=2  tools/train_amp.py --config configs/bisenet_customer.py

It can run normally! !

Guess you like

Origin blog.csdn.net/weixin_44669966/article/details/125625363