当前位置:网站首页>搭建自己的语义分割平台deeplabV3+
搭建自己的语义分割平台deeplabV3+
2022-07-02 12:01:00 【浅念念52】
前言
在上一篇主要了解了语义分割,实例分割,全景分割的区别,以及labelme标注的数据进行转换,这边文章主要是通过deeplabV3+ 构建自己的语义分割平台
一、deeplabV3+

上图所示,是deeplabV3+的主体框架,简单来说就是编码,解码的过程。将输入的图片通过DCNN深度卷积神经网络,获得两个有效的特征层(浅层)(深层)对深层特征层进行ASPP(利用不同膨胀率的膨胀卷积进行特征提取,然后对特征进行堆叠,通过1X1卷积调整通道数,得到最终的特征)将高语义的特征信息经过上采样与浅层特征进行特征融合,在进行3X3的卷积,然后通过1*1卷积进行通道数的调整,调整成num_class(分类数)进行上采样使得最终输出层,宽高与输入图片一样,得到每一个像素点的每一个种类。
二、数据准备
1.我们首先要对数据进行一些处理
JPEGImages 存放的是图片
SegmentationClass 存放的是mask掩码图像
ImageSets 存放是一些txt文件
三、修改代码
1.根目录下的mypath.py文件
2.dataloaders\datasets创建自己的数据集文件hat.py
复制这一路径下的pascal.py文件
3.dataloaders/utils.py

4.dataloaders/__init__.py

5.train.py
四、开始训练
一些主要的参数


然后就可以直接训练了:
也可以搭载服务器进行训练,可以看我之前的文章。
五、测试
训练完成之后,就可以进行测试了,下面直接看代码。
import torch
from modeling.deeplab_v3_50_modify_256 import deeplab_v3_50
import glob
import cv2
import os
from modeling.deeplab import *
from PIL import Image
from torchvision import transforms
from dataloaders.utils import *
from utils.saver import save_colored_mask
num_class=3
path = 'test_image'
out_path='out_image'
test_images = glob.glob(os.path.join(path,"*.jpg"))
composed_transforms = transforms.Compose([transforms.ToTensor()])
totensor = transforms.ToTensor()
model=DeepLab(num_classes=num_class,backbone='drn')
model.load_state_dict(torch.load(r'D:\xiangmu\deeplaV3_run\run_hat\hat\deeplab-drn\model_best.pth.tar')['state_dict'])
model.eval()
def Normalize(img,mean,std):
img = np.array(img).astype(np.float32)
img /= 255.0
img -= mean
img /=std
return img
for test_image in test_images:
name=os.path.basename(test_image)
name=name.replace('jpg','png')
img = Image.open(test_image)
img_norm = Normalize(img,mean=(0.485, 0.456, 0.406),std=(0.229, 0.224, 0.225))
img_resize = cv2.resize(img_norm,(513,513))
compose = composed_transforms(img_resize).unsqueeze(0)
out = model(compose)
pred=torch.argmax(out,1)[0].numpy()
H,W=img_norm.shape[0],img_norm.shape[1]
pred_orgin=cv2.resize(pred,(W,H),interpolation=cv2.INTER_NEAREST)
out_file=os.path.join(out_path,name)
save_colored_mask(pred_orgin,out_file)
print('save {} 测试完成'.format(out_file))
测试的结果:
边栏推荐
- Base64 编码原来还可以这么理解
- C RichTextBox controls the maximum number of lines displayed
- LeetCode 2320. Count the number of ways to place the house
- How does CTO help the business?
- CDN 在游戏领域的应用
- Dragonfly low code security tool platform development path
- Printf function and scanf function in C language
- Learn the method code of using PHP to realize the conversion of Gregorian calendar and lunar calendar
- [untitled] leetcode 2321 Maximum score of concatenated array
- 飞凌嵌入式RZ/G2L处理器核心板及开发板上手评测
猜你喜欢
随机推荐
如何对 TiDB 进行 TPC-C 测试
[untitled] leetcode 2321 Maximum score of concatenated array
TiDB 软件和硬件环境建议配置
03_ Linear table_ Linked list
飞凌嵌入式RZ/G2L处理器核心板及开发板上手评测
Application and practice of Jenkins pipeline
04_ 栈
Points clés de l'examen de principe de compilation pour l'année scolaire 2021 - 2022 [Université chinoise d'outre - mer]
[C language] explain the initial and advanced levels of the pointer and points for attention (1)
Map介绍
Huffman tree: (1) input each character and its weight (2) construct Huffman tree (3) carry out Huffman coding (4) find hc[i], and get the Huffman coding of each character
LeetCode_ Sliding window_ Medium_ 395. Longest substring with at least k repeated characters
How to write sensor data into computer database
AtCoder Beginner Contest 254
08_ strand
LeetCode 2320. Count the number of ways to place the house
05_队列
c语言入门--数组
Dragonfly low code security tool platform development path
12_Redis_Bitmap_命令









![[noi Simulation Competition] scraping (dynamic planning)](/img/ee/27a07f80207a2925f5065e633eb39f.png)