当前位置:网站首页>使用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就可以啦
边栏推荐
- Réplication de vulnérabilité - désrialisation fastjson
- It took "7" years to build the robot framework into a micro service
- Qinglong panel - today's headlines
- Interview questions (CAS)
- Minimum absolute difference of binary search tree (use medium order traversal as an ordered array)
- Complete linear regression manually based on pytoch framework
- LeetCode简单题之找到一个数字的 K 美丽值
- 复杂网络建模(三)
- Linux Installation MySQL 8.0 configuration
- 积分商城管理系统中应包含的四大项
猜你喜欢
![[quick start of Digital IC Verification] 13. SystemVerilog interface and program learning](/img/d8/ffc1b7527f0269cecb2946ab402a2e.png)
[quick start of Digital IC Verification] 13. SystemVerilog interface and program learning

Fast parsing intranet penetration escorts the document encryption industry

电池、电机技术受到很大关注,反而电控技术却很少被提及?

快解析内网穿透助力外贸管理行业应对多种挑战

eBPF Cilium实战(1) - 基于团队的网络隔离

Network learning (III) -- highly concurrent socket programming (epoll)

Lua 编程学习笔记

JS cross browser parsing XML application

Application of slip ring of shipborne radar antenna

Rainbond结合NeuVector实践容器安全管理
随机推荐
数据库实时同步利器——CDC(变化数据捕获技术)
Basic use of CTF web shrink template injection nmap
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after conne
What is the function of paralleling a capacitor on the feedback resistance of the operational amplifier circuit
拓维信息使用 Rainbond 的云原生落地实践
Qinglong panel -- Huahua reading
[quick start of Digital IC Verification] 12. Introduction to SystemVerilog testbench (svtb)
It's too true. There's a reason why I haven't been rich
[quick start of Digital IC Verification] 14. Basic syntax of SystemVerilog learning 1 (array, queue, structure, enumeration, string... Including practical exercises)
[step on the pit series] H5 cross domain problem of uniapp
王爽 《汇编语言》之寄存器
Zsh shell adds automatic completion and syntax highlighting
积分商城管理系统中应包含的四大项
Jmeter 的使用
JS复制图片到剪切板 读取剪切板
Pytorch(六) —— 模型调优tricks
快解析内网穿透为文档加密行业保驾护航
Wang Zijian: is the NFT of Tencent magic core worth buying?
The zblog plug-in supports the plug-in pushed by Baidu Sogou 360
Introduction à l'objet blob