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.
Baidu cloud: https://pan.baidu.com/s/1HlnKWToc00986jiTxhq_CA
Extraction code:RSAI
data processing
1. Dataset
datasets
The data set is stored in a folder under the root directory , coco
alongside city
the 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-->1
converted, 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,255
convert 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 train
toval
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.txt
files and val.txt
files. To convert files, you only need to replace val.txt
all of the following codes (there are three places)train
val
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.py
the file
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:gpu
quantity
2. Modify the category
This dataset class is modified 2
if configs/bisenet_customer.py
in the filemodel_type='bisenetv2'
lib/models/bisenetv2.py
n_classes=2
If the modification file configs/bisenet_customer.py
inmodel_type='bisenetv1'
lib/models/bisenetv1.py
BiSeNetV1(2)
run command
--nproc_per_node
I don't know what it means, here 2
is gpu
the number
CUDA_VISIBLE_DEVICES=0,1 torchrun --nproc_per_node=2 tools/train_amp.py --config configs/bisenet_customer.py
It can run normally! !