get_local_path in label_studio_tools/core/utils/io.py creates invalid path on Windows 10 when used with local storage
See original GitHub issueDescribe the bug A clear and concise description of what the bug is.
get_local_path in label_studio_tools/core/utils/io.py creates file paths with the format:
local-files/folder\img.jpg
, which causes it to raise a FileNotFoundError(local-files/folder\img.jpg)
To Reproduce Steps to reproduce the behavior:
-
Create a valid local files source storage connection according to https://labelstud.io/guide/storage.html#Set-up-connection-in-the-Label-Studio-UI-4
-
Execute some task that calls get_local_path. E.g. attempting to run ‘Auto-Annotation’ with a ml backend in the labelling UI interface.
-
Auto-Annotation fails with
FileNotFoundError: local-files/folder\img.jpg
Expected behavior
get_local_path to return a valid path for the file in question: e.g. C:/path/to/local/img.jpg
Screenshots If applicable, add screenshots to help explain your problem.
Environment (please complete the following information):
- OS: Windows 10, running directly on OS (no container)
- Label Studio Version 1.5.0.post0
Additional context I fixed this for my local implementation by changing lines 56-62 in io.py from:
if is_local_file:
dir_path, filename = url.split('/data/')[1].split('?d=')
filename = str(urllib.parse.unquote(filename))
filepath = os.path.join(dir_path, filename)
if not os.path.exists(filepath):
raise FileNotFoundError(filepath)
return filepath
to:
if is_local_file:
local_files_root = os.environ['LABEL_STUDIO_LOCAL_FILES_DOCUMENT_ROOT']
filename = url.split('/data/')[1].split('?d=')[1]
filename = str(urllib.parse.unquote(filename))
filepath = os.path.join(local_files_root, filename)
if not os.path.exists(filepath):
raise FileNotFoundError(filepath)
return filepath
I don’t know if this breaks other functionality / implementations on other OS’s but I did manage to get Auto-Annotation to work on my machine
On a related note, when I export annotations in COCO format I get ‘file_name’ lines that follow the format:
"file_name": "/data/local-files/?d=folder\\img.jpg"
Which, I assume is also a bug?
Issue Analytics
- State:
- Created a year ago
- Comments:6 (2 by maintainers)
@mukeshnarendran7 Yes, you need to set LOCAL_FILES_DOCUMENT_ROOT manually.
Could you please update your label-studio-tools to 0.0.0.dev15?