TensorLayer基于TensorFlow的新型深度學(xué)習(xí)和強化學(xué)習(xí)庫
TensorLayer是一個基于TensorFlow的新型深度學(xué)習(xí)和強化學(xué)習(xí)庫,專為研究人員和工程師而設(shè)計。 它提供了大量可自定義的神經(jīng)層/功能,這些是構(gòu)建真實AI應(yīng)用程序的關(guān)鍵。 TensorLayer被ACM多媒體協(xié)會授予2017年最佳開源軟件。
作為深度學(xué)習(xí)從業(yè)者,我們一直在尋找可以滿足各種開發(fā)目的的庫。 通過提供各種示例,教程和預(yù)先訓(xùn)練的模型,可以輕松采用該庫。 此外,它允許用戶輕松微調(diào)TensorFlow; 同時適合生產(chǎn)部署。 TensorLayer旨在滿足所有這些目的。 它有三個主要特點:
- 簡單性:TensorLayer將TensorFlow的低級數(shù)據(jù)流接口提升到高級層/模型。 通過廣泛社區(qū)提供的豐富示例代碼,您可以輕松學(xué)習(xí)。
- 靈活性:TensorLayer API是透明的:它不會屏蔽用戶的TensorFlow; 但留下大量的鉤子,有助于低級調(diào)整和深度定制。
- 零成本抽象:TensorLayer可以實現(xiàn)TensorFlow的全部功能。 下表顯示了使用TensorLayer和TITAN Xp上的原生TensorFlow的VGG16的訓(xùn)練速度。
Mode Lib Data Format Max GPU Memory Usage(MB) Max CPU Memory Usage(MB) Avg CPU Memory Usage(MB) Runtime (sec) AutoGraph TensorFlow 2.0 channel last 11833 2161 2136 74 Tensorlayer 2.0 channel last 11833 2187 2169 76 Graph Keras channel last 8677 2580 2576 101 Eager TensorFlow 2.0 channel last 8723 2052 2024 97 TensorLayer 2.0 channel last 8723 2010 2007 95
TensorLayer 是作為一個開發(fā)庫來使用的。 其他包裝庫如Keras和TFLearn也提供高級抽象。 然而,它們經(jīng)常隱藏用戶的底層引擎,這使得它們難以定制和微調(diào)。 相反,TensorLayer API通常是輕量級,靈活且透明的。 用戶經(jīng)常會發(fā)現(xiàn)從示例和教程開始很容易,然后無縫地深入了解TensorFlow。 此外,TensorLayer不會通過本機支持創(chuàng)建庫鎖定,以便從Keras導(dǎo)入組件。
TensorLayer在北京大學(xué),倫敦帝國理工學(xué)院,加州大學(xué)伯克利分校,卡內(nèi)基梅隆大學(xué),斯坦福大學(xué),康涅狄格大學(xué)(UTC)以及谷歌,微軟,阿里巴巴等公司等頂尖研究人員和工程師中的使用增長迅速。
模型定義:
靜態(tài)模型:
import tensorflow as tf
from tensorlayer.layers import Input, Dropout, Dense
from tensorlayer.models import Model
def get_model(inputs_shape):
ni = Input(inputs_shape)
nn = Dropout(keep=0.8)(ni)
nn = Dense(n_units=800, act=tf.nn.relu, name="dense1")(nn)
nn = Dropout(keep=0.8)(nn)
nn = Dense(n_units=800, act=tf.nn.relu)(nn)
nn = Dropout(keep=0.8)(nn)
nn = Dense(n_units=10, act=tf.nn.relu)(nn)
M = Model(inputs=ni, outputs=nn, name="mlp")
return M
MLP = get_model([None, 784])
MLP.eval()
outputs = MLP(data)
動態(tài)模型:
class CustomModel(Model):
def __init__(self):
super(CustomModel, self).__init__()
self.dropout1 = Dropout(keep=0.8)
self.dense1 = Dense(n_units=800, act=tf.nn.relu, in_channels=784)
self.dropout2 = Dropout(keep=0.8)#(self.dense1)
self.dense2 = Dense(n_units=800, act=tf.nn.relu, in_channels=800)
self.dropout3 = Dropout(keep=0.8)#(self.dense2)
self.dense3 = Dense(n_units=10, act=tf.nn.relu, in_channels=800)
def forward(self, x, foo=False):
z = self.dropout1(x)
z = self.dense1(z)
z = self.dropout2(z)
z = self.dense2(z)
z = self.dropout3(z)
out = self.dense3(z)
if foo:
out = tf.nn.relu(out)
return out
MLP = CustomModel()
MLP.eval()
outputs = MLP(data, foo=True) # controls the forward here
outputs = MLP(data, foo=False)
評論
圖片
表情
