2017년 8월 15일 화요일

fine-tuning with tensorflow

https://www.tensorflow.org/tutorials/image_retraining

찬찬히 잘 따라 하면 된다.

1. 꽃이미지 받고
    curl -O http://download.tensorflow.org/example_images/flower_photos.tgz
    tar xzf flower_photos.tgz
2. bazel build tensorflow/examples/image_retraining:retrain
  q: python -> c++ build & run ?
3. bazel-bin/tensorflow/examples/image_retraining/retrain --image_dir=flower_photos
 ... time is money
 ... 완료 & 테스트
4. bazel-bin/tensorflow/examples/label_image:label_image --graph=/tmp/output_graph.pb \
--labels=/tmp/output_labels.txt \
--output__layer=final_result \
--input_layer=Mul \
--image=$HOME/flower_photo/daisy/xxx.jpg


./bazel-bin/tensorflow/examples/label_image/label_image --graph=/tmp/output_graph.pb --labels=/tmp/output_labels.txt --output_layer=final_result --input_layer=Mul --image=/Users/bcc/flower_photos/daisy/21652746_cc379e0eea_m.jpg

2017년 8월 14일 월요일

TensorFlow Android Camera Demo(bazel version)

https://github.com/tensorflow/tensorflow/tree/master/tensorflow/examples/android

간단히 하려면

build.gradle에서 nativebuildsystem = 'none'로 설정하면

jcenter에서

compile 'org.tensorflow.tensorflow-android:+' 다운로드 하여 실행 한다. 

bazel로 하려면

tensorflow source를 다운 받고

WORKSPACE 파일의 주석을 제거 하고

android-stduio로 tensorflow/example/android를 import하고 

project에서 local.properties에 ndk.dir를 설정한다. 

빌드 하면 된다. 

참고:
온라인 문서에 나와 있는 bazel로 android 빌드 하는 방법은 tensorflow_demo로 시작 했지만 
build.gradle에서는 tensorflow_native_libs로 시작해서 libtensorflow_demo.so, libtensorflow_inference.so를 빌드하는 순서로 된다. 


bazel build -c opt tensorflow/examples/android:tensorflow_demo
adb install -r bazel-bin/tensorflow/examples/android/tensorflow_demo.apk 
이렇게 해도 되지만( 난 에러나서 안했음.)
build.gradle를 사용해서 하는 편이 더 좋은것 같다. 

결론은  build.gradle로 bazel로 사용하려면 WORKSPACE 파일 주석삭제후 bazel system에 알려주면 빌드 된다. 

참고:

build.gradle에  
apply from: "download-models.gradle"은 assets에 4개의 pb파일과 3개의 checkpoints파일이 생성 된다. 





2017년 8월 4일 금요일

Tensorflow-serving Docker image

https://tensorflow.github.io/serving/
->
https://tensorflow.github.io/serving/docker
->
https://tensorflow.github.io/serving/serving_basic

Download Dockerfile.devel
docker build --pull -t zaxrok/tensorflow-serving-devel -f Dockerfile.devel .
docker run -it zaxrok/tensorflow-serving-devel

git clone --recurse-submodules https://github.com/tensorflow/serving
cd serving/tensorflow
./configure
cd ..
bazel test tensorflow_serving/...
.. error


bazel build -c opt --jobs 1 --local_resources 2048,0.5,1.0 --verbose_failures tensorflow_serving/...

INFO: Elapsed time: 11026.956s, Critical Path: 41.09s
많은 시간이 걸리니 어디 갔다 오시길


bazel build -c opt //tensorflow_serving/example:mnist_saved_model

bazel-bin/tensorflow_serving/example/mnist_saved_model /tmp/mnist_model

Exporting trained model to /tmp/mnist_model/1
Done exporting!