当前位置:网站首页>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 :
边栏推荐
- 12_ Redis_ Bitmap_ command
- TiDB 环境与系统配置检查
- AtCoder Beginner Contest 254
- Dragonfly low code security tool platform development path
- 20_Redis_哨兵模式
- 表格响应式布局小技巧
- TiDB跨数据中心部署拓扑
- 18_ Redis_ Redis master-slave replication & cluster building
- How to avoid 7 common problems in mobile and network availability testing
- Common English abbreviations for data analysis (I)
猜你喜欢
Btrace- (bytecode) dynamic tracking tool
. Net core logging system
05_ queue
How to avoid 7 common problems in mobile and network availability testing
Tidb data migration tool overview
07_哈希
21_Redis_浅析Redis缓存穿透和雪崩
Why can't programmers who can only program become excellent developers?
08_ strand
How to choose a third-party software testing organization for automated acceptance testing of mobile applications
随机推荐
19_Redis_宕机后手动配置主机
List集合&UML图
哈夫曼树:(1)输入各字符及其权值(2)构造哈夫曼树(3)进行哈夫曼编码(4)查找HC[i],得到各字符的哈夫曼编码
牛客练习赛101
FPGA - 7系列 FPGA内部结构之Clocking -03- 时钟管理模块(CMT)
07_ Hash
Leetcode - Search 2D matrix
vChain: Enabling Verifiable Boolean Range Queries over Blockchain Databases(sigmod‘2019)
13_ Redis_ affair
05_ queue
[C language] explain the initial and advanced levels of the pointer and points for attention (1)
AtCoder Beginner Contest 254
. Net core logging system
[noi simulation] Elis (greedy, simulation)
18_ Redis_ Redis master-slave replication & cluster building
. Solution to the problem of Chinese garbled code when net core reads files
使用 TiUP 部署 TiDB 集群
MFC timer usage
20_ Redis_ Sentinel mode
解决el-radio-group 回显后不能编辑问题