当前位置:网站首页>[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
边栏推荐
- 渗透实战-guest账户-mimikatz-向日葵-sql提权-离线解密
- A review of reverse reinforcement learning at Virginia Tech (VT)
- Setting methods, usage methods and common usage scenarios of environment variables in postman
- Handler source code analysis
- [Wu Enda deep learning] beginner learning record 3 (regularization / error reduction)
- The difference between MCU serial communication and parallel communication and the understanding of UART
- Eh, the log time of MySQL server is less than 8h?
- Short math guide for latex by Michael downs
- JS object definition
- 2022 registration examination for safety production management personnel of fireworks and firecracker production units and examination skills for safety production management personnel of fireworks an
猜你喜欢
![Stm32bug [the project references devices, files or libraries that are not installed appear in keilmdk]](/img/0d/7a8370d153a8479b706377c3487220.jpg)
Stm32bug [the project references devices, files or libraries that are not installed appear in keilmdk]

Setting methods, usage methods and common usage scenarios of environment variables in postman

Add IDM to Google browser

This function has none of DETERMINISTIC, NO SQL..... (you *might* want to use the less safe log_bin_t

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

Code Execution Vulnerability - no alphanumeric rce create_ function()

Contest3145 - the 37th game of 2021 freshman individual training match_ 1: Origami
![[untitled]](/img/b5/bf76783aa428222623d760756a14d9.jpg)
[untitled]

Zhihu million hot discussion: why can we only rely on job hopping for salary increase? Bosses would rather hire outsiders with a high salary than get a raise?

微信公众号网页授权
随机推荐
[PaddleSeg 源码阅读] PaddleSeg计算Dice
Zlmediakit compilation and webrtc push-pull flow testing
@Scheduled scheduled tasks
150 ppt! The most complete "fair perception machine learning and data mining" tutorial, Dr. AIST Toshihiro kamishima, Japan
warning: LF will be replaced by CRLF in XXXXXX
Audio and video technology development weekly | 232
MySQL query
MySQL maxscale realizes read-write separation
[UE4] parse JSON string
Management and thesis of job management system based on SSM
Webhook triggers Jenkins for sonar detection
Formulaire day05
Monitoring - Prometheus introduction
Katalon框架测试web(二十一)获取元素属性断言
【.NET+MQTT】.NET6 環境下實現MQTT通信,以及服務端、客戶端的雙邊消息訂閱與發布的代碼演示
Exercices de renforcement des déclarations SQL (MySQL 8.0 par exemple)
JS object definition
基于PHP的轻量企业销售管理系统
Wechat official account web page authorization
SQL语句加强练习(MySQL8.0为例)