当前位置:网站首页>[paddleseg source code reading] paddleseg custom data class
[paddleseg source code reading] paddleseg custom data class
2022-07-04 03:37:00 【Master Fuwen】
Feel how to change it first :
Config In the document item Class related __init__.py The parameters correspond one by one
stay PaddleSeg Of Config In file :
val_dataset:
type: Dataset
dataset_root: /root/share/program/save/data/portraint
val_path: /root/share/program/save/data/portraint/txtfiles/test.txt
num_classes: 2
transforms:
- type: Resize
target_size: [224, 224]
- type: Normalize
mode: val
The above Config Parameters are passed in Dataset Class __init__ Parameters in
def __init__(self,
transforms,
dataset_root,
num_classes,
mode='train',
train_path=None,
val_path=None,
test_path=None,
separator=' ',
ignore_index=255,
edge=False):
self.dataset_root = dataset_root
self.transforms = Compose(transforms)
self.file_list = list()
self.mode = mode.lower()
self.num_classes = num_classes
self.ignore_index = ignore_index
self.edge = edge
......
If this Dataset It doesn't meet your needs , You can customize a class , Such as XXDataset
Will Config In the document Dataset type Partial change to Your custom class XXDataset
This class needs to be in paddleseg/datasets/__init__.py Import , Can be directly in __init__.py In the definition of , You can also create a new file , And then in __init__.py Import in .
Be careful , At the beginning of the custom data class , Put this decorator ,( Register like this ?)
@manager.DATASETS.add_component
( Ah, this , I remember not using it before , Or before PaddleClas no need ?
for instance :
paddleseg/datasets/dataset.py in :
config file :
__init__.py Import :
Then pay attention here :
If these two attributes are not defined , There will be an error ,transforms attribute , It should be the parameters that pass in , But here is the image of direct preprocessing , So I gave it to None Generally speaking, it needs to be transferred
So I have to change a place here , Anyway, there is no error , Just change where you want

Here's a little more , In general , With incoming Transform Parameter preprocessing , Don't be like me :
class myDataset(Dataset):
def __init__(self, data_root,
img_name="images",
ann_name="annotations"):
self.img_path = os.path.join(data_root, img_name)
self.ann_path = os.path.join(data_root, ann_name)
# Be sure to pass in the relative path , Absolute path OpenCV I can't read
self.imgs = [os.path.join(self.img_path, img) for img in os.listdir(self.img_path)]
self.anns = [img.replace(".jpg", ".png") for img in self.imgs]
self.anns = [img.replace(img_name, ann_name) for img in self.anns]
def __len__(self):
return len(self.anns)
def __getitem__(self, idx):
img = cv2.imread(self.imgs[idx])
ann = cv2.imread(self.anns[idx], 0)
img = self.img_preprocess(img)
ann = self.ann_preprocess(ann)
return img, ann
@staticmethod
def img_preprocess(img):
img = cv2.resize(img, (224, 224)).astype(np.float32)
img = img.transpose(2, 0, 1)
img = img[None]
img /= 255
return img
@staticmethod
def ann_preprocess(ann):
ann = cv2.resize(ann, (224, 224))
return ann
I specifically define here self.img_preprocess and self.ann_preprocess To read pictures , And do the pretreatment .
So the code above , Will be able to self.transform to None, Then the passed parameters are given to []
That's OK. , Anyway, I'm too lazy to be transforms Register a new transform
however ,PaddleSeg stay transforms I did a little lazy work in , Will help us automatically read in pictures and Label

Take a look at , What is the transforms Which class in will read pictures :
stay Compose Of __call__ Function :
If the parameter passed in is str Then it will read the corresponding figure
( Be careful , The pictures read here are 0-255 Of , yes uint8 Of )
( Be careful ,for Operation under cycle , It's all about Transform finish , And then Transpose)
in other words , Of all the Transform after , The output is CHW, That is, the number of channels is at the top
in addition , The final transpose is np The operation of , in other words PaddleSeg Of Transform Mostly based on numpy Realized ( Only when reading pictures , use PIL.Image class )
Finally, let's see what decorators there are :
manager.MODELS
manager.BACKBONES
manager.DATASETS
manager.TRANSFORMS
manager.LOSSES
Probably , Add in the back .add_component Then you can add a new object
边栏推荐
- [PaddleSeg 源码阅读] PaddleSeg Transform 的 Normalize操作
- Rhcsa day 3
- Typical applications of minimum spanning tree
- CUDA basic knowledge
- Zlmediakit compilation and webrtc push-pull flow testing
- 潘多拉 IOT 开发板学习(HAL 库)—— 实验6 独立看门狗实验(学习笔记)
- Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
- Redis notes (I) Linux installation process of redis
- 2022 Guangxi provincial safety officer a certificate examination materials and Guangxi provincial safety officer a certificate simulation test questions
- SQL语句加强练习(MySQL8.0为例)
猜你喜欢

Third party login initial version

GUI Graphical user interface programming (XIV) optionmenu - what do you want your girlfriend to wear on Valentine's day

No clue about the data analysis report? After reading this introduction of smartbi, you will understand!

National standard gb28181 protocol platform easygbs fails to start after replacing MySQL database. How to deal with it?
![[PaddleSeg 源码阅读] PaddleSeg 自定义数据类](/img/88/37c535b371486db545abc392a685af.png)
[PaddleSeg 源码阅读] PaddleSeg 自定义数据类

Command Execution Vulnerability - command execution - vulnerability sites - code injection - vulnerability exploitation - joint execution - bypass (spaces, keyword filtering, variable bypass) - two ex

150 ppt! The most complete "fair perception machine learning and data mining" tutorial, Dr. AIST Toshihiro kamishima, Japan

Katalon框架测试web(二十六)自动发邮件

Es network layer

JVM family -- monitoring tools
随机推荐
Base d'apprentissage de la machine: sélection de fonctionnalités avec lasso
Setting methods, usage methods and common usage scenarios of environment variables in postman
Have you entered the workplace since the first 00???
[.NET + mqtt]. Mise en œuvre de la communication mqtt dans l'environnement net 6 et démonstration de code pour l'abonnement et la publication de messages bilatéraux du serveur et du client
Love and self-discipline and strive to live a core life
CUDA basic knowledge
MySQL backup notes
(practice C language every day) pointer sorting problem
1289_FreeRTOS中vTaskSuspend()接口实现分析
System integration meets the three business needs of enterprises
[UE4] parse JSON string
Contest3145 - the 37th game of 2021 freshman individual training match_ G: Score
Basé sur... Netcore Development blog Project Starblog - (14) Implementation of theme switching function
Leecode 122. Zuijia timing of buying and selling stocks ②
数据库SQL语句汇总,持续更新......
Katalon框架测试web(二十一)获取元素属性断言
Sword finger offer:55 - I. depth of binary tree
[development team follows] API specification
渗透实战-SQLServer提权
Code Execution Vulnerability - no alphanumeric rce create_ function()