Getting an IndexError from the tflite backend on Raspberry Pi
aidenmitchell opened this issue · 13 comments
Traceback (most recent call last):
File "/home/pi/Desktop/tester.py", line 6, in <module>
result = model.predict_from_file('/home/pi/Desktop/image.png')
File "/home/pi/.local/lib/python3.7/site-packages/lobe/ImageModel.py", line 43, in predict_from_file
return self.predict(image_utils.get_image_from_file(path))
File "/home/pi/.local/lib/python3.7/site-packages/lobe/ImageModel.py", line 47, in predict
return self.__backend.predict(image_processed)
File "/home/pi/.local/lib/python3.7/site-packages/lobe/backends/_backend_tflite.py", line 57, in predict
output_details[1]["index"]
IndexError: list index out of range
Here is my code:
from lobe import ImageModel
model = ImageModel.load('/home/pi/Lobe/model')
result = model.predict_from_file('/home/pi/Desktop/image.png')
print(result.prediction)
I can reproduce this on my raspberry pi3 as far back as commit: 22c16f5
My old .tflite models work at this commit but my newly created models (using the naming convention saved_model.tflite) do not work and throw this same IndexError. I am not sure what versions of the UI aligns up with these commits, so I'm not sure what version of the UI I'd have to revert to in order to get a working tflite model.
@adiazulay Any idea what's going on? Hoping we can get someone from Lobe to take a look.
I'm taking a look at this now and refactoring a bit how models are loaded and run. Should have a branch up later this evening that would be great to get some testing help.
Sorry for the delay, turned into a larger refactor than anticipated! Here is the PR, would love to get some help testing in your cases: #15
Sorry for so many edits (too much coffee this afternoon!)
Some issues I've run into so far:
- from lobe.Signature import Signature
gives me an error:
Traceback (most recent call last):
File "motion.py", line 9, in <module>
from tf_classify import TFClassify
File "/home/pi/src/BeeTracker/tf_classify.py", line 3, in <module>
from lobe.Signature import Signature
ModuleNotFoundError: No module named 'lobe.Signature'
I fixed this by changing my code to lower case: lobe.signature
- it doesn't like something with the way i'm using this model.predict_from_file
from lobe import ImageModel
model: ImageModel = ImageModel.load_from_signature(sig)
res = model.predict_from_file(item)
the item in this case is: img/PiZero_v1_2b762167-0c7b-42a4-9f6f-eab31ca35324.jpg
my main program doesn't give a helpful error, it just crashes at runtime, however, trying to duplicate this in a separate test
says:
Traceback (most recent call last):
File "imgmdltest.py", line 11, in
res = model.predict_from_file(item)
File "/home/pi/.local/lib/python3.7/site-packages/lobe/model/image_model.py", line 42, in predict_from_file
return self.predict(image_utils.get_image_from_file(path))
File "/home/pi/.local/lib/python3.7/site-packages/lobe/model/image_model.py", line 45, in predict
image_processed = image_utils.preprocess_image(image, self.signature.input_image_size)
AttributeError: 'Signature' object has no attribute 'input_image_size'
I don't think i've ever been supplying a size before.
Ah gotcha! Yep I made it a subclass system -- you will want to use ImageClassificationSignature from lobe.signature (this one has the input_image_size property vs the generic Signature class).
It should also just work if you use ImageModel.load('path/to/your/signature.json') instead of using the load_from_signature function now.
(.venv) C:\Users\Aiden Mitchell>pip install git+https://github.com/lobe/lobe-python@v0.3-cleanup-and-match-lobe-export
Collecting git+https://github.com/lobe/lobe-python@v0.3-cleanup-and-match-lobe-export
Cloning https://github.com/lobe/lobe-python (to revision v0.3-cleanup-and-match-lobe-export) to c:\users\aiden mitchell\appdata\local\temp\pip-req-build-gzt1j6n0
ERROR: Could not find a version that satisfies the requirement tensorflow<2,>=1.15 (from lobe)
ERROR: No matching distribution found for tensorflow<2,>=1.15
I got an error on Windows trying to install the new branch. I can try on a Linux machine instead.
Same error on Linux, Ubuntu 20.04.1.
Also of note, this step doesn't work (also noted in #13):
sudo apt install -y \
> libatlas-base-dev \
> libopenjp2-7 \
> libtiff5 \
> libjpeg62-turbo
[sudo] password for aiden:
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package libjpeg62-turbo is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package 'libjpeg62-turbo' has no installation candidate
libjpeg62-dev
works instead, according to this
@mbeissinger thanks!
changing this:
from lobe.signature import Signature
to this:
from lobe.signature import ImageClassificationSignature
and this:
sig:Signature = Signature(sigpath)
to this:
sig: ImageClassificationSignature = ImageClassificationSignature(sigpath)
restored everything to working order.
@aidenmitchell for the Tensorflow error, what version of Windows and Python are you running? I suspect it is a Python version issue -- have tested with 3.6 and 3.7, but 3.8 I believe only works in Tensorflow 2.x
@aidenmitchell I just updated the branch to use tensorflow 2.4, could you please try now?
Works like a charm! Tested it on Ubuntu 20.10 with Python 3.8.6.