当前位置:网站首页>[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
边栏推荐
- Face recognition attendance system based on Baidu flying plasma platform (easydl)
- Function and usage of calendar view component
- Pro2: modify the color of div block
- ICer知识点杂烩(后附大量题目,持续更新中)
- Function and usage of numberpick
- 企业经营12法的领悟
- <代码随想录二刷>链表
- Main work of digital transformation
- 如何在软件研发阶段落地安全实践
- Define menus using XML resource files
猜你喜欢
深入浅出图解CNN-卷积神经网络
Introduction to OTA technology of Internet of things
Simple loading animation
Tips of the week 136: unordered containers
[4500 word summary] a complete set of skills that a software testing engineer needs to master
List selection JS effect with animation
目标检测1——YOLO数据标注以及xml转为txt文件脚本实战
保证接口数据安全的10种方案
[principles and technologies of network attack and Defense] Chapter 5: denial of service attack
swiper左右切换滑块插件
随机推荐
自动化测试:Robot FrameWork框架大家都想知道的实用技巧
List selection JS effect with animation
【蓝桥杯集训100题】scratch从小到大排序 蓝桥杯scratch比赛专项预测编程题 集训模拟练习题第17题
Mobile pixel bird game JS play code
Pro2: modify the color of div block
[principle and technology of network attack and Defense] Chapter 6: Trojan horse
深度学习机器学习各种数据集汇总地址
Native JS verification code
The report of the state of world food security and nutrition was released: the number of hungry people in the world increased to 828million in 2021
debian10编译安装mysql
TaffyDB开源的JS数据库
Tips for this week 140: constants: safety idioms
Slider plug-in for swiper left and right switching
Five simple ways to troubleshoot with Stace
目标检测1——YOLO数据标注以及xml转为txt文件脚本实战
What is agile testing
保证接口数据安全的10种方案
Easy to understand [linear regression of machine learning]
Functions and usage of tabhost tab
运行yolo v5-5.0版本报错找不到SPPF错误,进行解决