google-coral / project-bodypix

BodyPix model demo application for Google Coral
Apache License 2.0
275 stars 52 forks source link

IndexError: index 0 is out of bounds for axis 0 with size 0 #25

Closed 3344393853 closed 3 years ago

3344393853 commented 3 years ago

raspi4B + ubuntu Mate20.04 + Coral USB Accelerator + python3.8:

aaa@aaa:~/work/project-bodypix$ python3 bodypix.py Model: models/bodypix_mobilenet_v1_075_640_480_16_quant_decoder_edgetpu.tflite Traceback (most recent call last): File "bodypix.py", line 180, in main() File "bodypix.py", line 161, in main engine = PoseEngine(model) File "/home/aaa/work/project-bodypix/pose_engine.py", line 162, in init self.heatmap_zero_point = details['quantization_parameters']['zero_points'][0] IndexError: index 0 is out of bounds for axis 0 with size 0

hjonnala commented 3 years ago

Hello, for a workaround can you try commenting these line pose_engine.py

lines 162, 163: self.heatmap_zero_point = details['quantization_parameters']['zero_points'][0] self.heatmap_scale = details['quantization_parameters']['scales'][0]

3344393853 commented 3 years ago

Hello, for a workaround can you try commenting these line pose_engine.py

lines 162, 163: self.heatmap_zero_point = details['quantization_parameters']['zero_points'][0] self.heatmap_scale = details['quantization_parameters']['scales'][0]

Hi hjonnala,thank you very much for your answers, after I commented out those two lines of code, a new error appeared: AttributeError: 'PoseEngine' object has no attribute 'heatmap_zero_point'

hjonnala commented 3 years ago

Sorry, I have tested with commenting out execute python3 bodypix.py.. I haven't got any errors.

The original error because details dictionary keys have empty arrays. And the code trying access first element in it. please refer to section above Heatmap size: (641, 481) in screenshot.

to debug further Can you please add

  1. print(details) above self.heatmap_zero_point = details['quantization_parameters']['zero_points'][0] line
  2. please share the command you are trying to run and the error Screenshot from 2021-07-09 05-28-15
3344393853 commented 3 years ago

After commenting out those two lines of code: aaa@aaa:~/work/project-bodypix$ python3 bodypix.py Model: models/bodypix_mobilenet_v1_075_640_480_16_quant_decoder_edgetpu.tflite {'name': 'poses:4', 'index': 11, 'shape': array([ 1, 20, 33, 33], dtype=int32), 'shape_signature': array([ 1, 20, 33, 33], dtype=int32), 'dtype': <class 'numpy.float32'>, 'quantization': (0.0, 0), 'quantization_parameters': {'scales': array([], dtype=float32), 'zero_points': array([], dtype=int32), 'quantized_dimension': 0}, 'sparsity_parameters': {}} Heatmap size: (641, 481) Stride: 1 (641, 481) Inference size: (640, 480) Source size: (640, 480) Gstreamer pipeline: v4l2src device=/dev/video0 ! video/x-raw,width=640,height=480,framerate=30/1 ! queue max-size-buffers=1 leaky=downstream ! decodebin ! videoflip video-direction=identity ! videoconvert ! videoscale ! video/x-raw,width=640,height=480 ! videobox name=box autocrop=true ! video/x-raw,format=RGB,width=640,height=480 ! queue max-size-buffers=1 leaky=downstream ! appsink name=appsink sync=false emit-signals=true max-buffers=1 drop=true Gstreamer appsrc pipeline: appsrc name=appsrc ! video/x-raw,format=RGB,width=640,height=480,framerate=30/1 ! queue max-size-buffers=1 leaky=downstream ! videoconvert ! rsvgoverlay name=overlay ! videoconvert ! autovideosink Traceback (most recent call last): File "/home/aaa/work/project-bodypix/gstreamer.py", line 53, in on_new_sample appsrc_image = user_function(img, svg_canvas) File "bodypix.py", line 69, in call inference_time, poses, heatmap, bodyparts = self.engine.DetectPosesInImage(image) File "/home/aaa/work/project-bodypix/pose_engine.py", line 198, in DetectPosesInImage heatmap, bodyparts = self._parse_heatmaps(outputs) File "/home/aaa/work/project-bodypix/pose_engine.py", line 239, in _parse_heatmaps heatmap = (outputs[4].astype(np.float32) - self.heatmap_zero_point) self.heatmap_scale AttributeError: 'PoseEngine' object has no attribute 'heatmap_zero_point' Traceback (most recent call last): File "/home/aaa/work/project-bodypix/gstreamer.py", line 53, in on_new_sample appsrc_image = user_function(img, svg_canvas) File "bodypix.py", line 69, in call inference_time, poses, heatmap, bodyparts = self.engine.DetectPosesInImage(image) File "/home/aaa/work/project-bodypix/pose_engine.py", line 198, in DetectPosesInImage heatmap, bodyparts = self._parse_heatmaps(outputs) File "/home/aaa/work/project-bodypix/pose_engine.py", line 239, in _parse_heatmaps heatmap = (outputs[4].astype(np.float32) - self.heatmap_zero_point) self.heatmap_scale AttributeError: 'PoseEngine' object has no attribute 'heatmap_zero_point' Traceback (most recent call last): File "/home/aaa/work/project-bodypix/gstreamer.py", line 53, in on_new_sample appsrc_image = user_function(img, svg_canvas) File "bodypix.py", line 69, in call inference_time, poses, heatmap, bodyparts = self.engine.DetectPosesInImage(image) File "/home/aaa/work/project-bodypix/pose_engine.py", line 198, in DetectPosesInImage heatmap, bodyparts = self._parse_heatmaps(outputs) File "/home/aaa/work/project-bodypix/pose_engine.py", line 239, in _parse_heatmaps heatmap = (outputs[4].astype(np.float32) - self.heatmap_zero_point) * self.heatmap_scale AttributeError: 'PoseEngine' object has no attribute 'heatmap_zero_point' ... ...

jonhaun commented 3 years ago

Hi, I’m experiencing the same error.

I’m running

I get the following output when with “print(details)” added in front of the error line. FDA2D8CF-3FD8-471B-886F-8BF30258D340

I don’t know enough about how these variables are used to put in error handling myself. I get the same errors when running the non-“gl_mx” version.

yishinhung commented 3 years ago

Hi @hjonnala @jonhaun and @3344393853 : I revert the following patch and then the application run normally. Maybe the fail is related with model files. Thank a lot!

Add CPU versions, update filenames.

hjonnala commented 3 years ago

This issue got fixed with PR