当前位置:网站首页>[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
边栏推荐
- Webhook triggers Jenkins for sonar detection
- 1day vulnerability pushback skills practice (3)
- Consul of distributed service registration discovery and unified configuration management
- [database I] database overview, common commands, view the table structure of 'demo data', simple query, condition query, sorting data, data processing function (single row processing function), groupi
- static hostname; transient hostname; pretty hostname
- Defensive programming skills
- @Scheduled scheduled tasks
- Don't disagree, this is the most powerful "language" of the Internet
- Katalon框架测试web(二十一)获取元素属性断言
- warning: LF will be replaced by CRLF in XXXXXX
猜你喜欢
Www 2022 | taxoenrich: self supervised taxonomy complemented by Structural Semantics
[Wu Enda deep learning] beginner learning record 3 (regularization / error reduction)
Constantly changing harmonyos custom JS components during the Spring Festival - Smart Koi
[source code analysis] model parallel distributed training Megatron (5) -- pipestream flush
Teach you how to optimize SQL
AAAI2022 | Word Embeddings via Causal Inference: Gender Bias Reducing and Semantic Information Preserving
1day vulnerability pushback skills practice (3)
This function has none of DETERMINISTIC, NO SQL..... (you *might* want to use the less safe log_bin_t
Practical multifunctional toolbox wechat applet source code / support traffic master
Monitoring - Prometheus introduction
随机推荐
super_ Subclass object memory structure_ Inheritance tree traceability
Is it really so difficult to learn redis? Today, a fan will share his personal learning materials!
Contest3145 - the 37th game of 2021 freshman individual training match_ D: Ranking
潘多拉 IOT 开发板学习(HAL 库)—— 实验6 独立看门狗实验(学习笔记)
Slurm view node configuration information
Constantly changing harmonyos custom JS components during the Spring Festival - Smart Koi
Code Execution Vulnerability - no alphanumeric rce create_ function()
What kind of experience is it when the Institute earns 20000 yuan a month!
Katalon框架测试web(二十六)自动发邮件
Setting methods, usage methods and common usage scenarios of environment variables in postman
Short math guide for latex by Michael downs
Future源碼一觀-JUC系列
How to use websocket to realize simple chat function in C #
Exercices de renforcement des déclarations SQL (MySQL 8.0 par exemple)
Www 2022 | taxoenrich: self supervised taxonomy complemented by Structural Semantics
What are the virtual machine software? What are their respective functions?
Typical applications of minimum spanning tree
[latex] production of complex tables: excel2latex and detail adjustment
2022 attached lifting scaffold worker (special type of construction work) free test questions and attached lifting scaffold worker (special type of construction work) examination papers 2022 attached
Base d'apprentissage de la machine: sélection de fonctionnalités avec lasso