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

No Output #50

Open
mazaaaa opened this issue Jun 2, 2023 · 10 comments
Open

No Output #50

mazaaaa opened this issue Jun 2, 2023 · 10 comments

Comments

@mazaaaa
Copy link

mazaaaa commented Jun 2, 2023

The Code just ran with no output.

@bcwein
Copy link

bcwein commented Jun 2, 2023

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.

@mazaaaa
Copy link
Author

mazaaaa commented Jun 4, 2023

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

@widedh
Copy link

widedh commented Jun 19, 2023

hello, did you find a solution, please?

@ryouchinsa
Copy link

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.

@SadeghPouriyanZadeh
Copy link

same here. it makes a new directory named "new_dir" and only create the directory structures in it. the problem is in this line:

with open((fn / f).with_suffix('.txt'), 'a') as file:

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!

@glenn-jocher
Copy link
Member

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.

@AJAY31797
Copy link

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.

@ryouchinsa
Copy link

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.

@ponnyWu
Copy link

ponnyWu commented Jan 15, 2024

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")

@glenn-jocher
Copy link
Member

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! 🌟

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

No branches or pull requests

8 participants