'split image dataset into two folders according to info in json

I have a dataset in the form of coco dataset, and i need to split it into train and val. I did the split of the annotations which is in json file , so i have now two json files. but i still need to split the images into two separated folders (train and val). this should be according to the name of images (file_name) mentioned in each json file.

i don't know how to do so. it need to enter /read a certain object in json , from which search the name in another folder , took the image and but it in train or val folder.

my json format is like this: 5 objects

enter image description here

any help ? please.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source