예제 #1
0
def plot_multiple_models(images):
    model_name = 'syn_model'
    fig, axs = plt.subplots(3,3)

    fig.suptitle('Linear ranges for multiple models')
    # Some example data to display
    x = np.linspace(0, 2 * np.pi, 400)
    y =  np.sin(x ** 2)
    iter = 0
    for i in range(3):
        for j in range(3):
            model = FourLayerFNN()
            model.load_state_dict(torch.load(model_name+str(iter)+'.pkl'))
            for image in images:
                image = image.view(-1, 2)
                coefficients_file_name = calculate_ineuqality_coefficients(model, image)
                calculate_feasible_range(coefficients_file_name, axs[i][j])
            axs[i][j].set_xlim((-1.5, 1.5))
            axs[i][j].set_ylim((-1.5, 1.5))
            axs[i][j].set_title('model'+str(iter))
            axs[i][j].set(xlabel='x', ylabel='y')
            axs[i][j].label_outer()
            plot_unit_circle(axs[i][j])
            iter += 1
    plt.show()
예제 #2
0
def plot_multiple_models(x, images):

    model_name = 'syn_model'
    models = []
    fig, axes = plt.subplots(3, 3)
    fig.suptitle('Linear ranges for multiple models')
    for i, ax in enumerate(axes.flat):
        model = FourLayerFNN()
        model.load_state_dict(torch.load(model_name + str(i) + '.pkl'))
        plot_one_model(ax, model, x, images)
        ax.set(xlabel='x', ylabel='y')
        ax.set_xlim((-1.5, 1.5))
        ax.set_ylim((-1.5, 1.5))
        ax.set_title('model' + str(i))
        ax.label_outer()
    plt.show()
예제 #3
0
def plot_lines(weight_bias_states):
    for row in weight_bias_states[:3, :]:
        a, b, c, _ = row
        #        print('a: ', a, '; b:', b, '; c:', c)
        plot_line(a, b, c)


def plot_line(a, b, c):
    x = np.linspace(-1.5, 1.5, 1000)
    y = -(a * x + c) / b
    plt.plot(x, y)


if __name__ == '__main__':
    model = FourLayerFNN()
    model.load_state_dict(torch.load('syn_model.pkl'))

    # load test data, here is same to train_data
    test_loader = torch.utils.data.DataLoader(MyCustomDataset(
        './data/dataset.csv',
        transform=transforms.Compose([transforms.ToTensor()])),
                                              batch_size=1,
                                              shuffle=True)
    #    test(model, test_loader)
    images = test_loader.dataset.images
    #    print(image.shape)
    #  _, outputs = model(image)
    #   _, prediction = torch.max(outputs.data, 1)
    #     print(prediction)
    #    check_states(model, image)