發表文章

目前顯示的是 7月, 2017的文章

[DL] Tensorflow android demo

圖片
          最近在學習如何將tensorflow架在android上面,利用平板去跑深度學習。基本上是照的tensorflow官網的步驟,在修改自己環境問題,經過千辛萬苦終於跑出可執行的apk檔,現在就開始一步一步進行教學,希望之後使用的大家,也別踩到雷呀!! 執行的範例主要有以下三種: TF Classify: 物體分類 TF Stylize:   對相機預覽的影像進行圖像風格的變換 TF Detect:   偵測影像有人的位置,並劃出偵測框 引用: https://goo.gl/Wr2lKg 先前環境準備: 安裝android studio,並完成環境設置 https://developer.android.com/sx.html 下載NDK https://developer.android.com/ndk/downloads/older_releases.html#ndk-12b-downloads 下載tensprflow的官方文件 $ git clone https://github.com/tensorflow/tensorflow.git        並執行 $ cd tensorflow $ ./configure  下載bazel,mac 可以直接使用指令進行下載   $ brew install bazel 完成前置作業,開始修改要執行此專案需修改的程式部分修改<tensorflow_root>/WORKSPACE檔案, 將android_sdk_repository 和 android_ndk_repository 修改成自己電腦的環境 原始程式: # Uncomment and update the paths in these entries to build the Android demo. #android_sdk_repository( #    name = "androidsdk", #    api_level = 23, #    build_tools_version = "25.0.1", #    # Replace with path to Andro

[DL] Build simple model based on Tensorflow

圖片
本篇文章是從莫烦的學習影片學習的,主要是教學我們如何建置一個簡單的學習網絡。 以下的程式,主要是運用此方程式   y=Wx+b, 已知變數x,想利用兩個變數 W(weights),b(biases) 去算出我的們期望值y, 並另用SGD去降低loss值, 算出最能接近期望值y時的 W(weights)與b(biases) 以下程式: # coding=utf-8 import tensorflow as tf import numpy as np # creat data, random value between 0 and 1 x_data = np.random.rand(100).astype(np.float32) # define the learn value # to learn value: Weight:0.1  biases:0.3 # y_data= 真實值 y_data = x_data*0.1+0.3 ### creat tensorflow structure start ### # define the range and initial weights Weights = tf.Variable(tf.random_uniform([1],-1.0,1.0)) biases = tf.Variable(tf.zeros([1])) # 給定 tensorflow 學習的函數 # y = 預值測 y = Weights*x_data + biases # build loss  function loss = tf.reduce_mean(tf.square(y-y_data)) # select optimal methods to reduce loss and learning rate is always less than 1 # Define learning rate=0.5 optimizer = tf.train.GradientDescentOptimizer(0.5) #Optimal the loss value to small ,the best value is 0 train = optimizer.minimize(loss) #Initial all variabl