My directory is like this.
1/
Images/
1_1.jpg
1_2.jpg
2/
Images/
2_1.jpg
2_1.jpg
How to load data into databunch?
When I use from_folder all my images get tagged as ‘Images’
My directory is like this.
1/
Images/
1_1.jpg
1_2.jpg
2/
Images/
2_1.jpg
2_1.jpg
How to load data into databunch?
When I use from_folder all my images get tagged as ‘Images’
Hi there,
the from_folder()
part should not be the issue since this will just grab all files with image extension from your directory. You have probably used the label_from_folder()
function?? You might want to use
label_from_func(lambda fn: fn.name.split('_')[0])
The input to the lambda will be the paths to your images as pathlib object. the .name
gives you the name of the file as string and .split('_')
splits this name at every _
. From you example it seems the very first part of the filename, before the first _
is the class, therefore take the first element of the list that is returned from split()
as label.
Greetings
Thanks @xeTaiz.
I was able to get the training images.
But looks like validation images are named as
val_1.jpg
val_2.jpg
All the result are saved in csv
Val_1 classA
Val_2 classC
Can I get those images into ImageDataBunch?
Is there a resource on ImageDataBunch?
https://docs.fast.ai/data_block.html
This is probably the part of the documentation you want to look at. It has lots of examples too.
If your training and validation images have a different naming scheme this is not going to work that well. If that’s the case I would actually suggest writing a small python script to rename the validation images similar to the training images… Or just make a csv for both train and valid. Both works nicely, however trying to retrieve labels differently from train and valid is not easily doable as far as I am aware.