Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows COCO Import Issue #6949

Open
PatrickGold555 opened this issue Jan 23, 2025 · 5 comments
Open

Windows COCO Import Issue #6949

PatrickGold555 opened this issue Jan 23, 2025 · 5 comments

Comments

@PatrickGold555
Copy link

PatrickGold555 commented Jan 23, 2025

So i have seen so many people having this issue and cant believe this hasn't been sorted out.

I installed LS on windows in my python env with pip, created a new project, labeled 500 images and exported the project and images as COCO.

I wanted to send this export to a mate to double check the labeling, but before i did i deleted my LS project and tried to import the project and this is where it all went south.

I can get the annotations to import, but there are no images

I followed the guides and posts here

https://labelstud.io/guide/storage.html#Local-storage
#2806
https://community.labelstud.io/t/how-do-i-upload-annotations-in-the-ms-coco-format-for-images/374

in my python env, i found the base.py file and made my environment changes there.

My first issue is when i try and create a local storage folder via the UI i get the following error

[ErrorDetail(string="Serving local files can be dangerous, so it's disabled by default. You can enable it with LOCAL_FILES_SERVING_ENABLED environment variable, please check docs: https://labelstud.io/guide/storage.html#Local-storage", code='invalid')]

So i run the following set LOCAL_FILES_SERVING_ENABLED=true and i am able to upload files, i then add Source Storage, select Local, and specify my path D:\data, i include images into the data folder and try Sync, but sync always fails.

Next, when i unzip my coco export, i run the json file thru the label-studio-converter, i then create a new project, import that new json script, and i can see that all of my annotations load, however the images are not being displayed (Which makes sense at this point because no images have actually been uploaded yet)

But looking at the new json file the location to my image is "/data/local-files/?d=\9_17329744121672838.png" what does this even mean where is /data/local-files/?d= specified?, i tried manually changing the image locations to absolute paths and this also doesn't work.

There was a post that i saw that stated you can set a working directory when you start LS but for the life of me i cannot get the imports to work.

This there maybe a guide somewhere that can assist with this?

This is such a frustrating problem to have.

@PatrickGold555
Copy link
Author

In the newly created json file this is an example of my image location

"data": {
"image": "/data/local-files/?d=images/875c824e-0ae7bb1c-b2af-4c3d-9618-66b5bfa95d49_17329744121672838.png"
}

[/data/local-files] - i assume this is the local directory where the .sqlite3 database is stored, so in my instance it is stored here
C:\Users\User\AppData\Local\label-studio\label-studio

I added my images in multiple locations to see if it works, so i added my images to the following locations:

C:\Users\User\AppData\Local\label-studio\label-studio
C:\Users\User\AppData\Local\label-studio\label-studio\media
C:\Users\User\AppData\Local\label-studio\label-studio\media\images

In label studio i can see that my project has all of the image files with the annotations, however the images are not displayed.

There is no local storage setup in my project, because when i add local storage and point it to the directory where my 250 images are i have 250 items in my project with annotations but no images, and i also have 250 images with no annotations.

Starting to pull my hair out with this.

@JKYang01
Copy link

JKYang01 commented Jan 23, 2025

could you share the screen shot of your project settings page?
I have encountered similar issue before, here is my issue link:
#6946 (comment)

not exactly the same but I was wondering it is possible you may forget to turn off the "Treat every bucket object as a source file" button when you try to load the pre-annotation json files as annotation tasks.

@PatrickGold555
Copy link
Author

PatrickGold555 commented Jan 24, 2025

I managed to get the import to work, but this was not a fun experience.

This guide already assumes that you have project that was exported to COCO and you have the .json file and images from the export.

Here is what i did step by step.

  • Created a new python venv, activated it (scripts\activate) and installed label-studio with pip
  • Installed the Label-Studio Converter (See below)
git clone https://github.com/heartexlabs/label-studio-converter.git
cd label-studio-converter
pip install -e .
  • I then copied my export files (result.json and images folder) to a folder on my D:\Test
  • i then ran the following command with the label-studio converter

label-studio-converter import coco -i “D:\Test\result.json” -o “D:\Test\fixed.json”

  • I then opened the new fixed.json file and noticed my image paths looked like this
"data": {
    "image": "/data/local-files/?d=\\images\\0.png"
  }

i changed it to look like this (removed the \images\ and used single forward slashes and called my new folder dataset1)

"data": {
    "image": "/data/local-files/?d=dataset1/0.png"
  },
  • /data/local-files is the working directory for label-studio where the sqlite db is stored so in my instance it was stored here
    C:\Users\User\AppData\Local\label-studio\label-studio

  • I then opened the media folder and created a new folder in there called dataset1 to match the path in my fixed.json file and i pasted all of my images from the COCO export into the dataset1 folder, so the full path to where my images are now stored is now the follow C:\Users\User\AppData\Local\label-studio\label-studio\media\dataset1

  • I then made some changes to my label-studio base.py file found here
    ..\your_python_venv\Lib\site-packages\label_studio\core\settings\base.py

and i changed the following values, and if i didnt see the values i just added them

ENABLE_LOCAL_FILES_STORAGE = get_bool_env('ENABLE_LOCAL_FILES_STORAGE', default=True)
LOCAL_FILES_SERVING_ENABLED = get_bool_env('LOCAL_FILES_SERVING_ENABLED', default=True)
LABEL_STUDIO_LOCAL_FILES_SERVING_ENABLED=True
LOCAL_FILES_DOCUMENT_ROOT = get_env('LOCAL_FILES_DOCUMENT_ROOT', 'C:\Users\User\AppData\Local\label-studio\label-studio\media')
LABEL_STUDIO_LOCAL_FILES_DOCUMENT_ROOT='C:\Users\User\AppData\Local\label-studio\label-studio'

  • I then ran the following command in my active python venv set LOCAL_FILES_SERVING_ENABLED=true

  • Next i started label-studio

  • Created a new project

  • setup my labeling XML

<View>
<Image name="image" value="$image" zoom="true" zoomControl="true"/>
<RectangleLabels name="label" toName="image">
<Label value="column" background="#00FF00"/>
</RectangleLabels>
</View>
  • Saved the project then went to the settings tab.
  • Cloud Storage -> Source Cloud Storage -> Add Source Storage, and added the following values

Storage Type = Local Files.
Storage Title = dataset1
Absolute local = C:\Users\User\AppData\Local\label-studio\label-studio\media\dataset1
And check the box Treat every bucket object as a source file

I then saved this and click on the sync button, my images were synced and imported.
In my case i had 500 images updated to my project, i then selected all images from the project and removed then

I then clicked on import, and just added the new fixed.json file with the new image file paths, all of my images and previous annotations were successfully imported and i was able to continue labeling.

this process broke my brain, and maybe this import /export issue needs to resolved in a future release.

@PatrickGold555
Copy link
Author

I really hope this approach helps someone else that is having the same issue

@heidi-humansignal
Copy link
Collaborator

Hello PatrickGold555,

Thank you and that is correct approach. I'll see if we can have proper documentation for this

Thank you,
Abu

Comment by Abubakar Saad
Workflow Run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants