当前位置:网站首页>[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
边栏推荐
- CSP drawing
- what does ctrl + d do?
- Baijia forum the founding of the Eastern Han Dynasty
- This function has none of DETERMINISTIC, NO SQL..... (you *might* want to use the less safe log_bin_t
- MySQL is dirty
- 【.NET+MQTT】.NET6 環境下實現MQTT通信,以及服務端、客戶端的雙邊消息訂閱與發布的代碼演示
- MySQL backup notes
- CUDA basic knowledge
- What kind of experience is it when the Institute earns 20000 yuan a month!
- Command Execution Vulnerability - command execution - vulnerability sites - code injection - vulnerability exploitation - joint execution - bypass (spaces, keyword filtering, variable bypass) - two ex
猜你喜欢

MySQL maxscale realizes read-write separation

Redis notes (I) Linux installation process of redis

AAAI2022 | Word Embeddings via Causal Inference: Gender Bias Reducing and Semantic Information Preserving
![[PaddleSeg 源码阅读] PaddleSeg 自定义数据类](/img/88/37c535b371486db545abc392a685af.png)
[PaddleSeg 源码阅读] PaddleSeg 自定义数据类

Webhook triggers Jenkins for sonar detection

National standard gb28181 protocol platform easygbs fails to start after replacing MySQL database. How to deal with it?
![Stm32bug [stlink forced update prompt appears in keilmdk, but it cannot be updated]](/img/ad/b675364fcaf5d874397fd0cbfec11b.jpg)
Stm32bug [stlink forced update prompt appears in keilmdk, but it cannot be updated]

Summary of Chinese remainder theorem

@Scheduled scheduled tasks

Add token validation in swagger
随机推荐
Object oriented -- encapsulation, inheritance, polymorphism
Exercices de renforcement des déclarations SQL (MySQL 8.0 par exemple)
2006 translation
JVM family -- heap analysis
Contest3145 - the 37th game of 2021 freshman individual training match_ E: Eat watermelon
Rhcsa day 2
How to use STR function of C language
Value transfer communication between components (parent to child, child to parent, brother component to value)
Practical multifunctional toolbox wechat applet source code / support traffic master
Cache general management class + cache httpcontext Current. Cache and httpruntime Differences between caches
How much does it cost to open a futures account in China? Where is it safe to open an account at present?
[PaddleSeg 源码阅读] PaddleSeg 自定义数据类
Katalon框架测试web(二十一)获取元素属性断言
Which product is better for 2022 annual gold insurance?
150 ppt! The most complete "fair perception machine learning and data mining" tutorial, Dr. AIST Toshihiro kamishima, Japan
Day05 錶格
Eh, the log time of MySQL server is less than 8h?
[untitled]
Love and self-discipline and strive to live a core life
logistic regression