Exemplo n.º 1
0
    print(f'trained in {time.time() - t} sec')
    pre.save_results(loss_hist, loss_val_hist, f1_val_hist, f'{model_name}')

    if args.s_model:
        m_exporter = ModelExporter('fer2013_DatasetD')
        m_exporter.save_nn_model(trained_model, optimizer,
                                 trained_model.get_args())

    if args.s_patterns:
        detected_patterns1 = trained_model.get_detected_patterns1()
        for idx in range(10):
            plt.figure(1, figsize=(20, 10))
            for p in range(trained_model.n_patterns1):
                pattern = detected_patterns1[idx][p].reshape(
                    detected_patterns1.shape[2], detected_patterns1.shape[3])
                patern_np = pattern.detach().numpy().reshape(24, 24)
                plt.subplot(2, 5, 1 + p)
                plt.imshow(patern_np, cmap='gray', interpolation='none')
            pre.save_plt_as_image(plt, f'patterns_1_{idx}')

        detected_patterns2 = trained_model.get_detected_patterns2()
        for idx in range(10):
            plt.figure(1, figsize=(20, 10))
            for p in range(trained_model.n_patterns2):
                pattern = detected_patterns2[idx][p].reshape(
                    detected_patterns2.shape[2], detected_patterns2.shape[3])
                patern_np = pattern.detach().numpy().reshape(12, 12)
                plt.subplot(3, 5, 1 + p)
                plt.imshow(patern_np, cmap='gray', interpolation='none')
            pre.save_plt_as_image(plt, f'patterns_2_{idx}')
Exemplo n.º 2
0
    plt.figure(1, figsize=(30, 20))
    for idx in range(30):
        image = X_test[idx].detach().numpy().reshape(48, 48)
        image2 = X_test_encoded[idx].detach().numpy().reshape(
            int(math.sqrt(n_features_encoded)),
            int(math.sqrt(n_features_encoded)))
        image3 = X_test_decoded[idx].detach().numpy().reshape(48, 48)
        # Call signature: subplot(nrows, ncols, index, **kwargs)
        plt.subplot(10, 9, 1 + idx * 3)
        plt.imshow(image, cmap='hot', interpolation='none')
        plt.subplot(10, 9, 2 + idx * 3)
        plt.imshow(image2, cmap='winter', interpolation='none')
        plt.subplot(10, 9, 3 + idx * 3)
        plt.imshow(image3, cmap='winter', interpolation='none')

    pre.save_plt_as_image(plt, f'encoded_{n_features_encoded}')

    #for idx in range(30):
    #    plt.figure(1, figsize=(10, 5))
    #    plt.subplot(1, 3, 1)
    #    X_test_np = X_test[idx].detach().numpy().reshape(16, 16)
    #    plt.imshow(X_test_np, cmap='hot', interpolation='none')
    #
    #    plt.subplot(1, 3, 2)
    #    test_num_np = X_test_encoded[idx].detach().numpy().reshape(int(math.sqrt(n_features_encoded)), int(math.sqrt(n_features_encoded)))
    #    plt.imshow(test_num_np, cmap='hot', interpolation='none')
    #
    #    plt.subplot(1, 3, 3)
    #    X_test_decoded_np = X_test_decoded[idx].detach().numpy().reshape(16, 16)
    #    plt.imshow(X_test_decoded_np, cmap='hot', interpolation='none')
    #