当前位置:网站首页>[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
边栏推荐
- What is cloud primordial?
- AAAI2022 | Word Embeddings via Causal Inference: Gender Bias Reducing and Semantic Information Preserving
- 投资深度思考
- system information
- Solve the problems encountered by the laravel framework using mongodb
- Contest3145 - the 37th game of 2021 freshman individual training match_ D: Ranking
- Add token validation in swagger
- Stm32bug [stlink forced update prompt appears in keilmdk, but it cannot be updated]
- Recursive structure
- Management and thesis of job management system based on SSM
猜你喜欢

GUI Graphical user interface programming (XIV) optionmenu - what do you want your girlfriend to wear on Valentine's day

Audio and video technology development weekly | 232

Exercices de renforcement des déclarations SQL (MySQL 8.0 par exemple)

基于PHP的轻量企业销售管理系统

Wechat official account web page authorization

Mindmanager2022 efficient and easy to use office mind map MindManager

JVM family -- monitoring tools

Third party login initial version

This function has none of DETERMINISTIC, NO SQL..... (you *might* want to use the less safe log_bin_t
![[PaddleSeg 源码阅读] PaddleSeg 自定义数据类](/img/88/37c535b371486db545abc392a685af.png)
[PaddleSeg 源码阅读] PaddleSeg 自定义数据类
随机推荐
Recent learning fragmentation (14)
[untitled]
What kind of experience is it when the Institute earns 20000 yuan a month!
Aperçu du code source futur - série juc
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
智慧地铁| 云计算为城市地铁交通注入智慧
新型数据中心,助力加快构建以数据为关键要素的数字经济
Objective-C description method and type method
渗透实战-guest账户-mimikatz-向日葵-sql提权-离线解密
2022 registration examination for safety production management personnel of fireworks and firecracker production units and examination skills for safety production management personnel of fireworks an
Jenkins continuous integration environment construction V (Jenkins common construction triggers)
Third party login initial version
Zlmediakit compilation and webrtc push-pull flow testing
PMP 考試常見工具與技術點總結
Solve the problems encountered by the laravel framework using mongodb
Sword finger offer:55 - I. depth of binary tree
ctf-pikachu-CSRF
Management and thesis of job management system based on SSM
SQL语句加强练习(MySQL8.0为例)
How to pipe several commands in Go?