Tensorflow高性能數(shù)據(jù)優(yōu)化增強工具Pipeline使用詳解
安裝方法
給大家介紹一個非常好用的TensorFlow數(shù)據(jù)pipeline工具。
高性能的Tensorflow Data Pipeline,使用SOTA的增強和底層優(yōu)化。
pip install tensorflow-addons==0.11.2 pip install tensorflow==2.2.0 pip install sklearn
功能
- High Performance tf.data pipline
- Core tensorflow support for high performance
- Classification data support
- Bbox data support
- Keypoints data support
- Segmentation data support
- GridMask in core tf2.x
- Mosiac Augmentation in core tf2.x
- CutOut in core tf2.x
- Flexible and easy configuration
- Gin-config support
高級用戶部分
用例1,為訓(xùn)練創(chuàng)建數(shù)據(jù)Pipeline
from pipe import Funnel from bunch import Bunch """ Create a Funnel for the Pipeline! """ # Config for Funnel config = { "batch_size": 2, "image_size": [512,512], "transformations": { "flip_left_right": None, "gridmask": None, "random_rotate":None, }, "categorical_encoding":"labelencoder" } config = Bunch(config) pipeline = Funnel(data_path="testdata", config=config, datatype="categorical") pipeline = pipeline.dataset(type="train") # Pipline ready to use, iter over it to use. # Custom loop example. for data in pipeline: image_batch , label_batch = data[0], data[1] # you can use _loss = loss(label_batch,model.predict(image_batch)) # calculate gradients on loss and optimize the model. print(image_batch,label_batch)
用例2,為驗證創(chuàng)建數(shù)據(jù)Pipeline
from pipe import Funnel from bunch import Bunch """ Create a Funnel for the Pipeline! """ # Config for Funnel config = { "batch_size": 1, "image_size": [512,512], "transformations": { }, "categorical_encoding":"labelencoder" } config = Bunch(config) pipeline = Funnel(data_path="testdata", config=config, datatype="categorical", training=False) pipeline = pipeline.dataset(type="val") # use pipeline to validate your data on model. loss = [] for data in pipeline: image_batch , actual_label_batch = data[0], data[1] # pred_label_batch = model.predict(image_batch) # loss.append(calc_loss(actual_label_batch,pred_label_batch)) print(image_batch,label_batch)
初學(xué)者部分
Keras 兼容性
使用keras model.fit來構(gòu)建非常簡單的pipeline。
import tensorflow as tf from pipe import Funnel """ Create a Funnel for the Pipeline! """ config = { "batch_size": 2, "image_size": [100, 100], "transformations": { "flip_left_right": None, "gridmask": None, "random_rotate": None, }, "categorical_encoding": "labelencoder", } pipeline = Funnel(data_path="testdata", config=config, datatype="categorical") pipeline = pipeline.dataset(type="train") # Create Keras model model = tf.keras.applications.VGG16( include_top=True, weights=None,input_shape=(100,100,3), pooling=None, classes=2, classifier_activation='sigmoid' ) # compile model.compile(loss='mse', optimizer='adam') # pass pipeline as iterable model.fit(pipeline , batch_size=2,steps_per_epoch=5,verbose=1)
配置
- image_size - pipeline的圖像尺寸。
- batch_size - pipeline的Batch size。
- transformations - 應(yīng)用數(shù)據(jù)增強字典中的對應(yīng)關(guān)鍵字。
- categorical_encoding - 對類別數(shù)據(jù)進(jìn)行編碼 - ('labelencoder' , 'onehotencoder').
增強:
GridMask
在輸入圖像上創(chuàng)建gridmask,并在范圍內(nèi)定義旋轉(zhuǎn)。
參數(shù):
ratio - 空間上的網(wǎng)格比例
fill - 填充值fill value
rotate - 旋轉(zhuǎn)的角度范圍
MixUp
使用給定的alpha值,將兩個隨機采樣的圖像和標(biāo)簽進(jìn)行混合。
參數(shù):
alpha - 在混合時使用的值。
RandomErase
在給定的圖像上的隨機位置擦除一個隨機的矩形區(qū)域。
參數(shù):
prob - 在圖像上進(jìn)行隨機的概率。
CutMix
在給定圖像上對另一個隨機采樣的圖像進(jìn)行隨機的縮放,再以完全覆蓋的方式貼到這個給定圖像上。
params:
prob - 在圖像上進(jìn)行CutMix的概率。
Mosaic
把4張輸入圖像組成一張馬賽克圖像。
參數(shù):
prob - 進(jìn)行Mosaic的概率。
CutMix , CutOut, MixUp
Mosaic
Grid Mask
以上就是Tensorflow高性能數(shù)據(jù)優(yōu)化增強工具Pipeline使用詳解的詳細(xì)內(nèi)容,更多關(guān)于Tensorflow數(shù)據(jù)工具Pipeline的資料請關(guān)注腳本之家其它相關(guān)文章!
- Tensorflow2.1 完成權(quán)重或模型的保存和加載
- Tensorflow2.1實現(xiàn)Fashion圖像分類示例詳解
- Tensorflow2.4使用Tuner選擇模型最佳超參詳解
- python深度學(xué)習(xí)tensorflow訓(xùn)練好的模型進(jìn)行圖像分類
- python深度學(xué)習(xí)tensorflow1.0參數(shù)和特征提取
- python深度學(xué)習(xí)tensorflow1.0參數(shù)初始化initializer
- python深度學(xué)習(xí)tensorflow卷積層示例教程
- Tensorflow?2.4加載處理圖片的三種方式詳解
相關(guān)文章
在Python的Flask框架中實現(xiàn)單元測試的教程
這篇文章主要介紹了在Python的Flask框架中實現(xiàn)單元測試的教程,屬于自動化部署的方面,可以給debug工作帶來諸多便利,需要的朋友可以參考下2015-04-04Python利用pangu模塊實現(xiàn)文本格式化小工具
其實使用pangu做文本格式標(biāo)準(zhǔn)化的業(yè)務(wù)代碼在之前就實現(xiàn)了,主要能夠?qū)⒅形奈谋疚臋n中的文字、標(biāo)點符號等進(jìn)行標(biāo)準(zhǔn)化。但是為了方便起來我們這里使用了Qt5將其做成了一個可以操作的頁面應(yīng)用,需要的可以了解一下2022-10-10python代碼實現(xiàn)TSNE降維數(shù)據(jù)可視化教程
今天小編就為大家分享一篇python代碼實現(xiàn)TSNE降維數(shù)據(jù)可視化教程,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-02-02在Django admin中編輯ManyToManyField的實現(xiàn)方法
今天小編就為大家分享一篇在Django admin中編輯ManyToManyField的實現(xiàn)方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-08-08