当前位置:网站首页>Build your own semantic segmentation platform deeplabv3+
Build your own semantic segmentation platform deeplabv3+
2022-07-02 15:25:00 【Shallow thoughts 52】
List of articles
Preface
In the last article, I mainly learned about semantic segmentation , Instance segmentation , Difference of panoramic segmentation , as well as labelme Convert the marked data , This article is mainly through deeplabV3+ Build your own semantic segmentation platform
One 、deeplabV3+

The picture above , yes deeplabV3+ The main frame of , Simply put, it's coding , Decoding process . Pass the input picture through DCNN Deep convolution neural network , Get two effective feature layers ( Shallow )( Deep level ) The deep characteristic layer ASPP( The expansion convolution with different expansion rates is used for feature extraction , Then stack the features , adopt 1X1 Convolution adjusts the number of channels , Get the final feature ) High semantic feature information is combined with shallow features through up sampling , It's going on 3X3 Convolution of , And then through 1*1 Convolution adjusts the number of channels , Adjust to num_class( Number of categories ) Upsampling is performed so that the final output layer , The width and height are the same as the input image , Get every kind of every pixel .
Two 、 Data preparation
1. First of all, we need to deal with the data 
JPEGImages It stores pictures 
SegmentationClass Deposit is mask Mask image 
ImageSets Storage is some txt file 
3、 ... and 、 Modify the code
1. In the root directory mypath.py file 
2.dataloaders\datasets Create your own dataset file hat.py
Copy the pascal.py file 
3.dataloaders/utils.py

4.dataloaders/__init__.py

5.train.py
Four 、 Start training
Some main parameters 


Then you can train directly :
You can also carry a server for training , You can read my previous article .
5、 ... and 、 test
After training , So we can test it , Let's take a look at the code .
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 {} Testing is completed '.format(out_file))
Test results :
边栏推荐
猜你喜欢

面对“缺芯”挑战,飞凌如何为客户产能提供稳定强大的保障?

Solution of Queen n problem

Tidb data migration tool overview

语义分割学习笔记(一)
![[c voice] explain the advanced pointer and points for attention (2)](/img/fb/515e25899bd9a2905ee63cb041934a.png)
[c voice] explain the advanced pointer and points for attention (2)

做好抗“疫”之路的把关人——基于RK3568的红外热成像体温检测系统

18_ Redis_ Redis master-slave replication & cluster building

. Net again! Happy 20th birthday

可视化搭建页面工具的前世今生

vChain: Enabling Verifiable Boolean Range Queries over Blockchain Databases(sigmod‘2019)
随机推荐
Learn the method code example of converting timestamp to uppercase date using PHP
Learn the method code of using PHP to realize the conversion of Gregorian calendar and lunar calendar
YOLOV5 代码复现以及搭载服务器运行
. Solution to the problem of Chinese garbled code when net core reads files
搭建自己的语义分割平台deeplabV3+
【C语音】详解指针进阶和注意点(2)
17_ Redis_ Redis publish subscription
编译原理课程实践——实现一个初等函数运算语言的解释器或编译器
C语言实现N皇后问题
Guangzhou Emergency Management Bureau issued a high temperature and high humidity chemical safety reminder in July
Pytorch 保存tensor到.mat文件
Practice of compiling principle course -- implementing an interpreter or compiler of elementary function operation language
6.12 企业内部upp平台(Unified Process Platform)的关键一刻
牛客练习赛101
QML pop-up frame, customizable
二叉树的遍历方式主要有:先序遍历、中序遍历、后序遍历、层次遍历。先序、中序、后序其实指的是父节点被访问的次序。若在遍历过程中,父节点先于它的子节点被访问,就是先序遍历;
08_ strand
16_Redis_Redis持久化
Map介绍
做好抗“疫”之路的把关人——基于RK3568的红外热成像体温检测系统