当前位置:网站首页>[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
])边栏推荐
- Safety margin of mass consumption
- Personally test five efficient and practical ways to get rid of orders, and quickly collect them to help you quickly find high-quality objects!
- 软件测试岗:阿里三面,幸好做足了准备,已拿offer
- [noip2001 popularization group] packing problem
- Win11 method of changing disk drive letter
- Remember SQL optimization once
- 【TensorFlow&PyTorch】图像数据增强API
- STM32 - DMA notes
- Unity快速搭建城市场景
- snownlp库各功能及用法
猜你喜欢

Cloud native guide what is cloud native infrastructure
![[detailed explanation of key and difficult points of document operation]](/img/f5/99c8cdf09763c66ab5d56cc96e50c7.png)
[detailed explanation of key and difficult points of document operation]

Detailed explanation of extended physics informedneural networks paper

移位距离和假设的应用

Self-supervised learning method to solve the inverse problem of Fokker-Planck Equation

Arthas view the source code of the loaded class (JAD)

Three years of software testing experience, salary has been stuck at 10K, how to improve and develop automated testing?

实现一个方法,找出数组中的第k大和第m大的数字相加之和

LeetCode·83双周赛·6128.最好的扑克手牌·模拟

C language layered understanding (C language function)
随机推荐
STM32——DMA笔记
这种动态规划你见过吗——状态机动态规划之股票问题(上)
canvas——心电图的设计,以及如何清理画布
如何用U盘进行装机?
Chen Yili, China Academy of communications technology: cost reduction and efficiency increase are the greatest value of Enterprise Cloud native applications
YOLOv3: An Incremental Improvement
Continuous delivery and Devops are good friends
YOLOv3: An Incremental Improvement
重装Win7系统如何进行?
Machine learning foundation plan 0-2: what is machine learning? What does it have to do with AI?
Three years of software testing experience, salary has been stuck at 10K, how to improve and develop automated testing?
LeetCode·
Functions and usage of snownlp Library
Quick check of OGC WebGIS common service standards (wms/wmts/tms/wfs)
多线程编程
Programming example of STM32 state machine -- fully automatic washing machine (Part 1)
Keyboardtraffic, a tool developed by myself to solve CTF USB keyboard traffic
经典面试问题——OOP语言的三大特征
Skill list of image processing experts
中国信通院陈屹力:降本增效是企业云原生应用的最大价值
https://tensorflow.google.cn/versions/r2.0/api_docs/python/tf/image