JSON2YOLO
JSON2YOLO copied to clipboard
No Output
The Code just ran with no output.
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.
Hey, Bjorn, thanks for helping, that happened once i changed as you told but I'm not getting the converted file anywhere, please help.
hello, did you find a solution, please?
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.
Please let us know your opinion.
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!
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.
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.
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.
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")
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! 🌟