API - Preprocessing

Data preprocessing, more Tensor functions about image, signal processing can be found in TensorFlow API

distorted_images([images, height, width]) Distort images for generating more training data.
crop_central_whiten_images([images, height, …]) Crop the central of image, and normailize it for test data.

Images

For training data

tensorlayer.preprocess.distorted_images(images=None, height=24, width=24)[source]

Distort images for generating more training data.

Parameters:
images : 4D Tensor

The tensor or placeholder of images

height : int

The height for random crop.

width : int

The width for random crop.

Returns:
result : tuple of Tensor

(Tensor for distorted images, Tensor for while loop index)

Notes

The first image in ‘distorted_images’ should be removed.

References

tensorflow.models.image.cifar10.cifar10_input

Examples

>>> X_train, y_train, X_test, y_test = tl.files.load_cifar10_dataset(shape=(-1, 32, 32, 3), plotable=False)
>>> sess = tf.InteractiveSession()
>>> batch_size = 128
>>> x = tf.placeholder(tf.float32, shape=[batch_size, 32, 32, 3])
>>> distorted_images_op = tl.preprocess.distorted_images(images=x, height=24, width=24)
>>> sess.run(tf.initialize_all_variables())
>>> feed_dict={x: X_train[0:batch_size,:,:,:]}
>>> distorted_images, idx = sess.run(distorted_images_op, feed_dict=feed_dict)
>>> tl.visualize.images2d(X_train[0:9,:,:,:], second=2, saveable=False, name='cifar10', dtype=np.uint8, fig_idx=20212)
>>> tl.visualize.images2d(distorted_images[1:10,:,:,:], second=10, saveable=False, name='distorted_images', dtype=None, fig_idx=23012)

For testing data

tensorlayer.preprocess.crop_central_whiten_images(images=None, height=24, width=24)[source]

Crop the central of image, and normailize it for test data.

They are cropped to central of height * width pixels.

Whiten (Normalize) the images.

Parameters:
images : 4D Tensor

The tensor or placeholder of images

height : int

The height for central crop.

width: int

The width for central crop.

Returns:
result : tuple Tensor

(Tensor for distorted images, Tensor for while loop index)

Notes

The first image in ‘central_images’ should be removed.

Examples

>>> X_train, y_train, X_test, y_test = tl.files.load_cifar10_dataset(shape=(-1, 32, 32, 3), plotable=False)
>>> sess = tf.InteractiveSession()
>>> batch_size = 128
>>> x = tf.placeholder(tf.float32, shape=[batch_size, 32, 32, 3])
>>> central_images_op = tl.preprocess.crop_central_whiten_images(images=x, height=24, width=24)
>>> sess.run(tf.initialize_all_variables())
>>> feed_dict={x: X_train[0:batch_size,:,:,:]}
>>> central_images, idx = sess.run(central_images_op, feed_dict=feed_dict)
>>> tl.visualize.images2d(X_train[0:9,:,:,:], second=2, saveable=False, name='cifar10', dtype=np.uint8, fig_idx=20212)
>>> tl.visualize.images2d(central_images[1:10,:,:,:], second=10, saveable=False, name='central_images', dtype=None, fig_idx=23012)