Commit 368a1588 authored by freedom" Koan-Sin Tan's avatar freedom" Koan-Sin Tan Committed by Rasmus Munk Larsen
Browse files

Add a simple BMP decoder and enable it on Android (#9563)

* Add a simple bmp decoder

Add a bmp decoder and make sure that the decoder works with label_image.

tensorflow/python/kernel_tests/decode_bmp_op_test.py uses data from
Example 1 of Wikipedia BMP file format page [1].

tensorflow/core/lib/bmp/testdata/lena.bmp for
tensorflow/python/kernel_tests/decode_image_op_test.py is converted from
./tensorflow/core/lib/png/testdata/lena_rgba.png

[1] https://en.wikipedia.org/wiki/BMP_file_format#Example_1

* enable building label_image w/ bmp decoder for Android

(0) modifiy Andorid NDK entry in WORKSPACE
(1) build it
> bazel build -c opt \
  --cxxopt="-std=c++11" --cxxopt="-DTENSORFLOW_DISABLE_META"  \
  --crosstool_top=//external:android/crosstool \
  --cpu=arm64-v8a \
  --host_crosstool_top=@bazel_tools//tools/cpp:toolchain \
  tensorflow/examples/label_image/label_image

(2) push the binary to your Android device
> adb push bazel-bin/tensorflow/examples/label_image/label_image /data/local/tmp

(3) push model and other files to the device

(4) adb shell then 'cd /data/local/tmp/', then we can run 'label_image' like:

> ./label_image  --graph=inception_v3_2016_08_28_frozen.pb  --labels=imagenet_slim_labels.txt --image=grace_hopper.bmp

    And get results like:

native : main.cc:208 military uniform (653): 0.834119
native : main.cc:208 mortarboard (668): 0.0196274
native : main.cc:208 academic gown (401): 0.00946237
native : main.cc:208 pickelhaube (716): 0.00757228
native : main.cc:208 bulletproof vest (466): 0.0055856

* Small type fixes and style issues.

* Fixing syntax, check that channels is a valid number for now.

* Use internal::SubtleMustCopy on fields extracted from input tensor

* use channels_ extensively

use channels_ when calculating positions and support 4 channels

* PNG->BMP

* Change default channels of bmp decoder to 0

Change default channels of bmp decoder to 0 for consistency.
Fixed a typo in tensorflow/core/kernels/decode_bmp_op.cc

* Fixed BUILD files as suggested by buildifier

* Add test data for decode_image_op_test

Add test data dependency for tensorflow/python/kernel_tests:decode_image_op_test
and add tensorflow/python/kernel_tests:decode_bmp_op_test to test bmp.
parent 931fd84b
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment