The Knowledge
MNIST Pixel Knowledge
The primary dataset employed right here is the standard MNIST pixel knowledge, comprised by hand-written numbers. Right here, the background is black and the digits are white.
Anomalous MNIST Pixel Knowledge
To check the brand new process and examine it to the standard one, I created 4 easy varieties of anomalous knowledge.
The aim was to check every technique’s detection capabilities throughout a small spectrum of noise variations, incrementally intensified from one anomaly kind to the following.
The noise fee will increase from the primary to the fourth kind of anomalous knowledge. As you’ll be able to see within the determine beneath, within the first and second kinds of knowledge, the noise isn’t even detectable to the bare eye, whereas within the third kind, you’ll be able to already spot some white pixels.
Mannequin-state knowledge
Whereas MNIST pixel knowledge, with its hand-written digits in opposition to a stark backdrop, offers a traditional basis for anomaly detection, we’re attempting one thing else. It’s a little bit of a leap, taking us proper into the core of the skilled ANN to see what the neurons are as much as. This might give us a complete special approach on recognizing anomalies.
As talked about, this mannequin state knowledge is comprised by the state of the neurons in an ANN when skilled with MNIST knowledge. As such, to generate this knowledge, we begin with coaching a easy ANN with MNIST pixel knowledge, each with regular and anomalous knowledge (the anomalous are comprised by the noisy knowledge confirmed earlier than in Determine 2).
We then carry out the standard: cut up the info into coaching and testing, after which we match the ANN mannequin:
mannequin.match(X_train,Y_cat_train,epochs=8, validation_data=(X_test, y_cat_test))
After that, we need to retrieve the names of the layers in mannequin and retailer them in an inventory:
checklist(map(lambda x: x.title, mannequin.layers))
Lastly, we create a brand new mannequin that takes the identical enter as the unique mannequin however produces output from a selected layer referred to as “dense”:
intermediate_layer_model=Mannequin(inputs=mannequin.enter, outputs=mannequin.get_layer("dense").output)
That is helpful for extracting data from intermediate layers of a neural community.
Let’s check out this model-state knowledge:
model_state_data_layer1=pd.read_csv("first_layer_dense.csv",header=None)
model_state_data_layer2=pd.read_csv("second_layer_dense.csv",header=None)model_state_data_layer1.head(4)
The model-state knowledge of the primary neural layer is comprised by 32 columns and 4 rows.
With just some traces of code, we’re capable of extract knowledge from the intermediate layers of a neural community.
To review the effectiveness of the brand new technique, I’ll be utilizing knowledge from each the first and second layers of the neural community.