Skip to content
Advertisement

what does cardinality mean in relation to an image dataset?

After successfully creating a tensorflow image Dataset with:

dataset = tf.keras.utils.image_dataset_from_directory(...)

which returns

Found 21397 files belonging to 5 classes. Using 17118 files for training.

There is the cardinality method:

dataset.cardinality()

which returns a tensor containing the single value

tf.Tensor(535, shape=(), dtype=int64)

I’ve read the docs here but I don’t understand what 535 represents or why its different to the number of files?

I ask, because I would like to understand how cardinality plays into this equation:

steps_per_epoch = dataset.cardinality().numpy() // batch_size

Advertisement

Answer

The cardinality, in your case, is simply the rounded number of batches:

JavaScript
JavaScript

The equation is: 2936/32 = cardinality, so it depends on your batch size.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement