How do you read images if the folders are split into classes

My folder structure is in this format

 └─── case1
 │   │   case1.jpg
 └─── case2
 │   │   case2.jpg
 class 2
 └─── case3
 │   │   case3.jpg
 └─── case4
 │   │   case4.jpg

How do I create a databunch of those images, such that they are split into train/test aswell

Simple way of doing it would be re-saving the images in one folder where the image names are coded by class and case name, so you keep track of them. if you wish you can then select x% of the folder and re-save them in a validation/test folder afterwards. many libraries offer reading and writing images.

first find a way to iterate through folders in the class folders programatically, such that for-loops finds accessible folder and iterate through those, gets imagefiles, renames the imagefiles based on classname and resaves to a specific path, i.e. your now folder. you can also have it remove the images in original folders using os.remove(path).

as far as finding folders this might be what you are looking for:

Thanks alot for your reply what do you suggest I would do after I had them all in one folder? btw my image names are like class1 (2).png

It really depends and you’ll never get a generic answer. Is it image classification? What’s the abundance in each class? Is it necessary to deal with class imbalance? Is your dataset large enough for 20% split or do you have to be happy with less to be able to train? Are some of the questions you have to ask and I’m not necessarily an expert :slight_smile: I for segmentation have a dataset of 1400 images and 800000 objects but found through experimentation that I could train on just 20% of my dataset.

Thanks alot!, in my case I have 780 images only, so I divided it into 90% trainset and 10% Validset, but now I get a problem that how do I check the accuracy given that I had trained my model. I am using my model for classification

Sorry I really should get email notification on this to remember to reply. Did you solve this yet?

Yes I got it sorry to have kept you hanging there