Image Augmentation
import tensorflow as tf
import matplotlib.pyplot as plt
image = tf.io.read_file("tf_CN.png")
image = tf.io.decode_jpeg(image)
plt.figure()
plt.imshow(image)
Output
Flipping the Image
flip = tf.image.flip_left_right(image)
plt.imshow(flip)
Output
Adjusting saturation in the Image
saturate = tf.image.adjust_saturation(image, 10)
plt.imshow(saturate)
Output
Rotating the Image by 90 degree
rotate = tf.image.rot90(image)
plt.imshow(rotate)
Output
Cropping the Image
crop = tf.image.central_crop(image, central_fraction=0.5)
plt.imshow(crop)
Output
Brightening the Image
brighten = tf.image.adjust_brightness(image, delta=0.6)
plt.imshow(brighten)
Output
Accessing various datasets in the TensorFlow library
Install and import all TensorFlow datasets
pip install tensorflow-datasets
import tensorflow_datasets as tfds
There are different widely used datasets available in this library.
MNIST Digits Dataset
mnist_data = tfds.load("mnist")
mnist_train, mnist_test = mnist_data["train"], mnist_data["test"]
print(len(mnist_train))
print(len(mnist_test))
Output
Titanic Dataset
data = tfds.load('titanic', split='train', shuffle_files=True)
data = data.shuffle(1024).batch(32).prefetch(tf.data.experimental.AUTOTUNE)
for i in data.take(1):
print("Features")
print(i['features'])
print("Labels")
print(i['survived'])
Output