HumanSignal/label-studio-ml-backend

FileNotFoundError: SAM seems to be trying to interpret local file as a url? (Segment Anything integration)

BadCoder2 opened this issue · 5 comments

I started my Label Studio container with:

docker run -it -p 8080:8080 -v /mydata:/label-studio/data --env LABEL_STUDIO_LOCAL_FILES_SERVING_ENABLED=true --env LABEL_STUDIO_LOCAL_FILES_DOCUMENT_ROOT=/label-studio/data/images heartexlabs/label-studio

And I started Segment Anything with the following docker-compose.yml (with the access token added):

version: "3.8"

services:
  segment_anything_model:
    container_name: segment_anything_model
    image: heartexlabs/label-studio-ml-backend:sam-master
    build:
      context: .
      shm_size: '4gb'
      args:
        TEST_ENV: ${TEST_ENV}
    deploy:
      resources:
        limits:
            memory: 8G
        reservations:
            memory: 4G
# Add this to pass through 1 GPU 
            devices:
              - driver: nvidia
                count: 1
                capabilities: [gpu]
    environment:
      # specify these parameters if you want to use basic auth for the model server
      - BASIC_AUTH_USER=
      - BASIC_AUTH_PASS=
      # Change this to your model name: MobileSAM or SAM
      - SAM_CHOICE=MobileSAM
      - LOG_LEVEL=DEBUG
      # Enable this to use the GPU
      # - NVIDIA_VISIBLE_DEVICES=all
      # specify the number of workers and threads for the model server
      - WORKERS=1
      - THREADS=8
      # specify the model directory (likely you don't need to change this)
      - MODEL_DIR=/data/models

      # Specify the Label Studio URL and API key to access
      # uploaded, local storage and cloud storage files.
      # Do not use 'localhost' as it does not work within Docker containers.
      # Use prefix 'http://' or 'https://' for the URL always.
      # Determine the actual IP using 'ifconfig' (Linux/Mac) or 'ipconfig' (Windows).
      - LABEL_STUDIO_HOST=http://192.168.86.40:8080
      - LABEL_STUDIO_ACCESS_TOKEN=***REMOVED***

    ports:
      - 9090:9090
    volumes:
      - "./data/server:/data"
    environment:
      - NVIDIA_VISIBLE_DEVICES=all

Which I then ran with a command prompt, in that directory, with the command of docker compose up --build.
Everything runs fine with no errors - the model registers and validates fine - but when I go to actually try to do a prediction, the following happens in the SAM docker container and I get no prediction back:

