<jupyter_start><jupyter_text>Plotting the filters<jupyter_code>import sys; sys.path.insert(0, "..")
import tensorflow as tf
from tensorflow import keras
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
gpu_devices = tf.config.experimental.list_physical_devices("GPU")
for device in gpu_devices:
    tf.config.experimental.set_memory_growth(device, True)
# modelPath = ".model_checkpoint/validationset/bps-augmentednet-rmsproplr01-210526T143649/94-4.336-0.7938.hdf5" # best accuracy
# modelPath = ".model_checkpoint/prototyping/dropout-210528T215602/82-4.383-0.7917.hdf5" # with dropout
# modelPath = ".model_checkpoint/validationset/rmsprop-lr0001-200epochs-210529T090623/171-4.237-0.7809.hdf5" # low learning rate, 200 epochs
# modelPath = ".model_checkpoint/testset/haydnop20-augmentednet-alldata-210513T195252/23-3.821-0.8027.hdf5" # all data, evaluated on haydn
# modelPath = ".model_checkpoint/validationset/rmsprop-learningschedule-piecewise-210530T101943/55-4.175-0.7928.hdf5" # piecewise learning schedule
# modelPath = ".model_checkpoint/validationset/rmsprop-learningschedule-piecewise-stair-210530T170008/44-4.311-0.7949.hdf5" # piecewise stair
# modelPath = ".model_checkpoint/validationset/wirwtc-rotatinglrschedule-210530T215055/55-5.002-0.7453.hdf5" # wirwtc rotating lr
# modelPath = ".model_checkpoint/validationset/bps-lr01-0001-210530T233203/55-4.109-0.7956.hdf5" # bps, 01 to 0001
modelPath = ".model_checkpoint/validationset/bps-lr01-0001-210530T233203/46-4.088-0.7950.hdf5" # same as before, but lower loss instead of highest accuracy<jupyter_output><empty_output><jupyter_text>model = keras.models.load_model(modelPath)<jupyter_code>filters, biases = model.layers[2].get_weights()
filters = (filters - filters.min()) / (filters.max() - filters.min())<jupyter_output><empty_output><jupyter_text>First filter of first convolutional layer<jupyter_code>sns.heatmap(filters[0], cmap="inferno")<jupyter_output><empty_output><jupyter_text>Exploring outputs of model<jupyter_code>model.summary()
[l.name for l in model.layers]
model.inputs
newModel = keras.Model(inputs=model.inputs[0], outputs=model.layers[6].output)
newModel.layers
exampleInput = np.zeros((640, 19))
spellings = {
    (0, 10): "C--", (0, 11): "C-", (0, 0): "C", (0, 1): "C#", (0, 2): "C##",
    (1, 0): "D--", (1, 1): "D-", (1, 2): "D", (1, 3): "D#", (1, 4): "D##",
    (2, 2): "E--", (2, 3): "E-", (2, 4): "E", (2, 5): "E#", (2, 6): "E##",
    (3, 3): "F--", (3, 4): "F-", (3, 5): "F", (3, 6): "F#", (3, 7): "F##",
    (4, 5): "G--", (4, 6): "G-", (4, 7): "G", (4, 8): "G#", (4, 9): "G##",
    (5, 7): "A--", (5, 8): "A-", (5, 9): "A", (5, 10): "A#", (5, 11): "A##",
    (6, 9): "B--", (6, 10): "B-", (6, 11): "B", (6, 0): "B#", (6, 1): "B##",
}
numberOfSpellings = len(spellings)

for idx, (letter, pc) in enumerate(spellings.keys()):
    exampleInput[idx][letter] = 1
    exampleInput[idx][7 + pc] = 1

exampleInput = exampleInput.reshape((1, 640, 19))
plt.figure(figsize=(20,10))
plt.pcolormesh(exampleInput[0][:numberOfSpellings+5].T, edgecolors="k")
activations = newModel.predict(exampleInput)[0][:numberOfSpellings+5].T
activations[0]
activations.shape
plt.figure(figsize=(20,10))
plt.pcolormesh(activations, edgecolors="k", cmap="inferno")
for fidx, f in enumerate(activations):
    threshold = 0.5
    idxAct = [(idx, act) for idx, act in enumerate(f[:numberOfSpellings]) if act > threshold]
    idxAct.sort(key=lambda x: x[1], reverse=True)
    highActivations = [x[0] for x in idxAct]
#     print(highActivations)
    noteSpellings = list(spellings.values())
    notesActivated = [noteSpellings[idx] for idx in highActivations]
    print(f"Filter{fidx}: {notesActivated}")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1917808219178082, 'fraction_numerical': 0.09696481332258931, 'mean_word_length': 5.333333333333333, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '546322', 'license': 'MIT', 'n_tokens_mistral': 1702, 'n_tokens_neox': 1502, 'n_words': 290, 'path': 'notebooks/VisualizingFilters.ipynb', 'repo_name': 'napulen/AugmentedNet', 'size': '3723'}