コード例 #1
0
    plt.xticks(range(CLASSES))
    plt.ylabel('Actual Value')
    plt.yticks(range(CLASSES))
    plt.colorbar()
    plt.tight_layout()
    plt.savefig(str(plot_name), bbox_inches='tight', pad_inches=0)
    plt.close()


# Seed for consistency
np.random.seed(SEED)
# Load best weights back up and make confusion matrices
classifier = Classifier(input_size=INPUTS)
weight_files = sorted(CLASS_MODEL_DIR.iterdir())
for weight_file in weight_files[:-1]:
    classifier.addLayer(file_name=weight_file, output=False)
classifier.addLayer(file_name=weight_files[-1], output=True)
train_conf_title = 'Train Confusion Matrix'
makeConfMat(classifier,
            train_data,
            train_labels,
            CLASS_TRAIN_CONF,
            title=train_conf_title)
test_conf_title = 'Test Confusion Matrix'
makeConfMat(classifier,
            test_data,
            test_labels,
            CLASS_TEST_CONF,
            title=test_conf_title)
test_err = classifier.eval(test_data, test_labels)
print(f'Test error: {test_err:0.3f}')
コード例 #2
0
    dir_name : str
        Name of the directory to save the images to
    """
    for i, w in enumerate(weights):
        # Remove bias and normalize on [0, 1]
        w = w[1:]
        w -= w.min()
        w /= (w.max() - w.min())
        w_name = dir_name.joinpath(f'feat_{i:02d}.png')
        matplotlib.image.imsave(str(w_name),
                                w.reshape(28, 28, order='F'),
                                cmap='Greys_r')


# Seed for consistency
np.random.seed(SEED)
# Load best weights back up for each model
autoencoder = Autoencoder(input_size=INPUTS)
for weight_file in sorted(AUTO_MODEL_DIR.iterdir()):
    autoencoder.addLayer(file_name=weight_file)
classifier = Classifier(input_size=INPUTS)
for weight_file in sorted(CLASS_MODEL_DIR.iterdir()):
    classifier.addLayer(file_name=weight_file)
# Neurons to check
neuron_count = classifier.layers[0].num_neurons
neurons = np.random.choice(np.arange(neuron_count), 20, replace=False)
class_weights = classifier.layers[0].w[neurons]
drawFeatures(class_weights, CLASS_FEAT_DIR)
auto_weights = autoencoder.layers[0].w[neurons]
drawFeatures(auto_weights, AUTO_FEAT_DIR)