Tensorflow高性能數(shù)據(jù)優(yōu)化增強(qiáng)工具Pipeline使用詳解
安裝方法
給大家介紹一個非常好用的TensorFlow數(shù)據(jù)pipeline工具。
高性能的Tensorflow Data Pipeline,使用SOTA的增強(qiáng)和底層優(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,為驗(yà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": 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ù)增強(qiáng)字典中的對應(yīng)關(guān)鍵字。
- categorical_encoding - 對類別數(shù)據(jù)進(jìn)行編碼 - ('labelencoder' , 'onehotencoder').
增強(qiáng):
GridMask
在輸入圖像上創(chuàng)建gridmask,并在范圍內(nèi)定義旋轉(zhuǎn)。
參數(shù):
ratio - 空間上的網(wǎng)格比例
fill - 填充值fill value
rotate - 旋轉(zhuǎn)的角度范圍
MixUp
使用給定的alpha值,將兩個隨機(jī)采樣的圖像和標(biāo)簽進(jìn)行混合。
參數(shù):
alpha - 在混合時使用的值。
RandomErase
在給定的圖像上的隨機(jī)位置擦除一個隨機(jī)的矩形區(qū)域。
參數(shù):
prob - 在圖像上進(jìn)行隨機(jī)的概率。
CutMix
在給定圖像上對另一個隨機(jī)采樣的圖像進(jìn)行隨機(jī)的縮放,再以完全覆蓋的方式貼到這個給定圖像上。
params:
prob - 在圖像上進(jìn)行CutMix的概率。
Mosaic
把4張輸入圖像組成一張馬賽克圖像。
參數(shù):
prob - 進(jìn)行Mosaic的概率。
CutMix , CutOut, MixUp

Mosaic

Grid Mask

以上就是Tensorflow高性能數(shù)據(jù)優(yōu)化增強(qiáng)工具Pipeline使用詳解的詳細(xì)內(nèi)容,更多關(guān)于Tensorflow數(shù)據(jù)工具Pipeline的資料請關(guān)注腳本之家其它相關(guān)文章!
- Tensorflow2.1 完成權(quán)重或模型的保存和加載
- Tensorflow2.1實(shí)現(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 實(shí)現(xiàn)購物商城,含有用戶入口和商家入口的示例
下面小編就為大家?guī)硪黄狿ython 實(shí)現(xiàn)購物商城,含有用戶入口和商家入口的示例。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-09-09
python實(shí)現(xiàn)按任意鍵繼續(xù)執(zhí)行程序
本文給大家分享的是如何使用Python腳本實(shí)現(xiàn)按任意鍵繼續(xù)執(zhí)行程序的代碼,非常的簡單實(shí)用,有需要的小伙伴可以參考下2016-12-12
Pytest+Request+Allure+Jenkins實(shí)現(xiàn)接口自動化
這篇文章介紹了Pytest+Request+Allure+Jenkins實(shí)現(xiàn)接口自動化的方法,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-06-06
python?管理系統(tǒng)實(shí)現(xiàn)mysql交互的示例代碼
這篇文章主要介紹了python?管理系統(tǒng)實(shí)現(xiàn)mysql交互,本文通過實(shí)例代碼圖文相結(jié)合給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-12-12
python實(shí)現(xiàn)監(jiān)控windows服務(wù)并自動啟動服務(wù)示例
這篇文章主要介紹了python實(shí)現(xiàn)監(jiān)控windows服務(wù)并自動啟動服務(wù)示例,需要的朋友可以參考下2014-04-04
Python游戲開發(fā)實(shí)例之graphics實(shí)現(xiàn)AI五子棋
五子棋是經(jīng)典的棋牌類游戲,很多人都玩過,那么如何用Python實(shí)現(xiàn)五子棋呢,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-11-11

