当前位置:网站首页>[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
边栏推荐
- Object oriented -- encapsulation, inheritance, polymorphism
- Webhook triggers Jenkins for sonar detection
- Solve the problems encountered by the laravel framework using mongodb
- How to pipe several commands in Go?
- Webhook triggers Jenkins for sonar detection
- Examination question bank of constructor decoration direction post skills (constructor) and examination data of constructor decoration direction post skills (constructor) in 2022
- Infiltration practice guest account mimikatz sunflower SQL rights lifting offline decryption
- Audio and video technology development weekly | 232
- (practice C language every day) pointer sorting problem
- System integration meets the three business needs of enterprises
猜你喜欢

1day vulnerability pushback skills practice (3)

Constantly changing harmonyos custom JS components during the Spring Festival - Smart Koi

Session learning diary 1

Objective-C description method and type method

Consul of distributed service registration discovery and unified configuration management

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

In my spare time, I like to write some technical blogs and read some useless books. If you want to read more of my original articles, you can follow my personal wechat official account up technology c

Management and thesis of job management system based on SSM
![[untitled]](/img/b5/bf76783aa428222623d760756a14d9.jpg)
[untitled]

Want to do something in production? Then try these redis commands
随机推荐
SQL语句加强练习(MySQL8.0为例)
[.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
Zlmediakit compilation and webrtc push-pull flow testing
National standard gb28181 protocol platform easygbs fails to start after replacing MySQL database. How to deal with it?
Contest3145 - the 37th game of 2021 freshman individual training match_ E: Eat watermelon
How to use STR function of C language
Sword finger offer:55 - I. depth of binary tree
深入浅出对话系统——使用Transformer进行文本分类
GUI Graphical user interface programming (XIV) optionmenu - what do you want your girlfriend to wear on Valentine's day
Day05 錶格
CUDA basic knowledge
機器學習基礎:用 Lasso 做特征選擇
Third party login initial version
Objective-C string class, array class
XSS prevention
Base d'apprentissage de la machine: sélection de fonctionnalités avec lasso
Infiltration practice guest account mimikatz sunflower SQL rights lifting offline decryption
Love and self-discipline and strive to live a core life
Management and thesis of job management system based on SSM
AAAI2022 | Word Embeddings via Causal Inference: Gender Bias Reducing and Semantic Information Preserving