当前位置:网站首页>[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
边栏推荐
- Chapter 3 business function development (user login)
- Automated testing: a practical skill that everyone wants to know about robot framework
- 线上比赛相关规则补充说明
- 机器人工程终身学习和工作计划-2022-
- Cartoon | who is the first ide in the universe?
- Based on pytorch, we use CNN to classify our own data sets
- 深入浅出【机器学习之线性回归】
- [trusted computing] Lesson 13: TPM extended authorization and key management
- [trusted computing] Lesson 12: TPM authorization and conversation
- Use onedns to perfectly solve the optimization problem of office network
猜你喜欢
Cartoon | who is the first ide in the universe?
讨论 | AR 应用落地前,要做好哪些准备?
What is agile testing
Chapter 3 business function development (user access project)
Vscode three configuration files about C language
Function and usage of textswitch text switcher
Tear the Nacos source code by hand (tear the client source code first)
[distributed theory] (II) distributed storage
zdog. JS rocket turn animation JS special effects
回归测试的分类
随机推荐
Win11C盘满了怎么清理?Win11清理C盘的方法
yolo训练过程中批量导入requirments.txt中所需要的包
青年时代历练和职业发展
Easy to understand [linear regression of machine learning]
<代码随想录二刷>链表
MySQL index hit level analysis
【OKR目标管理】案例分析
【深度学习】3分钟入门
Hutool - 轻量级 DB 操作解决方案
In depth understanding of USB communication protocol
Ansible 学习总结(9)—— Ansible 循环、条件判断、触发器、处理失败等任务控制使用总结
Robot engineering lifelong learning and work plan-2022-
Ansible learning summary (9) -- ansible loop, condition judgment, trigger, processing failure and other task control use summary
Face recognition attendance system based on Baidu flying plasma platform (easydl)
Explain it in simple terms. CNN convolutional neural network
Sanxian Guidong JS game source code
运行yolo v5-5.0版本报错找不到SPPF错误,进行解决
Interviewer: why is the page too laggy and how to solve it? [test interview question sharing]
Chapter 2 building CRM project development environment (building development environment)
Self made dataset in pytoch for dataset rewriting