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