How to convert a group of images into a image dataset format so that I can feed the data in to a CNN?

Hello folks, I am trying to convert images generated in to a dataset.(All I ahve is just png images in n folders and there is no label or meta data)

This is what I aspire to do:

1.I am using torch audio to convert audio formats to Mel spectrogram and save the images as Png format. Status:done
2.Now I have ā€˜nā€™ number of folders(classes) with images so I am curious if I could convert the newly generated images into data and target as in normal datasets, so that I can use sklearn to do the test train splits sklearn.model_selection.train_test_split.Status:not done

eg: fetch mnist dataset

> ds_mnist = sklearn.datasets.fetch_openml(
>     data_id=554,
>     as_frame=False
> )

Split data and target in to X and y

dataset_X = ds_mnist .data.astype('float32')

dataset_y = ds_mnist .target.astype('int64')

Blockquote

You could use ImageFolder to load the dataset and create the class labels based on the folders. Once this is done you would then create the split indices and use Subsets to create the training, validation, and test datasets.

1 Like