1# TensorFlow Lite Python image classification demo 2 3This `label_image.py` script shows how you can load a pre-trained and converted 4TensorFlow Lite model and use it to recognize objects in images. The Python 5script accepts arguments specifying the model to use, the corresponding labels 6file, and the image to process. 7 8**Tip:** If you're using a Raspberry Pi, instead try the 9[classify_picamera.py example](https://github.com/tensorflow/examples/tree/master/lite/examples/image_classification/raspberry_pi). 10 11Before you begin, make sure you 12[have TensorFlow installed](https://www.tensorflow.org/install). 13 14## Download sample model and image 15 16You can use any compatible model, but the following MobileNet v1 model offers a 17good demonstration of a model trained to recognize 1,000 different objects. 18 19```sh 20# Get photo 21curl https://raw.githubusercontent.com/tensorflow/tensorflow/master/tensorflow/lite/examples/label_image/testdata/grace_hopper.bmp > /tmp/grace_hopper.bmp 22# Get model 23curl https://storage.googleapis.com/download.tensorflow.org/models/mobilenet_v1_2018_02_22/mobilenet_v1_1.0_224.tgz | tar xzv -C /tmp 24# Get labels 25curl https://storage.googleapis.com/download.tensorflow.org/models/mobilenet_v1_1.0_224_frozen.tgz | tar xzv -C /tmp mobilenet_v1_1.0_224/labels.txt 26 27mv /tmp/mobilenet_v1_1.0_224/labels.txt /tmp/ 28``` 29 30## Run the sample 31 32```sh 33python3 label_image.py \ 34 --model_file /tmp/mobilenet_v1_1.0_224.tflite \ 35 --label_file /tmp/labels.txt \ 36 --image /tmp/grace_hopper.bmp 37``` 38 39You should see results like this: 40 41``` 420.728693: military uniform 430.116163: Windsor tie 440.035517: bow tie 450.014874: mortarboard 460.011758: bolo tie 47``` 48