当前位置:网站首页>[paddleseg source code reading] add boundary IOU calculation in paddleseg validation (1) -- val.py file details tips
[paddleseg source code reading] add boundary IOU calculation in paddleseg validation (1) -- val.py file details tips
2022-07-07 18:08:00 【Master Fuwen】
The last one was tossed boundary IoU Calculation method of , This article talks about PaddleSeg How to add Boundary IoU do Val, Training and infer Almost. ,hxdm Step on the pit yourself
First of all, the whole thing PaddleSeg Lite version :
.travis.yml
.style.yapf
.pre-commit-config.yaml
.gitignore
.copyright.hook
LICENSE
README.md
README_CN.md
requirements.txt
export.py # Delete it or not , This is used to export static graph model files
setup.py # This is used to install PaddleSeg Of , Delete it
benchmark
deploy
docs
EISeg # An efficient and intelligent interactive segmentation and annotation software based on propeller
slim
test_tipc # Integrated certification of propeller training and propulsion (Training and Inference Pipeline Certification(TIPC)) Information and testing tools
tests
If it's just running training and reasoning , The above can be deleted directly
contrib Just some other functions , such as matting、PPHumanSeg And so on. , Can be deleted
configs Well , That's the pile of configuration files , Understand everything
tools, There are some commonly used tools , Label , Annotation format conversion and so on , After that, I don't want to write wheels , Just look here ( This is a treasure chest )

That's my PaddleSeg Lite version ,
val.py file
There's nothing to see , Just two sentences of code
# Directly here Data class Instantiation
val_dataset = cfg.val_dataset
# Directly here model Instantiation
model = cfg.model
Why instantiate directly here ? Obviously, it assigns an attribute , In fact, single-step debugging , You can see , He actually added a decorator to the attribute @property
@property
def val_dataset(self) -> paddle.io.Dataset:
_val_dataset = self.val_dataset_config
if not _val_dataset:
return None
return self._load_object(_val_dataset)
@property
def model(self) -> paddle.nn.Layer:
model_cfg = self.dic.get('model').copy()
if not model_cfg:
raise RuntimeError('No model specified in the configuration file.')
if not 'num_classes' in model_cfg:
......
if not self._model:
self._model = self._load_object(model_cfg)
return self._model
Did you see? , There is one self._load_object function , All classes are loaded through this method ( Instantiation ) Of
Take a look at this method ( I hope the old irons can read it by themselves ):
def _load_object(self, cfg: dict) -> Any:
cfg = cfg.copy()
if 'type' not in cfg:
raise RuntimeError('No object information in {}.'.format(cfg))
component = self._load_component(cfg.pop('type'))
# The upper boundary is to get the class name
# ----------------- This is the dividing line -----------------
# Below the dividing line is the parameter dictionary
params = {
}
for key, val in cfg.items():
if self._is_meta_type(val):
params[key] = self._load_object(val)
elif isinstance(val, list):
params[key] = [
self._load_object(item)
if self._is_meta_type(item) else item for item in val
]
else:
params[key] = val
# take config After taking out the classes and parameters in , stay return This step returns the object
return component(**params)
There's another one inside _is_meta_type Method , Guess the meaning , Is it Can be instantiated Judge
Click this method to see :
def _is_meta_type(self, item: Any) -> bool:
return isinstance(item, dict) and 'type' in item
If it's a dictionary , And there are type attribute , stay PaddleSeg Of Config In this architecture , Think that this class can be instantiated
OK, Now keep recursing to see the source code , Now let's jump back , have a look sellf._load_object in self._load_component How to get that kind of name
def _load_component(self, com_name: str) -> Any:
com_list = [
manager.MODELS, manager.BACKBONES, manager.DATASETS,
manager.TRANSFORMS, manager.LOSSES
]
for com in com_list:
if com_name in com.components_dict:
return com[com_name]
else:
raise RuntimeError(
'The specified component was not found {}.'.format(com_name))
See here , I believe if you have read my blog , Then there must be a feeling of sudden enlightenment
[PaddleSeg Source code reading ] PaddleSeg Custom data class
The end of this blog :
manager.MODELS
manager.BACKBONES
manager.DATASETS
manager.TRANSFORMS
manager.LOSSES
These components are shown , I think so ,PaddleSeg The commonly used components are abstracted , Directly abstracted as Model class ,Backbone Backbone network , Dataset class , picture Transform class and Loss function class
Abstract as a class , You need to add the corresponding decorator , For example, add custom classes , Need this decorator :
@manager.DATASETS.add_component
Look at that English .add_component It means adding components , So in _load_component In the source code ,
for com in com_list:
if com_name in com.components_dict:
return com[com_name]
Go and see com_name Whether in manager.MODELS、manager.BACKBONES、manager.DATASETS、manager.TRANSFORMS and manager.LOSSES Among these components
If none of them are in , be raise This is wrong :
raise RuntimeError(
'The specified component was not found {}.'.format(com_name))
“ This component was not found ”
Here's another line , image metrics Those indicators ( such as IoU, acc And so on. ), They're just functions , Not class , So you don't need to use it .add_component To register
( This sentence is for later use Boundary IoU Pave the way )
Almost , This blog starts with these two sentences :
val_dataset = cfg.val_dataset
model = cfg.model
Led to so many
To sum up for yourselves , Send it to the comment area
边栏推荐
- [tpm2.0 principle and Application guide] Chapter 1-3
- [trusted computing] Lesson 13: TPM extended authorization and key management
- SD_DATA_RECEIVE_SHIFT_REGISTER
- 机器视觉(1)——概述
- 测试3个月,成功入职 “字节”,我的面试心得总结
- Dragging the custom style of Baidu map to the right makes the global map longitude 0 unable to be displayed normally
- [trusted computing] Lesson 10: TPM password resource management (II)
- DatePickerDialog and trimepickerdialog
- Ten thousand words nanny level long article -- offline installation guide for datahub of LinkedIn metadata management platform
- Run Yolo v5-5.0 and report an error. If the sppf error cannot be found, solve it
猜你喜欢
随机推荐
<代码随想录二刷>链表
zdog. JS rocket turn animation JS special effects
目标管理【管理学之十四】
Simple loading animation
Tear the Nacos source code by hand (tear the client source code first)
Function and usage of calendar view component
原生js验证码
利用七种方法对一个文件夹里面的所有图像进行图像增强实战
mui侧边导航锚点定位js特效
Click on the top of today's headline app to navigate in the middle
TaffyDB开源的JS数据库
数字化转型的主要工作
数学分析_笔记_第11章:Fourier级数
开发一个小程序商城需要多少钱?
Based on pytorch, we use CNN to classify our own data sets
Explain it in simple terms. CNN convolutional neural network
js拉下帷幕js特效显示层
Sanxian Guidong JS game source code
自动化测试:Robot FrameWork框架大家都想知道的实用技巧
4种常见的缓存模式,你都知道吗?






![[tpm2.0 principle and Application guide] Chapter 5, 7 and 8](/img/38/93fd986916193803bbd90805f832fa.png)


