Last active
September 16, 2017 14:07
-
-
Save joelthchao/c40a47180a02cf1b671916a7f3583c60 to your computer and use it in GitHub Desktop.
Dead neuron
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import keras.backend as K | |
from keras.initializers import Constant | |
from keras.layers import Input, Dense | |
from keras.models import Model | |
from keras.optimizers import SGD | |
b_init = -0.5 # [-1, -0.75, -0.5, -0.25, 0, 0.25, 0.5, 0.75, 1] | |
net_input = Input(shape=(4,)) | |
net = Dense(2, activation='relu', bias_initializer=Constant(b_init))(net_input) | |
net = Dense(1, activation='sigmoid')(net) | |
model = Model(net_input, net) | |
model.compile(optimizer=SGD(0.5), loss='binary_crossentropy', metrics=['accuracy']) | |
""" | |
_b_init = K.eval(model.trainable_weights[1][0]) | |
assert abs(_b_init - b_init) < 0.001 | |
""" | |
result = model.fit(x, y, epochs=10) | |
acc = result.history['acc'][-1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment