ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
kopyl opened this issue · 2 comments
Got this error:
Traceback (most recent call last):
File "/Users/oleoyl/Dropbox/Development/Clients/K/Projects/classifier/yolov8/onnx-inference-yolo-main/inference_script.py", line 37, in <module>
batch.init_detected_objects(raw_out)
File "/Users/oleoyl/Dropbox/Development/Clients/K/Projects/classifier/yolov8/onnx-inference-yolo-main/data_models/images_input.py", line 175, in init_detected_objects
predictions_for_batch_id = [i for i in predictions if i[0] == batch_id]
File "/Users/oleoyl/Dropbox/Development/Clients/K/Projects/classifier/yolov8/onnx-inference-yolo-main/data_models/images_input.py", line 175, in <listcomp>
predictions_for_batch_id = [i for i in predictions if i[0] == batch_id]
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
How can I fix it?
seems like your i[0] in this case is contains more than one element which is not comparable to batch_id which is an integer. You could try to figure out what your predictions array looks like and check if the first element of each row of the predictions is indeed an integer which is supposed to be the batch id.
Could you also let me know what kind of model you are using?
@kopyl I have the same error for certain neural network weights. The output of inference, prediction array ("raw_out" variable), with batch size as 1, for example:
(1, 6300, 88) induced the error
(5, 7) passed batch_init_deteced_objects(raw_out)
The first case, I generated the ONNX file using python scripts/qat.py export qat.pt --size=640 --save=qat.onnx --dynamic
(ref). This is neural network weight quantization involved.
The second case, I used python export.py --weights yolov7-tiny.pt --grid --end2end --simplify --topk-all 100 --iou-thres 0.65 --conf-thres 0.35 --img-size 640 640 --max-wh 640
(ref).
As reference, I used Yolo Version 7.