I’m learning some Python using this tutorial for solving Vision Related tasks using CNNs, however there are several differences:
- Newest dataset is not anymore in tensorflow.keras.dataset as of tf 2.12 at least
1.b In fact, keras is also in a different path, i.etensorflow.python.keras
- Instead we need to install
tensorflow-datasets
So this in the tutorial:
import tensorflow as tf
from tensorflow.keras import datasets, layers, models
Ends up being:
import tensorflow as tf
from tensorflow.python.keras import layers, models
import tensorflow_datasets as tfds
- Now the API for this package is very different. So this in the tutorial:
class_names = ['airplane', 'automobile', 'bird', 'cat', 'deer',
'dog', 'frog', 'horse', 'ship', 'truck']
plt.figure(figsize=(10,10))
for i in range(25):
plt.subplot(5,5,i+1)
plt.xticks([])
plt.yticks([])
plt.grid(False)
plt.imshow(train_images[i])
# The CIFAR labels happen to be arrays,
# which is why you need the extra index
plt.xlabel(class_names[train_labels[i][0]])
plt.show()
Ends up using .take()
because you cant use indexes:
(train, test), info = tfds.load('cifar10', split=['train', 'test'], with_info=True)
for i, item in enumerate(train.take(25)):
image = item["image"].numpy()
plt.imsave(f'test_{i}.png', image)
I would be interesting hearing other options that you would show the images from the dataset.
Indexes can also be used item[0].numpy()
if the function is called with arg as_supervised=True
There is a nice tutorial for Dataset thought, just found it: TensorFlow Datasets