当前位置:网站首页>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 :
边栏推荐
猜你喜欢
16_ Redis_ Redis persistence
XML Configuration File
Set set you don't know
15_ Redis_ Redis. Conf detailed explanation
The past and present lives of visual page building tools
05_ queue
21_ Redis_ Analysis of redis cache penetration and avalanche
List集合&UML图
百变大7座,五菱佳辰产品力出众,人性化大空间,关键价格真香
Tidb data migration tool overview
随机推荐
Pytorch 保存tensor到.mat文件
17_ Redis_ Redis publish subscription
二叉树的遍历方式主要有:先序遍历、中序遍历、后序遍历、层次遍历。先序、中序、后序其实指的是父节点被访问的次序。若在遍历过程中,父节点先于它的子节点被访问,就是先序遍历;
Deploy tidb cluster with tiup
CDN 在游戏领域的应用
15_Redis_Redis.conf详解
表格响应式布局小技巧
Tidb cross data center deployment topology
Table responsive layout tips
kibana 基础操作
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
[c voice] explain the advanced pointer and points for attention (2)
04_ Stack
02_ Linear table_ Sequence table
YOLOV5 代码复现以及搭载服务器运行
10_ Redis_ geospatial_ command
编译原理课程实践——实现一个初等函数运算语言的解释器或编译器
03_ Linear table_ Linked list
Case introduction and problem analysis of microservice
Facing the challenge of "lack of core", how can Feiling provide a stable and strong guarantee for customers' production capacity?