Koldim2001 / COCO_to_YOLOv8

Converting COCO annotation (CVAT) to annotation for YOLOv8-seg (instance segmentation) and YOLOv8-obb (oriented bounding box detection)
GNU Affero General Public License v3.0
182 stars 9 forks source link

Cannot generate yolov8 dataset from coco-1.0 format created by cvat #2

Closed WorstCodeWay closed 2 weeks ago

WorstCodeWay commented 1 month ago

Enviroment

cvat : 2.17.0 (from develop branch) ubuntu : 22.04 COCO_to_YOLOv8 : main

Coco dataset folder

abeled$ tree
.
├── annotations
│   └── instances_Train.json
└── images
    └── Train
        └── Data
           ├── 0001_good.bmp
           ├── 0001_wrong_image.bmp
           ├── 0002_good.bmp
           ├── 0002_shifted.bmp
           ├── 0003_good.bmp
           └── 0003_wrong_color.bmp

3 directories, 7 files

Problem

FileNotFoundError: Some images annotated in ../datasets/labeled/annotations/instances_Train.json are missing from the images folder. Missing images: {'0001_good.bmp', '0002_shifted.bmp', '0001_wrong_image.bmp', '0002_good.bmp', '0003_wrong_color.bmp', '0003_good.bmp'}

My guess

Coco dataset has Train tag appended to label file(json file, like _instancesTrain.json), and meanwhile images are resided in that Train directory (see Coco dataset folder structure). However, codes here doesn't consider that case and fail.

I have a fix, but don't know if it helps?

Koldim2001 commented 1 month ago

I advise you to move the image files one level earlier, that is, so that the structure is like this:

COCO_dataset/
|-- annotations/
|   |-- instances_train.json
|   |-- instances_val.json
|-- images/
|   |-- image1.jpg
|   |-- image2.jpg
|   |-- ...
WorstCodeWay commented 4 weeks ago

I advise you to move the image files one level earlier, that is, so that the structure is like this:

COCO_dataset/
|-- annotations/
|   |-- instances_train.json
|   |-- instances_val.json
|-- images/
|   |-- image1.jpg
|   |-- image2.jpg
|   |-- ...

@Koldim2001 Thanks for reply.

Yes, that would be a solution, but my data folder structure is generated by cvat (since we claim to support CVAT application), so I think we should convert it to yolov8 format without touching these files and it structure, right?

Koldim2001 commented 4 weeks ago

yes, I agree. Apparently, the storage location of photos depends on the version cvat. My upload in this format looks like in the example. So, as an option, you can separately change the code for your format by forking this repository. It will be useful to have a solution for both versions. 👍🏻 The simplest solution to this problem is to write an automatic transfer of photos to the root of the images folder if they are not located where they should be

WorstCodeWay commented 4 weeks ago

yes, I agree. Apparently, the storage location of photos depends on the version cvat. My upload in this format looks like in the example. So, as an option, you can separately change the code for your format by forking this repository. It will be useful to have a solution for both versions. 👍🏻 The simplest solution to this problem is to write an automatic transfer of photos to the root of the images folder if they are not located where they should be

Sounds great. For now, I forked this repository and adapt it to newer version of cvat. For automatic transfer part, I'll think about it, and let you know if there is some better way to achieve it.

Besides, I've updated my original question in folder structure, there is another sub-folder within Train named Data(don't know why cvat do it this way?)

Anyway, thanks for your nice work!

Koldim2001 commented 4 weeks ago

I assume that if there is a task that is not defined to any of the subtasks such as train validation or test, then it creates a data folder. But I'm not exactly sure. I can hardly tell you.

WorstCodeWay commented 4 weeks ago

I assume that if there is a task that is not defined to any of the subtasks such as train validation or test, then it creates a data folder. But I'm not exactly sure. I can hardly tell you.

Not really, it will create a default installed of train, validataion or test. And thus a default sub-folder