当前位置:网站首页>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 :
边栏推荐
- 11_Redis_Hyperloglog_命令
- How to write sensor data into computer database
- HUSTPC2022
- 20_ Redis_ Sentinel mode
- CodeCraft-22 and Codeforces Round #795 (Div. 2)D,E
- 编译原理课程实践——实现一个初等函数运算语言的解释器或编译器
- 哈夫曼树:(1)输入各字符及其权值(2)构造哈夫曼树(3)进行哈夫曼编码(4)查找HC[i],得到各字符的哈夫曼编码
- AtCoder Beginner Contest 254
- 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
- 19_ Redis_ Manually configure the host after downtime
猜你喜欢
随机推荐
Markdown tutorial
vChain: Enabling Verifiable Boolean Range Queries over Blockchain Databases(sigmod‘2019)
Table responsive layout tips
05_队列
[noi simulation] Elis (greedy, simulation)
Btrace- (bytecode) dynamic tracking tool
Sharp tool SPL for post SQL calculation
Learn the method code example of converting timestamp to uppercase date using PHP
实用调试技巧
07_ Hash
FPGA - clock-03-clock management module (CMT) of internal structure of 7 Series FPGA
TiDB跨数据中心部署拓扑
Tidb data migration scenario overview
17_Redis_Redis发布订阅
06_栈和队列转换
How does the computer set up speakers to play microphone sound
[C language] explain the initial and advanced levels of the pointer and points for attention (1)
10_Redis_geospatial_命令
TiDB 集群最小部署的拓扑架构
TiDB数据迁移场景综述









