当前位置:网站首页>[paddleseg source code reading] normalize operation of paddleseg transform
[paddleseg source code reading] normalize operation of paddleseg transform
2022-07-04 03:37:00 【Master Fuwen】
Connected to a ,PaddleSeg Custom data class https://blog.csdn.net/HaoZiHuang/article/details/125566058 Let's talk about it here Normalize operation
Let's write it ourselves Transform when , Always worry about some details , such as :
- np.uint8 Did you turn , Do you want to change to np.float32
- Have you done it yet (
/255Did you do it ) - With or without subtracting 0.5, Then divide by 0.5, Move it to -1 To 1
- Before sending data , Is there any transpose And so on.
- When will numpy.ndarray Initialize to paddle.Tensor
Last one PaddleSeg Speaking of , stay Compose ending , Can convert the number of input channels (Transpose), And look at the source code :
batch_sampler = paddle.io.DistributedBatchSampler(
eval_dataset, batch_size=1, shuffle=False, drop_last=False)
loader = paddle.io.DataLoader(
eval_dataset,
batch_sampler=batch_sampler,
num_workers=num_workers,
return_list=True, )
This is instantiation ,Dataset and DataLoader Part of , Even though eval_dataset Every data returned is np.ndarray, however paddle.io.DataLoader This class , Will go straight back to Paddle.Tensor Class , That is, there is no need to do paddle.to_tensor operation
OK, The next three items :
- np.uint8 Did you turn , Do you want to change to np.float32
- Have you done it yet
- With or without subtracting 0.5, Then divide by 0.5, Move it to -1 To 1
Namely Normalize Part of the operation , Take a look at the source code of its implementation
paddleseg\transforms\transforms.py in Normalize class
@manager.TRANSFORMS.add_component
class Normalize:
""" Normalize an image. Args: mean (list, optional): The mean value of a data set. Default: [0.5, 0.5, 0.5]. std (list, optional): The standard deviation of a data set. Default: [0.5, 0.5, 0.5]. Raises: ValueError: When mean/std is not list or any value in std is 0. """
def __init__(self, mean=(0.5, 0.5, 0.5), std=(0.5, 0.5, 0.5)):
self.mean = mean
self.std = std
if not (isinstance(self.mean,
(list, tuple)) and isinstance(self.std,
(list, tuple))):
raise ValueError(
"{}: input type is invalid. It should be list or tuple".format(
self))
from functools import reduce
if reduce(lambda x, y: x * y, self.std) == 0:
raise ValueError('{}: std is invalid!'.format(self))
def __call__(self, im, label=None):
""" Args: im (np.ndarray): The Image data. label (np.ndarray, optional): The label data. Default: None. Returns: (tuple). When label is None, it returns (im, ), otherwise it returns (im, label). """
mean = np.array(self.mean)[np.newaxis, np.newaxis, :]
std = np.array(self.std)[np.newaxis, np.newaxis, :]
im = functional.normalize(im, mean, std)
if label is None:
return (im, )
else:
return (im, label)
paddleseg\transforms\functional.py in normalize function
def normalize(im, mean, std):
im = im.astype(np.float32, copy=False) / 255.0
im -= mean
im /= std
return im
You can see stay normalize Function , Made a turn np.float32, normalization
then -0.5 after /0.5
If you are interested in these two fields :
mean = np.array(self.mean)[np.newaxis, np.newaxis, :]
std = np.array(self.std )[np.newaxis, np.newaxis, :]
Print it yourself , It's the original array The dimension is preceded by two 1
shape from (3,) Turned into (1, 1, 3)
and np.newaxis In fact, that is None
(np.newaxis == None) == True
If the Normalize __init__ Function reduce Interested in :
Look at this :
functools Under the reduce function
边栏推荐
- Webhook triggers Jenkins for sonar detection
- The property of judging odd or even numbers about XOR.
- Audio and video technology development weekly | 232
- Why is it recommended that technologists write blogs?
- Class summation, shortest row
- Recent learning fragmentation (14)
- Object oriented -- encapsulation, inheritance, polymorphism
- How much does it cost to open a futures account in China? Where is it safe to open an account at present?
- Infiltration practice guest account mimikatz sunflower SQL rights lifting offline decryption
- Typical applications of minimum spanning tree
猜你喜欢

What is cloud primordial?

(column 23) typical C language problem: find the minimum common multiple and maximum common divisor of two numbers. (two solutions)

AAAI2022 | Word Embeddings via Causal Inference: Gender Bias Reducing and Semantic Information Preserving

微信公众号网页授权

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

SQL语句加强练习(MySQL8.0为例)

Objective-C description method and type method

Cache general management class + cache httpcontext Current. Cache and httpruntime Differences between caches

Monitoring - Prometheus introduction

The 37 year old programmer was laid off, and he didn't find a job for 120 days. He had no choice but to go to a small company. As a result, he was confused
随机推荐
Sword finger offer:55 - I. depth of binary tree
选择排序与冒泡排序模板
Which product is better for 2022 annual gold insurance?
CUDA basic knowledge
Learning video website
What are the virtual machine software? What are their respective functions?
PMP 考試常見工具與技術點總結
Base d'apprentissage de la machine: sélection de fonctionnalités avec lasso
Tsinghua University product: penalty gradient norm improves generalization of deep learning model
MySQL is dirty
XSS prevention
Love and self-discipline and strive to live a core life
Defensive programming skills
@Scheduled scheduled tasks
Contest3145 - the 37th game of 2021 freshman individual training match_ F: Smallest ball
Rhcsa day 3
Stm32bug [the project references devices, files or libraries that are not installed appear in keilmdk]
New year's first race, submit bug reward more!
SQL statement strengthening exercise (MySQL 8.0 as an example)
Management and thesis of job management system based on SSM