当前位置:网站首页>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 :
边栏推荐
猜你喜欢
![[C language] explain the initial and advanced levels of the pointer and points for attention (1)](/img/61/1619bd2e959bae1b769963f66bab4e.png)
[C language] explain the initial and advanced levels of the pointer and points for attention (1)

03_线性表_链表

21_Redis_浅析Redis缓存穿透和雪崩

03_線性錶_鏈錶
![[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)

【C语音】详解指针进阶和注意点(2)

10_Redis_geospatial_命令

20_ Redis_ Sentinel mode

19_ Redis_ Manually configure the host after downtime

Markdown tutorial
随机推荐
20_Redis_哨兵模式
AtCoder Beginner Contest 254
语义分割学习笔记(一)
C # delay, start the timer in the thread, and obtain the system time
GeoServer offline map service construction and layer Publishing
面对“缺芯”挑战,飞凌如何为客户产能提供稳定强大的保障?
12_Redis_Bitmap_命令
TiDB数据迁移工具概览
How to choose a third-party software testing organization for automated acceptance testing of mobile applications
2021-2022学年编译原理考试重点[华侨大学]
你不知道的Set集合
Common English abbreviations for data analysis (I)
TiDB 软件和硬件环境建议配置
TiDB 环境与系统配置检查
C语言实现N皇后问题
Base64 编码原来还可以这么理解
工程师评测 | RK3568开发板上手测试
How to test tidb with sysbench
How does the computer set up speakers to play microphone sound
Real estate market trend outlook in 2022