Skip to content

Instantly share code, notes, and snippets.

@joelthchao
Last active September 16, 2017 14:07
Show Gist options
  • Save joelthchao/c40a47180a02cf1b671916a7f3583c60 to your computer and use it in GitHub Desktop.
Save joelthchao/c40a47180a02cf1b671916a7f3583c60 to your computer and use it in GitHub Desktop.
Dead neuron
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