Fix TF Lite import to use recommended 'tf' symbols instead of deep imports

PiperOrigin-RevId: 274190027
This commit is contained in:
Scott Main 2019-10-11 09:42:02 -07:00 committed by TensorFlower Gardener
parent d1a1b7f4cb
commit e9b998ec50
3 changed files with 18 additions and 6 deletions

View File

@ -10,6 +10,6 @@ py_binary(
python_version = "PY3",
srcs_version = "PY2AND3",
deps = [
"//tensorflow/lite/python:lite",
"//tensorflow:tensorflow_py",
],
)

View File

@ -23,7 +23,7 @@ import numpy as np
from PIL import Image
from tensorflow.lite.python.interpreter import Interpreter
import tensorflow as tf # TF2
def load_labels(filename):
@ -58,7 +58,7 @@ if __name__ == '__main__':
help='input standard deviation')
args = parser.parse_args()
interpreter = Interpreter(model_path=args.model_file)
interpreter = tf.lite.Interpreter(model_path=args.model_file)
interpreter.allocate_tensors()
input_details = interpreter.get_input_details()

View File

@ -78,16 +78,28 @@ For example, after you install the package above, copy and run the
[`label_image.py`](
https://github.com/tensorflow/tensorflow/tree/master/tensorflow/lite/examples/python/)
file. It will (probably) fail because you don't have the `tensorflow` library
installed. To fix it, simply edit this line of the file:
installed. To fix it, edit this line of the file:
```python
from tensorflow.lite.python.interpreter import Interpreter
import tensorflow as tf
```
So it instead reads:
```python
from tflite_runtime.interpreter import Interpreter
import tflite_runtime.interpreter as tflite
```
And then change this line:
```python
interpreter = tf.lite.Interpreter(model_path=args.model_file)
```
So it reads:
```python
interpreter = tflite.Interpreter(model_path=args.model_file)
```
Now run `label_image.py` again. That's it! You're now executing TensorFlow Lite