# %% Read Data image_name = Args.image # get the images name image_path = Args.path # get the path of the images image = mpimg.imread(image_path + image_name) # read the images plt.ion() 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()
Args = parser.parse_args() # the Arguments #%% Main Function if __name__ == '__main__': # %% Read Data image_name = Args.image # get the images name 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
# %% Read Data image_name = Args.image # get the images name image_path = Args.path # get the path of the images image = mpimg.imread(image_path + image_name) # read the images plt.ion() 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) shuffle_image, index0 = processing.shuffle(shuffle_image, axis=1) shuffle_image, index0 = processing.shuffle(shuffle_image, axis=0) shuffle_image, index0 = processing.shuffle(shuffle_image, axis=1) shuffle_image, index0 = processing.shuffle(shuffle_image, axis=0) shuffle_image, index0 = processing.shuffle(shuffle_image, axis=1) plt.subplot(1, 3, 3) # show plt.imshow(shuffle_image, cmap='gray') fluency = score.fluency(shuffle_image) plt.title('shuffle %d' % fluency)
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) plt.title('Original'), plt.axis('off') plt.subplot(1, 3, 2) # show datasets.demo_show(data_shuffled[num_index], datasets_name) plt.title('Shuffled'), plt.axis('off') plt.subplot(1, 3, 3) # show datasets.demo_show(data_recover[num_index], datasets_name)