試玩~Xnor.ai@macos 的 samples(C、Python)

動機:若想在 macOSXnor.ai samples(CPython),要如何做呢?!(因為官網只提供 linux-x86_64 線上教學文件)

準備環境
1.macOS Mojave v.10.14.5
2.Python 3.7.3
3.clang-1001.0.46.4
4.GNU Make 3.81

實作步驟
1.先到官網(https://ai2go.xnor.ai/home)下載 xnor SDK壓縮檔(sdk_v1.0.0.zip),並 $ unzip 解壓縮
2.再到C samples目錄:/Users/account/xnor-sdk/samples/macos/c 中,執行 $ make
即可產生 build 子目錄及執行檔...
3.撰寫 bash script 執行其C samples,如下:
a) 0.model_benchmark.sh
./build/model_benchmark


結果如下圖

b) 1.object_detector.sh
cp ../../../lib/macos/person-pet-vehicle-detector/libxnornet.dylib ./build/

./build/object_detector

open ../../test-images/dog.jpg

結果如下圖

c) 2.classify_image.sh
cp ../../../lib/macos/facial-expression-classifier/libxnornet.dylib ./build/

./build/classify_image_file ../../test-images/happy.jpg

open ../../test-images/happy.jpg

結果如下圖

d) 3.detect_print_object.sh
cp ../../../lib/macos/person-pet-vehicle-detector/libxnornet.dylib ./build/

./build/detect_and_print_objects_in_image ../../test-images/dog.jpg

open ../../test-images/dog.jpg

結果如下圖

e) 4.segmentation_image.sh
cp ../../../lib/macos/person-segmenter/libxnornet.dylib ./build/

./build/segmentation_mask_of_image_file_to_file ../../test-images/person.jpg 

open ../../test-images/person.jpg
open ../../test-images/person.person.tga

結果如下圖

f) 5.json_dump_object.sh
cp ../../../lib/macos/person-pet-vehicle-detector/libxnornet.dylib ./build/

./build/json_dump_objects_in_image ../../test-images/dog.jpg

open ../../test-images/dog.jpg

結果如下圖

4.再到Python samples目錄:/Users/account/xnor-sdk/samples/macos/python 中,撰寫 bash script 執行其Python samples,如下:
a) 0.model_benchmark.sh
python3 model_benchmark.py

結果如下圖

b) 1.image_bounding.sh
python3 -m pip uninstall -y xnornet

python3 -m pip install  ../../../lib/macos/person-pet-vehicle-detector/xnornet-1.0-cp35-abi3-macosx_10_13_x86_64.whl

python3 static_image_bounding_box.py ../../test-images/vehicle.jpg

open static_image_bounding_box_output.png

結果如下圖

c) 2.sort_images.sh
python3 -m pip uninstall -y xnornet

python3 -m pip install  ../../../lib/macos/person-pet-vehicle-detector/xnornet-1.0-cp35-abi3-macosx_10_13_x86_64.whl

rm -fr test_image_output/

python3 sort_images_into_directories.py ../../test-images/ test_image_output/

tree test_image_output/


結果如下圖


心得
xnor.ai的執行速度不會輸給darknet(其CEO Ali Farhadi是華盛頓大學計算機系教授,真的很厲害!!),可見這二年他們想要將深度學習模型直接跑在樹莓派上是成功的。
本篇原是筆者為了要做demo而記錄,事後想一想,就是因為要demo才有動力去解開這些步驟,也算是箇小成就感吧!!


留言