• 使用BiSeNet实现自己的数据集


    数据集准备

    数据集:遥感房屋影像分割,分先后两个时间,主要是实现建筑物面积随时间的面积变化情况。
    在这里插入图片描述

    百度云:https://pan.baidu.com/s/1HlnKWToc00986jiTxhq_CA
    提取码:RSAI

    数据处理

    1. 数据集

    数据集存放在根目录下的datasets文件夹下,与cococity数据集并列,如果你的数据集的标签已经是0,1,那么可以不用管label_255,如果标签没有经过255-->1的转化,可以先将标签文件放在label_255下。

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

    2. 在datasets/times/文件夹下创建one.py

    目的是将0,255的标签转化为0,1,如果是多类的,那么标签就是0,1,2,3,...n
    代码中只转化了train中的文件,要转化val中的文件,修改trainval即可

    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)
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    2. 在datasets/times/文件夹下创建util.py文件

    目的是生成train.txt文件和val.txt文件,要转化val.txt文件,只需要将下面代码中的所有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()
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    网络模型地址

    模型修改

    1. 修改configs/bisenet_customer.py文件

    在这里插入图片描述
    n_cats:包括背景在内的类别数,这里类别是2
    max_iter:训练次数
    im_root:数据路径
    train_im_anns:刚才生成的train.txt路径
    val_im_anns:刚才生成的val.txt路径
    cropsize:改成图像尺寸
    eval_crop:改成图像尺寸(不知道作用)
    ims_per_gpu:gpu数量

    2. 修改类别

    这个数据集类别是2
    如果configs/bisenet_customer.py中的model_type='bisenetv2'修改lib/models/bisenetv2.py文件中的n_classes=2

    在这里插入图片描述
    如果configs/bisenet_customer.py中的model_type='bisenetv1'修改lib/models/bisenetv1.py文件中的BiSeNetV1(2)
    在这里插入图片描述

    运行命令

    --nproc_per_node不知道什么意思,这里的2gpu的数量

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

    就可以正常运行啦!!

  • 相关阅读:
    Micropython——Pico获取双轴摇杆模块数据(一)
    PyTorch实现注意力机制及使用方法汇总,附30篇attention论文
    Java 中你绝对没用过的一个关键字?
    【centos】【Redis】【systemd】Redis进程守护
    Flutter 异步编程指南
    Aimi.fm:AI的生成音乐平台
    关于butterfly主题
    华为机试 - 找出经过特定点的路径长度
    17-ETL工具、大数据架构、Flume介绍、Flume组件介绍
    【考研复习】二叉树的特殊存储|三叉链表存储二叉树、一维数组存储二叉树、线索二叉树
  • 原文地址:https://blog.csdn.net/weixin_44669966/article/details/125625363