当前位置:网站首页>[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
边栏推荐
- EV6 helps the product matrix, and Kia is making efforts in the high-end market. The global sales target in 2022 is 3.15 million?
- SQL語句加强練習(MySQL8.0為例)
- Exercices de renforcement des déclarations SQL (MySQL 8.0 par exemple)
- Detailed explanation of PPTC self recovery fuse
- 機器學習基礎:用 Lasso 做特征選擇
- 投资深度思考
- [latex] production of complex tables: excel2latex and detail adjustment
- 150 ppt! The most complete "fair perception machine learning and data mining" tutorial, Dr. AIST Toshihiro kamishima, Japan
- SQL statement strengthening exercise (MySQL 8.0 as an example)
- 深入浅出对话系统——使用Transformer进行文本分类
猜你喜欢

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

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

EV6 helps the product matrix, and Kia is making efforts in the high-end market. The global sales target in 2022 is 3.15 million?
![[untitled]](/img/b5/bf76783aa428222623d760756a14d9.jpg)
[untitled]

Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?

JVM family -- monitoring tools
![[source code analysis] model parallel distributed training Megatron (5) -- pipestream flush](/img/94/2bdc31ec05595dbbc8a7a8d6b22252.jpg)
[source code analysis] model parallel distributed training Megatron (5) -- pipestream flush

Jenkins configures IP address access

Why is it recommended that technologists write blogs?

SQL语句加强练习(MySQL8.0为例)
随机推荐
Love and self-discipline and strive to live a core life
Audio and video technology development weekly | 232
Solve the problems encountered by the laravel framework using mongodb
Handler source code analysis
MySQL query
EV6 helps the product matrix, and Kia is making efforts in the high-end market. The global sales target in 2022 is 3.15 million?
Leetcode51.n queen
渗透实战-guest账户-mimikatz-向日葵-sql提权-离线解密
static hostname; transient hostname; pretty hostname
Objective-C string class, array class
New year's first race, submit bug reward more!
Base d'apprentissage de la machine: sélection de fonctionnalités avec lasso
Code Execution Vulnerability - no alphanumeric rce create_ function()
MySQL one master multiple slaves + linear replication
system information
Contest3145 - the 37th game of 2021 freshman individual training match_ 1: Origami
Future源碼一觀-JUC系列
Value transfer communication between components (parent to child, child to parent, brother component to value)
What kind of experience is it when the Institute earns 20000 yuan a month!
渗透实战-SQLServer提权