I’d like to create a dataset from images in a special folder. Next I’d like to classify them using tensorflow according to the scheme from the dataset.
Is there any quick and efficient way to create a dataset from images and labels?
I’d like to create a dataset from images in a special folder. Next I’d like to classify them using tensorflow according to the scheme from the dataset.
Is there any quick and efficient way to create a dataset from images and labels?
Your question is a bit vague but here is what I think you mean and you can solve your problem.
I guess you have some images, who belong to certain classes. The images of the same class are in the same folder. Like so:
images/
cats/
img_0.png
img_1.png
img_2.png
...
dogs/
img_0.png
img_1.png
img_2.png
...
You now want a dataset where the x-values are the images and the y-values are the classes.
As described here you can use
train_ds = tf.keras.preprocessing.image_dataset_from_directory(
data_dir,
validation_split=0.2,
subset="training",
seed=123,
image_size=(img_height, img_width),
batch_size=batch_size)
to load your data. In the example I've given the variable for data_dir
should hold the value "images"
. This is a fast and convenient way to load data in TensorFlow. I recommend to click on the link I provided to see the full tutorial on loading data into TensorFlow.