wkentaro / labelme

Image Polygonal Annotation with Python (polygon, rectangle, circle, line, point and image-level flag annotation).
https://labelme.io
Other
13.63k stars 3.42k forks source link

Crash on clicking "Create AI-polygons" #1334

Open Erotemic opened 1 year ago

Erotemic commented 1 year ago

Provide environment information

(pyenv3.11.2) joncrall@toothbrush:~$ which python; python --version; python -m pip list | grep labelme
/home/joncrall/.pyenv/versions/3.11.2/envs/pyenv3.11.2/bin/python
Python 3.11.2
labelme                             5.3.1
python -c "import onnxruntime; print('onnxruntime.__version__ = ' + str(onnxruntime.__version__))"
onnxruntime.__version__ = 1.16.0

What OS are you using?

Ubuntu 22.04

Describe the Bug

I'm getting a core dump when I click "Create AI-Polygons":

[INFO   ] __init__:get_config:70 - Loading config file from: /home/joncrall/.labelmerc
Computing MD5: /home/joncrall/.cache/gdown/https-COLON--SLASH--SLASH-github.com-SLASH-wkentaro-SLASH-labelme-SLASH-releases-SLASH-download-SLASH-sam-20230416-SLASH-sam_vit_l_0b3195.quantized.encoder.onnx
MD5 matches: /home/joncrall/.cache/gdown/https-COLON--SLASH--SLASH-github.com-SLASH-wkentaro-SLASH-labelme-SLASH-releases-SLASH-download-SLASH-sam-20230416-SLASH-sam_vit_l_0b3195.quantized.encoder.onnx
Computing MD5: /home/joncrall/.cache/gdown/https-COLON--SLASH--SLASH-github.com-SLASH-wkentaro-SLASH-labelme-SLASH-releases-SLASH-download-SLASH-sam-20230416-SLASH-sam_vit_l_0b3195.quantized.decoder.onnx
MD5 matches: /home/joncrall/.cache/gdown/https-COLON--SLASH--SLASH-github.com-SLASH-wkentaro-SLASH-labelme-SLASH-releases-SLASH-download-SLASH-sam-20230416-SLASH-sam_vit_l_0b3195.quantized.decoder.onnx
Traceback (most recent call last):
  File "/home/joncrall/.pyenv/versions/3.11.2/envs/pyenv3.11.2/lib/python3.11/site-packages/labelme/app.py", line 373, in <lambda>
    lambda: self.toggleDrawMode(False, createMode="ai_polygon"),
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/joncrall/.pyenv/versions/3.11.2/envs/pyenv3.11.2/lib/python3.11/site-packages/labelme/app.py", line 1071, in toggleDrawMode
    self.canvas.initializeAiModel(
  File "/home/joncrall/.pyenv/versions/3.11.2/envs/pyenv3.11.2/lib/python3.11/site-packages/labelme/widgets/canvas.py", line 141, in initializeAiModel
    self._ai_model = labelme.ai.SegmentAnythingModel(
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/joncrall/.pyenv/versions/3.11.2/envs/pyenv3.11.2/lib/python3.11/site-packages/labelme/ai/models/segment_anything.py", line 19, in __init__
    self._encoder_session = onnxruntime.InferenceSession(encoder_path)
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/joncrall/.pyenv/versions/3.11.2/envs/pyenv3.11.2/lib/python3.11/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 432, in __init__
    raise e
  File "/home/joncrall/.pyenv/versions/3.11.2/envs/pyenv3.11.2/lib/python3.11/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 419, in __init__
    self._create_inference_session(providers, provider_options, disabled_optimizers)
  File "/home/joncrall/.pyenv/versions/3.11.2/envs/pyenv3.11.2/lib/python3.11/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 451, in _create_inference_session
    raise ValueError(
ValueError: This ORT build has ['AzureExecutionProvider', 'CPUExecutionProvider'] enabled. Since ORT 1.9, you are required to explicitly set the providers parameter when instantiating InferenceSession. For example, onnxruntime.InferenceSession(..., providers=['AzureExecutionProvider', 'CPUExecutionProvider'], ...)
Aborted (core dumped)

It seemed to download the data just fine.

Expected Behavior

not crashing?

To Reproduce

I just did a pip install labelme and did labelme . on a directory of images. Not sure what's causing the issue.

Erotemic commented 1 year ago

I was able to fix this by adding:

        self._encoder_session = onnxruntime.InferenceSession(encoder_path, providers=['AzureExecutionProvider', 'CPUExecutionProvider'])
        self._decoder_session = onnxruntime.InferenceSession(decoder_path, providers=['AzureExecutionProvider', 'CPUExecutionProvider'])

on lines 19/20 in labelme/ai/models/segment_anything.py