JSON2YOLO icon indicating copy to clipboard operation
JSON2YOLO copied to clipboard

No Output

Open mazaaaa opened this issue 1 year ago • 10 comments

The Code just ran with no output.

mazaaaa avatar Jun 02 '23 03:06 mazaaaa

I am facing the same issue

I modified the main section to

if __name__ == '__main__':
    source = 'COCO'

    if source == 'COCO':
        convert_coco_json('../datasets/json',  # directory with *.json
                          use_segments=True,
                          cls91to80=False)

And when I run the command

python general_json2yolo.py

It creates a new folder called new_dir with no contents.

bcwein avatar Jun 02 '23 08:06 bcwein

Hey, Bjorn, thanks for helping, that happened once i changed as you told but I'm not getting the converted file anywhere, please help.

mazaaaa avatar Jun 04 '23 00:06 mazaaaa

hello, did you find a solution, please?

widedh avatar Jun 19 '23 11:06 widedh

Thanks for writing the issue. We check it works using this script global_json2yolo.py.

Looking at the global_json2yolo code, there are some flags. Converting the COCO bbox format to YOLO bbox format.

use_segments=False,
use_keypoints=False,

Converting the COCO segmentation format to YOLO segmentation format.

use_segments=True,
use_keypoints=False,

Converting the COCO keypoints format to YOLO keypoints format.

use_segments=False,
use_keypoints=True,

To convert the COCO segmentation format to YOLO segmentation format.

if __name__ == '__main__':
    source = 'COCO'

    if source == 'COCO':
        convert_coco_json('../datasets/coco/annotations',  # directory with *.json
                          use_segments=True,
                          use_keypoints=False,
                          cls91to80=False)

This is the folder structure when we run the script.

スクリーンショット 2023-10-25 20 51 05

Please let us know your opinion.

ryouchinsa avatar Oct 25 '23 13:10 ryouchinsa

same here. it makes a new directory named "new_dir" and only create the directory structures in it. the problem is in this line: https://github.com/ultralytics/JSON2YOLO/blob/c38a43f342428849c75c103c6d060012a83b5392/general_json2yolo.py#L306

fn is a PathPosix and so f. but the problem is that at last the fn directory is the result of fn / f.

What about the images directory in the created directory called new_dir? There is no code to copy the source images to destination directory!

SadeghPouriyanZadeh avatar Nov 01 '23 08:11 SadeghPouriyanZadeh

Thanks for reaching out! It appears that the issue might be occurring due to the usage of fn / f on the PathPosix objects fn and f at line 306, which may result in unexpected directory structure within new_dir. Additionally, there seems to be no code to copy the source images to the destination directory. These factors could be leading to the observed behavior. Let us know your thoughts on this.

glenn-jocher avatar Nov 09 '23 18:11 glenn-jocher

Same for me, the code is just creating an empty folder named 'new_dir' which contains two subfolders, 'images' and 'labels'. Both of these are empty. I have checked the values of the arguments use_segments and use_keypoints, both are correct as mentioned above. Could you suggest what could be the problem.

AJAY31797 avatar Nov 28 '23 22:11 AJAY31797

Hi @SadeghPouriyanZadeh, please copy images by yourself. Do you have any other problems?

Hi @AJAY31797, please show us your COCO JSON file. We can debug with the script.

ryouchinsa avatar Nov 29 '23 03:11 ryouchinsa

Find the section “Write”on line 308:

            # Write
            with open((fn / f).with_suffix(".txt"), "a") as file:
                for i in range(len(bboxes)):
                    line = (*(segments[i] if use_segments else bboxes[i]),)  # cls, box or segments
                    file.write(("%g " * len(line)).rstrip() % line + "\n")

Add two lines of code:

            # Write
            output_file_path = (fn / f).with_suffix(".txt")
            os.makedirs(os.path.dirname(output_file_path), exist_ok=True)

            with open((fn / f).with_suffix(".txt"), "a") as file:
                for i in range(len(bboxes)):
                    line = (*(segments[i] if use_segments else bboxes[i]),)  # cls, box or segments
                    file.write(("%g " * len(line)).rstrip() % line + "\n")

ponnyWu avatar Jan 15 '24 13:01 ponnyWu

Hello @ponnyWu, thank you for your patience. It seems like you've identified a potential fix by ensuring the directory exists before attempting to write the file. This is a good catch! The os.makedirs(os.path.dirname(output_file_path), exist_ok=True) line creates the directory structure needed for the output file if it doesn't already exist. This should resolve the issue of the script creating empty folders. If you continue to experience problems, please provide a snippet of your COCO JSON file for further debugging. Your contributions are valuable to the community! 🌟

glenn-jocher avatar Jan 15 '24 17:01 glenn-jocher