HumanSignal / HumanSignal/label-studio-ml-backend
SAM inferrence fails with `FileNotFoundError` while pulling from local storage
- Dominant language
- Python
- Stars
- 1.1k
- Forks
- 490
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 3
Description
Annotation with SAM backend fails consistently when trying to retrieve images from local storage. Tasks in question are loaded in the label studio itself and images are visible, it is only when annotation is requested that issues manifest.
The annotation works with manually uploaded files. The only problem is local storage.
Local storage settings:

Docker compose file snippet (I've cut out secrets etc., but relevant parts remain):
```
label-studio:
image: heartexlabs/label-studio:latest
command: label-studio start
user: "1587059813:0"
volumes:
- ./mydata:/label-studio/data:rw # Main storage in user home
- images-extracted:/label-studio/files/external:rw # External storage - general
- labels:/label-studio/files/labels:rw # External storage - labels
- source-images:/label-studio/files/sourcedata:rw # External storage - data only
# - ./labelstudio:/root/.local/share/label-studio:rw
depends_on:
- db
ports:
- 9000:8080
deploy:
resources:
reservations:
cpus: '1'
environment:
...
- LABEL_STUDIO_LOCAL_FILES_SERVING_ENABLED=${LABEL_STUDIO_LOCAL_FILES_SERVING_ENABLED:-true} # Necessary for local file connection
- LABEL_STUDIO_LOCAL_FILES_DOCUMENT_ROOT=${LABEL_STUDIO_LOCAL_FILES_DOCUMENT_ROOT:-/label-studio/files/} # Location of local file connection mount
- DJANGO_DB=default
- POSTGRE_NAME=${DB_NAME:-postgres}
- POSTGRE_USER=${DB_USER:-postgres}
- POSTGRE_PASSWORD=...
- POSTGRE_PORT=5432
- POSTGRE_HOST=localhost
restart: unless-stopped
network_mode: "host"
...
sam_server:
container_name: sam_server
image: humansignal/sam:v0 # Locally build, is not available in online repos
deploy:
resources:
limits:
memory: 16G # Hard memory limit
reservations:
memory: 8G # Soft maximum
cpus: '1'
environment:
# Change this to your model name
- SAM_CHOICE=MobileSAM # Other options are available, but may be slower
- LOG_LEVEL=DEBUG # We can disable this, but it's useful
# Add these variables if you want to access the images stored in Label Studio
- LABEL_STUDIO_HOSTNAME=http://localhost:8080 # Always set to 'localhost' if we are on "host" network
- LABEL_STUDIO_ACCESS_TOKEN=${LABEL_STUDIO_USER_TOKEN}
ports:
- 9090:9090
volumes:
- ./sam_data/server:/data:rw # Location of SAM model weights and checkpoints
restart: unless-stopped
network_mode: "host"
```
Full trace:
```
File "/usr/local/lib/python3.8/site-packages/label_studio_ml/exceptions.py", line 39, in exception_f
return f(*args, **kwargs)
File "/usr/local/lib/python3.8/site-packages/label_studio_ml/api.py", line 61, in _predict
predictions = model.predict(tasks, context=context, **params)
File "/app/model.py", line 48, in predict
predictor_results = PREDICTOR.predict(
File "/app/sam_predictor.py", line 195, in predict
return self.predict_sam(img_path, point_coords, point_labels, input_box)
File "/app/sam_predictor.py", line 167, in predict_sam
self.set_image(img_path, calculate_embeddings=False)
File "/app/sam_predictor.py", line 83, in set_image
image_path = get_image_local_path(
File "/usr/local/lib/python3.8/site-packages/label_studio_ml/utils.py", line 64, in get_image_local_path
image_local_path = get_local_path(
File "/usr/local/lib/python3.8/site-packages/label_studio_tools/core/utils/io.py", line 68, in get_local_path
raise FileNotFoundError(filepath)
FileNotFoundError: /external/subdir/someimage.jpg
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.