canonical / tf-lite-examples-snap

Snap packaging of TensorFlow Lite examples for Raspberry Pi
Apache License 2.0
0 stars 0 forks source link

Error on `video-classification`: ValueError: Model provided has model identifier '<!DO', should be 'TFL3' #3

Open locnnil opened 6 days ago

locnnil commented 6 days ago

On RPi4, running noble:

pi4@buri:~$ tf-lite-examples.video-classification 
Traceback (most recent call last):
  File "/snap/tf-lite-examples/x1/tflite/video_classification/classify.py", line 172, in <module>
    main()
  File "/snap/tf-lite-examples/x1/tflite/video_classification/classify.py", line 167, in main
    run(args.model, args.label, int(args.maxResults), int(args.numThreads),
  File "/snap/tf-lite-examples/x1/tflite/video_classification/classify.py", line 51, in run
    classifier = VideoClassifier(model, label, options)
  File "/snap/tf-lite-examples/x1/tflite/video_classification/video_classifier.py", line 82, in __init__
    interpreter = Interpreter(
  File "/snap/tf-lite-examples/x1/lib/python3.8/site-packages/tflite_runtime/interpreter.py", line 464, in __init__
    self._interpreter = _interpreter_wrapper.CreateWrapperFromFile(
ValueError: Model provided has model identifier '<!DO', should be 'TFL3'

Not sure if related, but when running with root privileges, it gets the same error with the AppArmor denial:

= AppArmor =
Time: Jun 28 15:14:21
Log: apparmor="DENIED" operation="capable" class="cap" profile="snap.tf-lite-examples.video-classification" pid=5529 comm="cd-to-snap.sh" capability=2  capname="dac_read_search"
Capability: dac_read_search
Suggestions:
* adjust program to not require 'CAP_DAC_READ_SEARCH' (see 'man 7 capabilities')
* add one of 'microstack-support, system-backup' to 'plugs'
* do nothing if program otherwise works properly

Additional info:

pi4@buri:~$ cat /proc/device-tree/model 
Raspberry Pi 4 Model B Rev 1.5
pi4@buri:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 24.04 LTS
Release:    24.04
Codename:   noble
jpm-canonical commented 6 days ago

This is a known issue. If you look carefully at the error line: '<!DO', should be 'TFL3' That <!DO looks familiar. Almost like an html page.

When the snap is built, the models are downloaded from various sources. Some of those sources are Google, but in the video classification case it is tfhub.dev: https://github.com/tensorflow/examples/blob/master/lite/examples/video_classification/raspberry_pi/setup.sh#L17C17-L17C26

At the time of building the snap this server responded with the error page that got stored in the model file in the snap.

I think we have two options:

In both cases this will mean changing the upstream setup file which we currently rely on to download the dependencies.

farshidtz commented 4 days ago

I suggest keeping this simple and making the build fails when the model isn't fetched correctly, perhaps via a checksum verification.