예제 #1
0
def _load_data():
    # load CIFAR10 data
    (target_data, _), (test_target_data, _) = cifar10.load_data()

    # input image dimensions
    # we assume data format "channels_last"
    rows = target_data.shape[1]
    cols = target_data.shape[2]
    channels = target_data.shape[3]

    # convert color train and test images to gray
    source_data = other_utils.rgb2gray(target_data)
    test_source_data = other_utils.rgb2gray(test_target_data)

    # display color version of test images
    imgs = test_target_data[:100]
    title = 'CIFAR10 test color images (Ground  Truth)'
    img_shape = (rows, cols, channels)
    filename = 'test_color.png'
    other_utils.display_images(imgs,
                               img_shape=img_shape,
                               filename=filename,
                               title=title)

    # display grayscale version of test images
    imgs = test_source_data[:100]
    title = 'CIFAR10 test gray images (Input)'
    filename = 'test_gray.png'
    other_utils.display_images(imgs,
                               img_shape=(rows, cols, 1),
                               filename=filename,
                               title=title)

    # normalize output train and test color images
    target_data = target_data.astype('float32') / 255
    test_target_data = test_target_data.astype('float32') / 255

    # normalize input train and test grayscale images
    source_data = source_data.astype('float32') / 255
    test_source_data = test_source_data.astype('float32') / 255

    # reshape images to row x col x channels
    # for CNN output/validation
    target_data = target_data.reshape(target_data.shape[0], rows, cols,
                                      channels)
    test_target_data = test_target_data.reshape(test_target_data.shape[0],
                                                rows, cols, channels)

    # reshape images to row x col x channel for CNN input
    source_data = source_data.reshape(source_data.shape[0], rows, cols, 1)
    test_source_data = test_source_data.reshape(test_source_data.shape[0],
                                                rows, cols, 1)

    # source data, target data, test_source data
    data = (source_data, target_data, test_source_data, test_target_data)
    source_shape = (rows, cols, 1)
    target_shape = (rows, cols, channels)
    shapes = (source_shape, target_shape)

    return data, shapes
def load_data():
    # load CIFAR10 data
    (x_train, _), (x_test, _) = cifar10.load_data()

    # input image dimensions
    # we assume data format "channels_last"
    rows = x_train.shape[1]
    cols = x_train.shape[2]
    channels = x_train.shape[3]

    # convert color train and test images to gray
    x_train_gray = other_utils.rgb2gray(x_train)
    x_test_gray = other_utils.rgb2gray(x_test)

    # display color version of test images
    imgs = x_test[:100]
    title = 'Test color images (Ground  Truth)'
    img_shape = (rows, cols, channels)
    filename = 'test_color.png'
    other_utils.display_images(imgs,
                               img_shape=img_shape,
                               filename=filename,
                               title=title)

    # display grayscale version of test images
    imgs = x_test_gray[:100]
    title = 'Test gray images (Input)'
    filename = 'test_gray.png'
    other_utils.display_images(imgs,
                               img_shape=(rows, cols, 1),
                               filename=filename,
                               title=title)

    # normalize output train and test color images
    x_train = x_train.astype('float32') / 255
    x_test = x_test.astype('float32') / 255

    # normalize input train and test grayscale images
    x_train_gray = x_train_gray.astype('float32') / 255
    x_test_gray = x_test_gray.astype('float32') / 255

    # reshape images to row x col x channels
    # for CNN output/validation
    x_train = x_train.reshape(x_train.shape[0], rows, cols, channels)
    x_test = x_test.reshape(x_test.shape[0], rows, cols, channels)

    # reshape images to row x col x channel for CNN input
    x_train_gray = x_train_gray.reshape(x_train_gray.shape[0], rows, cols, 1)
    x_test_gray = x_test_gray.reshape(x_test_gray.shape[0], rows, cols, 1)

    # source data, target data, test_source data
    data = (x_train_gray, x_train, x_test_gray)
    gray_shape = (rows, cols, 1)
    color_shape = (rows, cols, channels)
    # source shape, target shape
    shapes = (gray_shape, color_shape)

    return data, shapes
예제 #3
0
def load_cifar10():
    (B_data, _), (test_B_data, _) = cifar10.load_data()
    A_data = other_utils.rgb2gray(B_data)
    test_A_data = other_utils.rgb2gray(test_B_data)
    A_data = A_data[:, :, :, np.newaxis]
    test_A_data = test_A_data[:, :, :, np.newaxis]
    data = (A_data, B_data, test_A_data, test_B_data)
    titles = ('CIFAR10 test_A_data images', 'CIFAR10 test_A_data images')
    return other_utils.load_data(data, titles)
예제 #4
0
def load_data():
    # load CIFAR10 data
    (target_data, _), (test_target_data, _) = cifar10.load_data()

    # input image dimensions
    # we assume data format "channels_last"
    rows = target_data.shape[1]
    cols = target_data.shape[2]
    channels = target_data.shape[3]

    # convert color train and test images to gray
    source_data = other_utils.rgb2gray(target_data)
    test_source_data = other_utils.rgb2gray(test_target_data)
    # reshape images to row x col x channel for CNN input
    source_data = source_data.reshape(source_data.shape[0], rows, cols, 1)
    test_source_data = test_source_data.reshape(test_source_data.shape[0],
                                                rows, cols, 1)

    # source data, target data, test_source data
    data = (source_data, target_data, test_source_data, test_target_data)
    filenames = ('cifar10_test_source.png', 'cifar10_test_target.png')
    titles = ('CIFAR10 test source images', 'CIFAR10 test target images')

    return other_utils.load_data(data, titles, filenames)
import numpy as np
from tensorflow.keras.datasets import cifar10
import matplotlib.pyplot as plt
import other_utils
import math

# load dataset
(x_train, y_train), (x_test, y_test) = cifar10.load_data()

# sample cifar10 from train dataset
size = 1
side = int(math.sqrt(size))
indexes = np.random.randint(0, x_train.shape[0], size=size)
images = x_train[indexes]
gray_images = other_utils.rgb2gray(x_train[indexes])

# plot color cifar10
plt.figure(figsize=(side, side))
for i in range(len(indexes)):
    plt.subplot(side, side, i + 1)
    image = images[i]
    plt.imshow(image)
    plt.axis('off')

plt.savefig("cifar10-color-samples.png")
plt.show()
plt.close('all')

# plot gray cifar10
plt.figure(figsize=(side, side))