Ejemplo n.º 1
0
    image_path = Args.path  # get the path of the images
    image = mpimg.imread(image_path + image_name)  # read the images
    # change the axis
    image_f = image.transpose(2, 0, 1)
    image_f = image_f[np.newaxis, ...]
    # show
    plt.ion()
    plt.figure(1)  # show
    plt.subplot(1, 2, 1)
    fluency = score.fluency(image_f)
    plt.imshow(image_f[0].transpose(1, 2, 0))
    plt.axis('off')
    plt.title('%s %d' % (image_name, fluency))

    # %% Shuffle
    shuffle_image, index0 = processing.shuffle(image_f, axis=2)
    index0 = np.array(index0)  # change to ndarray
    plt.subplot(1, 2, 2)  # show
    plt.imshow(shuffle_image[0].transpose(1, 2, 0))
    fluency = score.fluency(shuffle_image)
    plt.title('shuffle %d' % fluency)
    plt.axis('off')
    plt.draw()

    # %% SVD image sort
    recover = model.ImageRecover(shuffle_image)
    new_image1, index = recover.svd_imsort()
    # show
    plt.figure(2)
    plt.imshow(new_image1[0].transpose(1, 2, 0))
    fluency = score.fluency(new_image1)
Ejemplo n.º 2
0
    plt.figure(1)  # show
    plt.subplot(1, 3, 1)
    plt.imshow(image)
    plt.axis('off')
    plt.title(image_name)

    # %% Gray
    gray_image = processing.rgb2gray(image)
    plt.subplot(1, 3, 2)  # show
    plt.imshow(gray_image, cmap='gray')
    fluency = score.fluency(gray_image)
    plt.axis('off')
    plt.title('%s-Gray %d' % (image_name, fluency))

    # %% Shuffle
    shuffle_image, index0 = processing.shuffle(gray_image, axis=0)
    index0 = np.array(index0)  # change to ndarray
    plt.subplot(1, 3, 3)  # show
    plt.imshow(shuffle_image, cmap='gray')
    fluency = score.fluency(shuffle_image)
    plt.title('shuffle %d' % fluency)
    plt.axis('off')
    plt.draw()
    # %% SVD image sort
    recover = model.ImageRecover(shuffle_image)
    new_image1, index = recover.svd_imsort()
    new_image1 = new_image1[0][0]
    # show
    plt.figure(2)
    plt.imshow(new_image1, cmap='gray')
    fluency = score.fluency(new_image1)
Ejemplo n.º 3
0
     cnn2 = models.CNN_MNIST1().cuda() if Args.cuda else models.CNN_MNIST1()
 elif datasets_name == 'CIFAR-10':
     print('Using the CIFAR-10 dataset.')
     data_train, data_test = datasets.CIFAR10(True)
     num_index = [0, 1, 2, 3, 4]  # save 0,1,2,3,4,5,6,7,8,9
     axis = 2
     data = data_train.data[:1000]
     data = np.array(data).transpose(0, 3, 1, 2)
     # networks
     data_loader_train = torch.utils.data.DataLoader(dataset=data_train, batch_size=Args.batch_size, shuffle=True)
     data_loader_test = torch.utils.data.DataLoader(dataset=data_test, batch_size=Args.batch_size, shuffle=True)
     cnn0 = models.CNN_CIFAR10().cuda() if Args.cuda else models.CNN_CIFAR10()
     cnn1 = models.CNN_CIFAR10().cuda() if Args.cuda else models.CNN_CIFAR10()
     cnn2 = models.CNN_CIFAR10().cuda() if Args.cuda else models.CNN_CIFAR10()
 #%% Shuffle and Recover
 data_shuffled, index0 = processing.shuffle(data, axis=axis)
 index0 = np.array(index0) # change to ndarray
 best_index = [float('inf'), []]
 # direct greed
 recover = model.ImageRecover(data_shuffled)
 data_recover, index = recover.direct_greed()
 fluency = score.fluency(data_recover)
 k_coeff, k_distance = score.Kendal(index0[index], range(len(index)))
 if fluency < best_index[0]:
     best_index[1] = index
     best_index[0] = fluency
 if Args.show:
     plt.ion()
     plt.figure(1)
     plt.subplot(1, 3, 1) # show
     datasets.demo_show(data[num_index], datasets_name)