I'm training a simple CNN on the MNIST dataset. This is form a tutorial (https://machinelearningmastery.com/how-to-develop-a-convolutional-neural-network-from-scratch-for-mnist-handwritten-digit-classification/).
def define_model():
model = Sequential()
model.add(Conv2D(32, (3, 3), activation='relu', kernel_initializer='he_uniform', input_shape=(28, 28, 1)))
model.add(MaxPooling2D((2, 2)))
model.add(Flatten())
model.add(Dense(100, activation='relu', kernel_initializer='he_uniform'))
model.add(Dense(10, activation='softmax'))
# compile model
opt = SGD(lr=0.01, momentum=0.9)
model.compile(optimizer=opt, loss='categorical_crossentropy', metrics=['accuracy'])
return model
I actually want to be able to step through the training process. So starting with an example from the dataset:
I want to see the 32 initialised kernels and the resulting output of the convolutions. Then maybe I want to see these things again a bunch of iterations later when the model has started to converge. I want to then be able to see the outputs of MaxPooling, Flatten, and the Dense layers.
So my question is not around how to visualise things (I'll use print
and pypolot.imshow
for that), but more about how I can code it up so that I can look into all of these things wherever I want.