A custom Keras layer to prevent overfitting
Project description
Stroke
While reading about the concept of dropout, I thought about removing weights between layers instead of removing data. So I created a custom Keras layer called "Stroke", which randomizes a set percentage of weights from the previous layer, sort of replicating what happens when a human has a stroke. The goal of the Stroke layer is to re-initialize weights that have begun to contribute to overfitting.
An implementation of the Stroke layer on an MNIST classification model can be seen below:
from keras.models import Sequential
from keras.layers import Dense, Conv2D, MaxPool2D, Flatten
from kerastroke import Stroke
model = Sequential()
model.add(Conv2D(32, 3, 3, input_shape = (28,28, 1), activation = 'relu'))
model.add(MaxPool2D(pool_size = (2,2)))
model.add(Conv2D(32,3,3, activation = 'relu'))
model.add(MaxPool2D(pool_size = (2,2)))
model.add(Flatten())
model.add(Dense(output_dim = 128, init = 'uniform', activation = 'relu'))
model.add(Stroke(model.get_layer(index=-1)))
model.add(Dense(10, init = 'uniform', activation = 'sigmoid'))
classifier.compile(optimizer = 'adam', loss = 'sparse_categorical_crossentropy', metrics = ['accuracy'])
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
kerastroke-0.1.6.tar.gz
(2.0 kB
view hashes)
Built Distribution
Close
Hashes for kerastroke-0.1.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fde527f3b96f670a5995c1a091b5e790eff0f60e40d2031bbc87fd0673c004cb |
|
MD5 | b51436b33727da70b3a486e0b85cc238 |
|
BLAKE2b-256 | 69c1d24b7b22a80e806bcd0299f7fa0bf93d266e4603033e4cfd0747163183d8 |