当前位置:网站首页>[tensorflow & pytorch] image data enhancement API
[tensorflow & pytorch] image data enhancement API
2022-07-26 03:10:00 【Detour】
Preface :
In deep learning training , The training effect is poor 、 Small number of training sets 、 When there is a fitting trend, you can choose to increase the number of data sets to optimize the training model , But most of the time , The amount of time and effort spent on increasing the number of data sets is enormous , Therefore, the more common method we use is to enhance the existing data sets . It's better to actually increase the number of data sets , But it still has certain effect , High cost performance .( Just add a few lines of code )
TensorFlow Of API stay image Next :( I am using 2.0 edition , Different versions may API Different , But basically, it can be in iamge Find below )
from tensorflow import imagePyTorch Of API stay torchvision Of transforms Next :torchvision — Torchvision 0.13 documentation
https://pytorch.org/vision/stable/index.html
from torchvision import transformsHere are some methods I think are commonly used .
To be detailed API Click the link above to view the official documents .
Randomly flip the picture :
TensorFlow:
Randomly flip up and down :
output=image.random_flip_up_down(input)
Randomly flip left and right :
output=image.random_flip_left_right(input)
PyTorch:
Randomly flip up and down :
layer=transform.RandomHorizontalFlip( )
Randomly flip left and right :
layer=transform.RandomVerticalFlip( )
Rotate the image randomly |n°|:
layer=transform.RandomRotation(n)
Notice that what you get here is a layer (layer), You also need to stuff the picture into the layer to get the result . and TensorFlow The example in is that the result can be obtained directly .
example :output=layer(input)
Crop the image randomly :
TensorFlow:
take input Cut randomly into shape size :
output=image.random_crop(input,[shape])
take input Random cutting , The central part is reserved central_fraction(0~1). for example central_fraction=0.5, Then half of the central part is reserved .
output=image.central_crop(input, central_fraction)
PyTorch:
Get to crop the incoming image into shape The layer :
layer=transforms.RandomCrop(shape)
Get the central part of the incoming image and crop it into shape The layer :
layer=transform.CenterCrop(shape)
Regularization :
Strictly speaking, regularization is not data enhancement , But it can make the image more convenient for training . The following example is limited to three channels RGB Images .
Change the pixel value of the image into an average of mean, The variance of std Is a normal distribution .
Following mean and std It is the optimal value calculated by predecessors ( Maybe ?)
TensorFlow:
TensorFlow There seems to be no interface , So I have to write it myself :
mean=tf.constant([0.485,0,456,0.406]) std=tf.constant([0.229,0.224,0.225]) output=(input-mean)/std
PyTorch:
layer=transform.Normalize(mean=[0.485,0.456,0.406],std=[0.229,0.224,0.225])
ending :
TensorFlow Of image There are many image processing API( Not limited to data enhancement ), If you are interested, you can have a look at .( I'm tired of reading English if I'm not good at it )
Because of the above PyTorch What you get is layers , So it can be packaged into a container :
transform.Compose([
layer1,
layer2,
layer3,
………………
transform.ToTensor()# Finally, remember to add this layer , Turn the image into tensorf Can be pytorch distinguish
])边栏推荐
- 文件操作(一)——文件简介与文件的打开方式和关闭
- [translation] safety. Value of sboms
- (九)属性自省
- My friend took 25koffer as soon as he learned automation test. When will my function test end?
- Golang log programming system
- Small test (I)
- Machine learning foundation plan 0-2: what is machine learning? What does it have to do with AI?
- Self-supervised learning method to solve the inverse problem of Fokker-Planck Equation
- STM32——DMA笔记
- Neo4j 导入csv数据报错:Neo4j load csv error : Couldn‘t load the external resource
猜你喜欢
随机推荐
如何用U盘进行装机?
ByteDance (Tiktok) software test monthly salary 23K post, technical two-sided interview questions are newly released
STM——EXTI外部中断学习笔记
C language layered understanding (C language function)
Influence of middle tap change on ZVS oscillation circuit
【尤里复裂人】带你轻松理解——深拷贝和浅拷贝
了解预加载和懒加载、学会缓动动画
Arthas download and startup
Be highly vigilant! Weaponization of smartphone location data on the battlefield
Jsd-2204-cool shark Mall (Management Commodity module) -day02
[NOIP2001 普及组]装箱问题
Three years of software testing experience, salary has been stuck at 10K, how to improve and develop automated testing?
经典面试问题——OOP语言的三大特征
记一次SQL优化
Detailed explanation of extended physics informedneural networks paper
.net serialize enumeration as string
VR panoramic shooting and production of business center helps businesses effectively attract people
Application of shift distance and hypothesis
Is the galaxy VIP account opened by qiniu safe?
LeetCode·每日一题·剑指 Offer || 115.重建序列·拓扑排序
https://tensorflow.google.cn/versions/r2.0/api_docs/python/tf/image








