label-studio-ml-backend icon indicating copy to clipboard operation
label-studio-ml-backend copied to clipboard

segment_anything_model reproduction error

Open rookiez7 opened this issue 1 year ago • 15 comments

  1. after I follow segment_anything_model readme,I run python _wsgi.py -p 4243,get this
Traceback (most recent call last):
  File "/data/zqh/project/label-studio-ml-backend/label_studio_ml/examples/segment_anything_model/_wsgi.py", line 107, in <module>
    app = init_app(
          ^^^^^^^^^
TypeError: init_app() got an unexpected keyword argument 'model_dir'
  1. then,i found init_app() define in api.py ,only model_class parameter,so i commented function init_app() 's parameters except for the model_class,then,code run sucess,but when i add model in Machine Larening,
    app = init_app(
        model_class=MyModel,
        # model_dir=os.environ.get('MODEL_DIR', args.model_dir),
        # redis_queue=os.environ.get('RQ_QUEUE_NAME', 'default'),
        # redis_host=os.environ.get('REDIS_HOST', 'localhost'),
        # redis_port=os.environ.get('REDIS_PORT', 6379),
        # **kwargs
    )

I get this

[2023-08-08 08:21:50,050] [INFO] [werkzeug::_log::187] 127.0.0.1 - - [08/Aug/2023 08:21:50] "GET /health HTTP/1.1" 200 -
[2023-08-08 08:21:50,069] [ERROR] [label_studio_ml.exceptions::exception_f::53] Traceback (most recent call last):
  File "/data/zqh/project/label-studio-ml-backend/label_studio_ml/exceptions.py", line 39, in exception_f
    return f(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^
  File "/data/zqh/project/label-studio-ml-backend/label_studio_ml/api.py", line 73, in _setup
    model = MODEL_CLASS(project_id, cache)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: MyModel.__init__() takes 1 positional argument but 3 were given
  1. Then,I solved the problem by turning model = MODEL_CLASS(project_id, cache) into model = MODEL_CLASS(project_id=project_id, cache=cache)

4.next,i run code,I get

Traceback (most recent call last):
  File "/data/zqh/project/label-studio-ml-backend/label_studio_ml/exceptions.py", line 39, in exception_f
    return f(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^
  File "/data/zqh/project/label-studio-ml-backend/label_studio_ml/api.py", line 73, in _setup
    model = MODEL_CLASS(project_id=project_id, cache=cache)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/zqh/project/label-studio-ml-backend/label_studio_ml/examples/segment_anything_model/segment_anything_model.py", line 54, in __init__
    from_name, schema = list(self.parsed_label_config.items())[0]
                             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/zqh/project/label-studio-ml-backend/label_studio_ml/model.py", line 58, in parsed_label_config
    return json.loads(self.get('parsed_label_config'))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/anaconda3/envs/label-studio-ml/lib/python3.11/json/__init__.py", line 339, in loads
    raise TypeError(f'the JSON object must be str, bytes or bytearray, '
TypeError: the JSON object must be str, bytes or bytearray, not NoneType
[2023-08-08 09:01:40,045] [INFO] [werkzeug::_log::187] 127.0.0.1 - - [08/Aug/2023 09:01:40] "POST /setup HTTP/1.1" 500 -

the error code is below

    def parsed_label_config(self):
        return json.loads(self.get('parsed_label_config'))

rookiez7 avatar Aug 08 '23 02:08 rookiez7

struggling with this right now too

samhoff20 avatar Aug 08 '23 02:08 samhoff20

I think it is because of the last commit. It changed init_app() function image

I changed call function same as you then I got this message. I think changing the URL parameter from localhost to ip then it will work. But I got this... image

hoohahaBIGHEAD avatar Aug 08 '23 06:08 hoohahaBIGHEAD

@hoohahaBIGHEAD I feel like this problem caused by the mismatch between label-studio and label-studio-ml-backend, and I hope the official can help us answer this question,I have been tortured by this problem for several days.

rookiez7 avatar Aug 08 '23 07:08 rookiez7

@rookiez7 I reverted commit to 3a9486c4f5084820b83811f5b3996fc63e331f5a then SAM ml-backend running but

  File "/label-studio-ml-backend/label_studio_ml/exceptions.py", line 39, in exception_f
    return f(*args, **kwargs)
  File "/label-studio-ml-backend/label_studio_ml/api.py", line 47, in _predict
    predictions, model = _manager.predict(tasks,  **params)
  File "/label-studio-ml-backend/label_studio_ml/model.py", line 567, in predict
    predictions = cls._current_model.model.predict(tasks, **kwargs)
  File "/label-studio-ml-backend/label_studio_ml/examples/segment_anything_model/segment_anything_model.py", line 69, in predict
    height = kwargs['context']['result'][0]['original_height']
TypeError: 'NoneType' object is not subscriptable

[2023-08-08 16:36:45,011] [INFO] [werkzeug::_log::187] 172.17.0.2 - - [08/Aug/2023 16:36:45] "POST /predict HTTP/1.1" 500 -

happened. PLEASE HELP!!!

hoohahaBIGHEAD avatar Aug 08 '23 07:08 hoohahaBIGHEAD

@hoohahaBIGHEAD In my updated comment,I solved the problem you mentiond,but then I get new problem..... I found out the result None is come from sqlite.

rookiez7 avatar Aug 08 '23 09:08 rookiez7

@rookiez7 Did you check the place where the images are? In the first instruction, they say place the image folders to the same directory and after I did, that error not happened. But in my case, I used docker but because of the volume path mismatch, now I use pip then another error happened. Please check the image directory and share me thank you.

hoohahaBIGHEAD avatar Aug 08 '23 09:08 hoohahaBIGHEAD

The TypeError: 'NoneType' object is not subscriptable error is not fatal.

hogepodge avatar Aug 09 '23 05:08 hogepodge

We are working on updated instructions on how to setup and run SAM. It's going to take a bit of time but it's possible to get it all working.

hogepodge avatar Aug 09 '23 05:08 hogepodge

The TypeError: 'NoneType' object is not subscriptable error is not fatal.

becaues this error,I cant sucess run the backend.I found this error because I need to read the auto-generated cache.db database that is automatically generated under the current folder, but this database is empty. cache table:

project_id key value
N/A N/A N/A

rookiez7 avatar Aug 09 '23 06:08 rookiez7

@rookiez7 Did you check the place where the images are? In the first instruction, they say place the image folders to the same directory and after I did, that error not happened. But in my case, I used docker but because of the volume path mismatch, now I use pip then another error happened. Please check the image directory and share me thank you.

I just upload images,I don't know if this matters

rookiez7 avatar Aug 09 '23 07:08 rookiez7

Was anyone able to make any progress on this?

samhoff20 avatar Aug 10 '23 15:08 samhoff20

Have you had an opportunity to review the new installation video that was merged into the project this week? The updates also include a number of improvements.

I'm also working on a patch that adds storage connection options that should help.

https://github.com/HumanSignal/label-studio-ml-backend/tree/master/label_studio_ml/examples/segment_anything_model#creating-the-annotation

hogepodge avatar Aug 10 '23 23:08 hogepodge

@hogepodge I tried new directions but I got this. Please check below error and requirements.

Traceback (most recent call last):
  File ".../labeling_tool/.venv/lib/python3.9/site-packages/label_studio_ml/exceptions.py", line 39, in exception_f
    return f(*args, **kwargs)
  File ".../labeling_tool/.venv/lib/python3.9/site-packages/label_studio_ml/api.py", line 70, in _setup
    model = _manager.fetch(project, schema, force_reload,
  File ".../labeling_tool/.venv/lib/python3.9/site-packages/label_studio_ml/model.py", line 537, in fetch
    model = cls.model_class(label_config=label_config, **kwargs)
  File ".../labeling_tool/label-studio-ml-backend/label_studio_ml/examples/segment_anything_model/advanced_sam.py", line 49, in __init__
    from_name, schema = list(self.parsed_label_config.items())[0]
IndexError: list index out of range

[2023-08-11 14:44:58,784] [INFO] [werkzeug::_log::225] 192.168.0.21 - - [11/Aug/2023 14:44:58] "POST /setup HTTP/1.1" 500 -

.../labeling_tool dir is for test dir. I changed several requirements.txt because of the conflicts of label-studio's requirements such as label-studio-converter==0.0.54rc0. But in this repo's requirements, label-studio-converter==0.0.50. I've reinstalled both segment-anything and label-studio to match your direction, but it's not working, please help.

hoohahaBIGHEAD avatar Aug 11 '23 05:08 hoohahaBIGHEAD

Have you had an opportunity to review the new installation video that was merged into the project this week? The updates also include a number of improvements.

I'm also working on a patch that adds storage connection options that should help.

https://github.com/HumanSignal/label-studio-ml-backend/tree/master/label_studio_ml/examples/segment_anything_model#creating-the-annotation

I just did and was able to get it running, thanks!

@hoohahaBIGHEAD did you copy and paste the labeling code into the the 'code' section of the labeling interface tab?

samhoff20 avatar Aug 11 '23 05:08 samhoff20

@samhoff20 Solved!!! It was because the labels were not set in the UI interface that they were not imported. Thank you!!!

hoohahaBIGHEAD avatar Aug 11 '23 06:08 hoohahaBIGHEAD