TensorFlow(二)
TensorFlow
控制流
tf.cond
a=tf.constant(2) b=tf.constant(3) x=tf.constant(4) y=tf.constant(5) z = tf.multiply(a, b) result = tf.cond(x < y, lambda: tf.add(x, z), lambda: tf.square(y)) with tf.Session() as session:print(result.eval())tf.case
decode_png = lambda :tf.image.decode_png(image_tensor, channels) decode_jpg = lambda :tf.image.decode_jpeg(image_tensor, channels) decoder = { tf.equal(image_ext, '.png'): decode_png,tf.equal(image_ext, '.jpg'): decode_jpg} image_tensor = tf.case(decoder, default = decode_png, exclusive = True)TFLite
Tensorflow源代碼中自帶的toco工具,可用于生成一個(gè)可供TensorFlow Lite框架使用的tflite文件。
代碼:
https://github.com/tensorflow/tensorflow/tree/master/tensorflow/contrib/lite/toco
參考:
https://www.jianshu.com/p/fa204a54a956
生成TFLite模型文件
https://mp.weixin.qq.com/s/eSczqqyzh4PZomJL4saxug
出門(mén)問(wèn)問(wèn):使用TensorFlow Lite在嵌入式端部署熱詞檢測(cè)模型
https://mp.weixin.qq.com/s/U_Pew90j9swIqti3oKEIQg
玩轉(zhuǎn)TensorFlow Lite:有道云筆記實(shí)操案例分享
https://mp.weixin.qq.com/s/lNP9WdzSWE4FjB_-Sjc2aA
TensorFlow Lite for Android初探
Broadcast
Broadcast是一種填充元素以使操作數(shù)的形狀相匹配的操作。例如,對(duì)一個(gè)[3,2]的張量和一個(gè)[3,1]的張量相加在TF中是合法的,TF會(huì)使用默認(rèn)的規(guī)則將[3,1]的張量填充為[3,2]的張量,從而使操作能夠執(zhí)行下去。
參考:
https://www.cnblogs.com/yangmang/p/7125458.html
numpy數(shù)組廣播
https://blog.csdn.net/LoseInVain/article/details/78763303
TensorFlow中的廣播Broadcast機(jī)制
TensorFlow Serving
TensorFlow Serving是一個(gè)用于機(jī)器學(xué)習(xí)模型serving的高性能開(kāi)源庫(kù)。它可以將訓(xùn)練好的機(jī)器學(xué)習(xí)模型部署到線上,使用gRPC作為接口接受外部調(diào)用。更加讓人眼前一亮的是,它支持模型熱更新與自動(dòng)模型版本管理。
代碼:
https://github.com/tensorflow/serving
TensorFlow Serving實(shí)際上是TensorFlow Extended (TFX)的一部分:
https://tensorflow.google.cn/tfx
TFX還包括了Data Validation、Transform和Model Analysis等方面的功能。
參考:
https://zhuanlan.zhihu.com/p/23361413
TensorFlow Serving嘗嘗鮮
http://www.cnblogs.com/xuchenCN/p/5888638.html
tensorflow serving
https://mp.weixin.qq.com/s/iqvpX6QuBEmF_UK9RMu9eQ
TensorFlow Serving入門(mén)
https://mp.weixin.qq.com/s/TL87BY3DdP1bolc0Sxkahg
gRPC客戶(hù)端創(chuàng)建和調(diào)用原理解析
https://zhuanlan.zhihu.com/p/30628048
遠(yuǎn)程通信協(xié)議:從CORBA到gRPC
https://mp.weixin.qq.com/s/b569est_LpcxsoTNWXcfog
TensorFlow Extended幫你快速落地項(xiàng)目
https://mp.weixin.qq.com/s/qOy9fR8Zd3SufvsMmLpoGg
使用TensorFlow Serving優(yōu)化TensorFlow模型
https://mp.weixin.qq.com/s/IPwOZKvDsONegyIuwkG6bQ
將深度學(xué)習(xí)模型部署為web應(yīng)用有多難?答案自己找
https://mp.weixin.qq.com/s/7nugWFKtD-C6cpwm2TyvdQ
手把手教你如何部署深度學(xué)習(xí)模型
op的C++實(shí)現(xiàn)
有的時(shí)候?yàn)榱藢ensorflow的op移植到其他平臺(tái),需要找到相應(yīng)op的cpu實(shí)現(xiàn)。比如space_to_batch這個(gè)op,它的實(shí)現(xiàn)在:
core/kernels/spacetobatch_op.cc
簡(jiǎn)單的op一般找到這里就可以了,但space_to_batch還要更深一層:
core/kernels/spacetobatch_functor.cc
一般XXX_impl.cc或者XXX_functor.cc才是op實(shí)現(xiàn)真正所在的位置。
此外,TFlite的實(shí)現(xiàn)往往更加簡(jiǎn)單:
tensorflow/contrib/lite/kernels/internal/reference/reference_ops.h
TensorFlow.js
https://mp.weixin.qq.com/s/dqMS4NjmNYs7IFHm8uFM8w
TensorFlow發(fā)布面向JavaScript開(kāi)發(fā)者的機(jī)器學(xué)習(xí)框架TensorFlow.js
https://zhuanlan.zhihu.com/p/35181413
TensorFlow.js人臉識(shí)別—玩轉(zhuǎn)吃豆豆小游戲
https://mp.weixin.qq.com/s/ebLHZAG8H78TsZUKSzAtIw
TF官方博客:基于TensorFlow.js框架的瀏覽器實(shí)時(shí)姿態(tài)估計(jì)
https://mp.weixin.qq.com/s/z6p4A4DfCuK8IBGVGwrtLQ
如何利用TensorFlow.js部署簡(jiǎn)單的AI版“你畫(huà)我猜”圖像識(shí)別應(yīng)用
https://mp.weixin.qq.com/s/NO_XY-JmTpIkoC-fpkZ-qg
在瀏覽器上也能訓(xùn)練神經(jīng)網(wǎng)絡(luò)?TensorFlow.js帶你玩游戲~
Eager Execution
TensorFlow的Eager Execution可立即評(píng)估操作,無(wú)需構(gòu)建圖:操作會(huì)返回具體的值,而不是構(gòu)建以后再運(yùn)行的計(jì)算圖。這也就是所謂的動(dòng)態(tài)圖計(jì)算的概念。
參考:
https://mp.weixin.qq.com/s/Yp2zE85VCx8q67YXvuw5qw
TensorFlow引入了動(dòng)態(tài)圖機(jī)制Eager Execution
https://github.com/ZhuanZhiCode/TensorFlow-Eager-Execution-Examples
Eager Execution的代碼示例
https://mp.weixin.qq.com/s/By_GKPtY6xr8MwkWA6frzA
TensorFlow的動(dòng)態(tài)圖工具Eager怎么用?這是一篇極簡(jiǎn)教程
https://mp.weixin.qq.com/s/Lvd4NfLg0Lzivb4BingV7w
Tensorflow Eager Execution入門(mén)指南
https://mp.weixin.qq.com/s/q6bJfCV5kU8BzvWjOXkCDg
簡(jiǎn)單粗暴TensorFlow Eager教程
https://mp.weixin.qq.com/s/zz8XCykJ6jxbE5J4YwAkEA
一招教你使用tf.keras和eager execution解決復(fù)雜問(wèn)題
Estimator
Estimator是一個(gè)非常高級(jí)的API,其抽象等級(jí)甚至在Keras之上。
Estimator主要包括以下部分:
1.初始化。定義網(wǎng)絡(luò)結(jié)構(gòu)。
2.train。
3.evaluate。
4.predict。
TensorFlow已經(jīng)包含了一些預(yù)置的Estimator。例如:BoostedTreesClassifier、DNNClassifier、LinearClassifier等。具體可參見(jiàn):
https://tensorflow.google.cn/api_docs/python/tf/estimator
參考:
https://mp.weixin.qq.com/s/a68brFJthczgwiFoUBh30A
TensorFlow數(shù)據(jù)集和估算器介紹
細(xì)節(jié)
執(zhí)行session.run(out),會(huì)在終端打印out的值,但執(zhí)行res = session.run(out)則不會(huì)。
tensorflow的程序中,在main函數(shù)下,都是使用tf.app.run()來(lái)啟動(dòng)。查看源碼可知,該函數(shù)是用來(lái)處理flag解析,然后執(zhí)行main函數(shù)。
https://blog.csdn.net/lujiandong1/article/details/53262612
tensorflow中的tf.app.run()
TF提供了一套專(zhuān)門(mén)的IO函數(shù):tf.gfile。主要優(yōu)點(diǎn)在于:對(duì)于寫(xiě)文件來(lái)說(shuō),open操作直到真的需要寫(xiě)的時(shí)候才執(zhí)行。
遷移學(xué)習(xí)的時(shí)候,有的時(shí)候需要保持某幾層的權(quán)值,在后續(xù)訓(xùn)練中不被改變。這時(shí),可以在創(chuàng)建Variable時(shí),令trainable=false。
sparse_softmax_cross_entropy_with_logits和softmax_cross_entropy_with_logits的區(qū)別在于:后者的label是一個(gè)one hot的tensor,而前者label直接用對(duì)應(yīng)分類(lèi)的index表示就行了。
blog
http://www.jianshu.com/u/eaec1fc422e9
一個(gè)TF的blog
http://blog.csdn.net/u012436149
一個(gè)TensorFlow+PyTorch的blog
我的TensorFlow實(shí)踐
MNIST+Softmax
代碼:
https://github.com/antkillerfarm/antkillerfarm_crazy/tree/master/python/ml/tensorflow/hello_mnist.py
MNIST+CNN
代碼:
https://github.com/antkillerfarm/antkillerfarm_crazy/tree/master/python/ml/tensorflow/hello_cnn.py
第一個(gè)例子中,我對(duì)CPU的計(jì)算能力還沒(méi)有切膚之痛,但在這里使用CPU差不多要花半個(gè)小時(shí)時(shí)間。。。
總結(jié)
以上是生活随笔為你收集整理的TensorFlow(二)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 深度学习(三十)——Deep Speec
- 下一篇: 知名数据集