-
Notifications
You must be signed in to change notification settings - Fork 407
Description
I'm trying to use the segment anything example and am running into an issue with my personal access token/api key
I'm using docker for both Label Studio and the ML Backend. So far everything else is working, but when I actually add my first keypoint on an imported image, I get the following error in the ml backend
segment_anything_model | [2025-05-20 00:04:54,843] [DEBUG] [urllib3.connectionpool::_make_request::544] http://<my_ip>:8080 "GET /data/upload/2/8471850e-004.png HTTP/1.1" 401 124 segment_anything_model | [2025-05-20 00:04:54,844] [ERROR] [label_studio_ml.exceptions::exception_f::53] Traceback (most recent call last): segment_anything_model | File "/usr/local/lib/python3.10/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.10/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.10/site-packages/label_studio_sdk/_extensions/label_studio_tools/core/utils/io
.py", line 178, in get_local_path
segment_anything_model | filepath = download_and_cache(
segment_anything_model | File "/usr/local/lib/python3.10/site-packages/label_studio_sdk/_extensions/label_studio_tools/core/utils/io
.py", line 237, in download_and_cache
segment_anything_model | r.raise_for_status()
segment_anything_model | File "/usr/local/lib/python3.10/site-packages/requests/models.py", line 1024, in raise_for_status
segment_anything_model | raise HTTPError(http_error_msg, response=self)
segment_anything_model | requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: http://<my_ip>:8080/data/upload/2/8
471850e-004.png
and this error from my label studio docker container
[ERROR] d4716b7f-3bce-44a4-a650-aa6c8048e59e Invalid token.
Traceback (most recent call last):
File "/label-studio/.venv/lib/python3.12/site-packages/rest_framework/authentication.py", line 201, in authenticate_credentials
token = model.objects.select_related('user').get(key=key)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/label-studio/.venv/lib/python3.12/site-packages/django/db/models/query.py", line 649, in get
raise self.model.DoesNotExist(
rest_framework.authtoken.models.Token.DoesNotExist: Token matching query does not exist.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/label-studio/.venv/lib/python3.12/site-packages/rest_framework/views.py", line 497, in dispatch
self.initial(request, *args, **kwargs)
File "/label-studio/.venv/lib/python3.12/site-packages/sentry_sdk/integrations/django/__init__.py", line 333, in sentry_patched_drf_initial
return old_drf_initial(self, request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/label-studio/.venv/lib/python3.12/site-packages/rest_framework/views.py", line 414, in initial
self.perform_authentication(request)
File "/label-studio/.venv/lib/python3.12/site-packages/rest_framework/views.py", line 324, in perform_authentication
request.user
File "/label-studio/.venv/lib/python3.12/site-packages/rest_framework/request.py", line 231, in user
self._authenticate()
File "/label-studio/.venv/lib/python3.12/site-packages/rest_framework/request.py", line 384, in _authenticate
user_auth_tuple = authenticator.authenticate(self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/label-studio/label_studio/jwt_auth/auth.py", line 18, in authenticate
auth_result = super().authenticate(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/label-studio/.venv/lib/python3.12/site-packages/rest_framework/authentication.py", line 196, in authenticate
return self.authenticate_credentials(token)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/label-studio/.venv/lib/python3.12/site-packages/rest_framework/authentication.py", line 203, in authenticate_credentials
raise exceptions.AuthenticationFailed(_('Invalid token.'))
rest_framework.exceptions.AuthenticationFailed: Invalid token.
My label_studio_ml/examples/segment_anything_model/docker-compose.yml looks like
version: "3.8"
services:
segment_anything_model:
container_name: segment_anything_model
image: heartexlabs/label-studio-ml-backend:sam-master
init: true
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://<my_ip>:8080
- LABEL_STUDIO_ACCESS_TOKEN=<my_personal_acces_token>
ports:
- 9090:9090
volumes:
- "./data/server:/data"
I have copied my access token directly from my local Label Studio instance, so I don't understand why it is not working. Another thing I noticed is that my key seems to be very long in comparison to other examples (https://labelstud.io/guide/access_tokens#Personal-access-tokens-and-the-API) I see the API key is about 40 characters long, however mine is 185-240 characters long, which doesn't seem right.
Furthermore, if I click the "copy" button right after creating a new key, then the key is 230 characters, with the last 45 characters being a . followed by an 44 more characters. However if I highlight the key after creating it and click copy, I get a shortened version of just the first 185 characters.
It seems that something is going wrong with my key creation and setup. Has anyone seen this before or know why this may happen? Any assistance would be helpful.