Example #1
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)
    plt.axis('off')
    plt.draw()

    #%%
    plt.figure(2)
    temp_image = shuffle_image
    for i in range(10):
        recover = model.ImageRecover(temp_image)
        t_image = []
        fluency = []
        new_image3, index = recover.direct_greed()
        t_image.append(new_image3[0][0])
        fluency.append(score.fluency(t_image[-1]))
        for j in range(40):
            new_image3, index = recover.svd_greed(j + 1)
            t_image.append(new_image3[0][0])
            fluency.append(score.fluency(t_image[-1]))
        pos = np.array(fluency).argmin()
        print(pos)
        temp_image = t_image[pos]
        plt.subplot(2, 5, i + 1)
        plt.title('greed %d' % (fluency[pos]))
        plt.imshow(temp_image, cmap='Greys_r')
Example #2
0
    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)
    k_coeff, k_distance = score.Kendal(index0[index], range(len(index)))
    plt.title('SVD_imsort %d %.2f' % (fluency, k_coeff))
    plt.axis('off')
    plt.draw()

    # %% SVD greed
    plt.figure(3)
    for i in range(1, 21):
        plt.subplot(4, 5, i)
Example #3
0
     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)
     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')