当前位置:网站首页>使用SwinUnet训练自己的数据集
使用SwinUnet训练自己的数据集
2022-07-07 05:19:00 【我是一个小稻米】
参考博文: https://blog.csdn.net/qq_37652891/article/details/123932772
数据集准备
遥感图像多类别语义分割,总共分为7类(包括背景)
image:
label_rgb
label(这里并不是全黑,其中的类别取值为0,1,2,3,4,5,6
),此后的训练使用的也是这样的数据
数据地址
百度云:https://pan.baidu.com/s/1zZHnZfBgVWxs6TJW4yjeeQ
提取码:2022
SwinUNet代码地址
数据集处理
数据集的image
和label
,这个数据集应该提供了rgb
格式标签和包含0,1,2,3,4,5,6
值的标签,SwinUNet
使用的是包含0,1,2,3,4,5,6
的标签图像;
1. 数据集
数据集存放在SwinUNet
根目录下,image
中是原图像,label
中是标签图像(共7类,其标签取值为0,1,2,3,4,5,6,7
);
如果使用其他数据集,要注意标签的取值。比如如果是二分类。即标签0
或255
,需要换成0
或1
—SwinUNet
---------configs
---------img_datas
---------------train
--------------------image
--------------------label
---------------test
--------------------image
--------------------label
2. 在SwinUnet
根目录下创建npz.py
文件,运行npz.py
文件
import glob
import cv2
import numpy as np
import os
def npz(im, la, s):
images_path = im
labels_path = la
path2 = s
images = os.listdir(images_path)
for s in images:
image_path = os.path.join(images_path, s)
label_path = os.path.join(labels_path, s)
image = cv2.imread(image_path)
image = cv2.cvtColor(image,cv2.COLOR_BGR2RGB)
# 标签由三通道转换为单通道
label = cv2.imread(label_path, flags=0)
# 保存npz文件
np.savez(path2+s[:-4]+".npz",image=image,label=label)
npz('./img_datas/train/image/', './img_datas/train/label/', './data/Synapse/train_npz')
npz('./img_datas/test/image/', './img_datas/test/label/', './data/Synapse/test_vol_h5')
3. 在SwinUnet
根目录下创建txt.py
文件,运行txt.py
文件
目的是生成./list/list_Synapse/train.txt
和./list/list_Synapse/test_vol.txt
文件
import os
def write_name(np, tx):
#npz文件路径
files = os.listdir(np)
#txt文件路径
f = open(tx, 'w')
for i in files:
#name = i.split('\\')[-1]
name = i[:-4]+'\n'
f.write(name)
write_name('./data/Synapse/train_npz', './lists/lists_Synapse/train.txt')
write_name('./data/Synapse/test_vol_h5', './lists/lists_Synapse/test_vol.txt')
4. 下载预训练权重,放在SwinUnet
目录下的pretrained_ckpt
文件夹下
链接:https://pan.baidu.com/s/1-hYwJRlr95Fv08e9AEARww
提取码:2022
修改网络
1. 修改train.py
文件
比较重要的是类别数量,其他视情况而定
2. 修改./datasets/dataset_synapse.py
文件
3. 修改trainer.py
文件
此处不知道为什么
4. 运行代码
这些信息可以作为超参传入,如果不能,那么可以使用default=
的方式写入默认值
如果设置好啦默认值,那么运行python train.py
就可以啦
边栏推荐
- Uniapp mobile terminal forced update function
- 调用 pytorch API完成线性回归
- Bayes' law
- [quick start of Digital IC Verification] 12. Introduction to SystemVerilog testbench (svtb)
- 饥荒云服管理脚本
- Minimum absolute difference of binary search tree (use medium order traversal as an ordered array)
- It's too true. There's a reason why I haven't been rich
- Zcmu--1396: queue problem (2)
- Leetcode simple question: find the K beauty value of a number
- Network learning (II) -- Introduction to socket
猜你喜欢
Unityhub cracking & unity cracking
[quick start of Digital IC Verification] 12. Introduction to SystemVerilog testbench (svtb)
Empire CMS collection Empire template program general
Network learning (II) -- Introduction to socket
jeeSite 表单页面的Excel 导入功能
通俗易懂单点登录SSO
The zblog plug-in supports the plug-in pushed by Baidu Sogou 360
CDC (change data capture technology), a powerful tool for real-time database synchronization
Register of assembly language by Wang Shuang
Quick analysis of Intranet penetration helps the foreign trade management industry cope with a variety of challenges
随机推荐
青龙面板--花花阅读
ZCMU--1396: 队列问题(2)
Application of slip ring of shipborne radar antenna
Example of file segmentation
OpenVSCode云端IDE加入Rainbond一体化开发体系
Empire CMS collection Empire template program general
电池、电机技术受到很大关注,反而电控技术却很少被提及?
ROS Bridge 笔记(05)— carla_ackermann_control 功能包(将Ackermann messages 转化为 CarlaEgoVehicleControl 消息)
JS copy picture to clipboard read clipboard
Recursive method to construct binary tree from preorder and inorder traversal sequence
Easy to understand SSO
DNS server configuration
The simple problem of leetcode is to judge whether the number count of a number is equal to the value of the number
[quick start of Digital IC Verification] 11. Introduction to Verilog testbench (VTB)
opencv学习笔记三——图像平滑/去噪处理
【无标题】
Quick analysis of Intranet penetration helps the foreign trade management industry cope with a variety of challenges
CCTV is so warm-hearted that it teaches you to write HR's favorite resume hand in hand
Basic use of CTF web shrink template injection nmap
Bayes' law