segment_anything_model  | Point coords are [[2040, 1356]], point labels are [1], input box is None
segment_anything_model  | [2024-06-02 12:18:30,316] [ERROR] [label_studio_ml.exceptions::exception_f::53] Traceback (most recent call last):
segment_anything_model  |   File "/usr/local/lib/python3.8/site-packages/label_studio_ml/exceptions.py", line 39, in exception_f
segment_anything_model  |     return f(*args, **kwargs)
segment_anything_model  |   File "/usr/local/lib/python3.8/site-packages/label_studio_ml/api.py", line 69, in _predict
segment_anything_model  |     response = model.predict(tasks, context=context, **params)
segment_anything_model  |   File "/app/model.py", line 51, in predict
segment_anything_model  |     predictor_results = PREDICTOR.predict(
segment_anything_model  |   File "/app/sam_predictor.py", line 202, in predict
segment_anything_model  |     return self.predict_sam(img_path, point_coords, point_labels, input_box, task)
segment_anything_model  |   File "/app/sam_predictor.py", line 173, in predict_sam
segment_anything_model  |     self.set_image(img_path, calculate_embeddings=False, task=task)
segment_anything_model  |   File "/app/sam_predictor.py", line 86, in set_image
segment_anything_model  |     image_path = get_local_path(
segment_anything_model  |   File "/usr/local/lib/python3.8/site-packages/label_studio_tools/core/utils/io.py", line 121, in get_local_path
segment_anything_model  |     raise FileNotFoundError(
segment_anything_model  | FileNotFoundError: Can't resolve url, neither hostname or project_dir passed: /data/upload/1/80cf6086-1LookingAwayOrig.JPG. You can set LABEL_STUDIO_URL environment variable to use it as a hostname.
segment_anything_model  |
segment_anything_model  | Traceback (most recent call last):
segment_anything_model  |   File "/usr/local/lib/python3.8/site-packages/label_studio_ml/exceptions.py", line 39, in exception_f
segment_anything_model  |     return f(*args, **kwargs)
segment_anything_model  |   File "/usr/local/lib/python3.8/site-packages/label_studio_ml/api.py", line 69, in _predict
segment_anything_model  |     response = model.predict(tasks, context=context, **params)
segment_anything_model  |   File "/app/model.py", line 51, in predict
segment_anything_model  |     predictor_results = PREDICTOR.predict(
segment_anything_model  |   File "/app/sam_predictor.py", line 202, in predict
segment_anything_model  |     return self.predict_sam(img_path, point_coords, point_labels, input_box, task)
segment_anything_model  |   File "/app/sam_predictor.py", line 173, in predict_sam
segment_anything_model  |     self.set_image(img_path, calculate_embeddings=False, task=task)
segment_anything_model  |   File "/app/sam_predictor.py", line 86, in set_image
segment_anything_model  |     image_path = get_local_path(
segment_anything_model  |   File "/usr/local/lib/python3.8/site-packages/label_studio_tools/core/utils/io.py", line 121, in get_local_path
segment_anything_model  |     raise FileNotFoundError(
segment_anything_model  | FileNotFoundError: Can't resolve url, neither hostname or project_dir passed: /data/upload/1/80cf6086-1LookingAwayOrig.JPG. You can set LABEL_STUDIO_URL environment variable to use it as a hostname.

I've checked similar issues and I believe this is a new issue (though I may be entirely wrong). Could anyone help me out with this? Thanks so much!!

After poking around for a bit, I found this which suggests that maybe I have to use an absolute path instead of a relative path - give me a second to see if this fixes the issue

Still getting the same error running docker run -it -p 8080:8080 -v /mydata:/label-studio/data --env LABEL_STUDIO_LOCAL_FILES_SERVING_ENABLED=true --env LABEL_STUDIO_LOCAL_FILES_DOCUMENT_ROOT=C:\\data\\media heartexlabs/label-studio :(

segment_anything_model  | Point coords are [[2040, 1356], [1883, 1408]], point labels are [0, 1], input box is None
segment_anything_model  | [2024-06-02 13:20:00,785] [ERROR] [label_studio_ml.exceptions::exception_f::53] Traceback (most recent call last):
segment_anything_model  |   File "/usr/local/lib/python3.8/site-packages/label_studio_ml/exceptions.py", line 39, in exception_f
segment_anything_model  |     return f(*args, **kwargs)
segment_anything_model  |   File "/usr/local/lib/python3.8/site-packages/label_studio_ml/api.py", line 69, in _predict
segment_anything_model  |     response = model.predict(tasks, context=context, **params)
segment_anything_model  |   File "/app/model.py", line 51, in predict
segment_anything_model  |     predictor_results = PREDICTOR.predict(
segment_anything_model  |   File "/app/sam_predictor.py", line 202, in predict
segment_anything_model  |     return self.predict_sam(img_path, point_coords, point_labels, input_box, task)
segment_anything_model  |   File "/app/sam_predictor.py", line 173, in predict_sam
segment_anything_model  |     self.set_image(img_path, calculate_embeddings=False, task=task)
segment_anything_model  |   File "/app/sam_predictor.py", line 86, in set_image
segment_anything_model  |     image_path = get_local_path(
segment_anything_model  |   File "/usr/local/lib/python3.8/site-packages/label_studio_tools/core/utils/io.py", line 121, in get_local_path
segment_anything_model  |     raise FileNotFoundError(
segment_anything_model  | FileNotFoundError: Can't resolve url, neither hostname or project_dir passed: /data/upload/1/80cf6086-1LookingAwayOrig.JPG. You can set LABEL_STUDIO_URL environment variable to use it as a hostname.
segment_anything_model  |
segment_anything_model  | Traceback (most recent call last):
segment_anything_model  |   File "/usr/local/lib/python3.8/site-packages/label_studio_ml/exceptions.py", line 39, in exception_f
segment_anything_model  |     return f(*args, **kwargs)
segment_anything_model  |   File "/usr/local/lib/python3.8/site-packages/label_studio_ml/api.py", line 69, in _predict
segment_anything_model  |     response = model.predict(tasks, context=context, **params)
segment_anything_model  |   File "/app/model.py", line 51, in predict
segment_anything_model  |     predictor_results = PREDICTOR.predict(
segment_anything_model  |   File "/app/sam_predictor.py", line 202, in predict
segment_anything_model  |     return self.predict_sam(img_path, point_coords, point_labels, input_box, task)
segment_anything_model  |   File "/app/sam_predictor.py", line 173, in predict_sam
segment_anything_model  |     self.set_image(img_path, calculate_embeddings=False, task=task)
segment_anything_model  |   File "/app/sam_predictor.py", line 86, in set_image
segment_anything_model  |     image_path = get_local_path(
segment_anything_model  |   File "/usr/local/lib/python3.8/site-packages/label_studio_tools/core/utils/io.py", line 121, in get_local_path
segment_anything_model  |     raise FileNotFoundError(
segment_anything_model  | FileNotFoundError: Can't resolve url, neither hostname or project_dir passed: /data/upload/1/80cf6086-1LookingAwayOrig.JPG. You can set LABEL_STUDIO_URL environment variable to use it as a hostname.

This is like #443 and #355 except the images are already imported using the GUI and it still doesn't work.
Any advice?

On a whim I tried docker run -it -p 8080:8080 -v C:\\labelstudiodata:\\label-studio\\data --env LABEL_STUDIO_LOCAL_FILES_SERVING_ENABLED=true --env LABEL_STUDIO_LOCAL_FILES_DOCUMENT_ROOT=C:\\data\\media heartexlabs/label-studio and that didn't work either unfortunately

Have you tried to set LABEL_STUDIO_URL and LABEL_STUDIO_API_KEY ?
I see you used HOST and ACCESS_TOKEN, but it is better to try url and api_key.

WOW that did it! For others who come across this issue, I just changed LABEL_STUDIO_HOST and LABEL_STUDIO_ACCESS_TOKEN to LABEL_STUDIO_URL and LABEL_STUDIO_API_KEY respectively and it worked first try! Thanks @makseq!