The answer given by @Chris_K should work - model.get_weights()
prints correct initialization weights before fit is called. Try running this code as a sanity check - it should print two matrices (for two layers) that are non-zero, then print two matrices that are zero:
from keras.models import Sequential
from keras.layers import Dense
import keras
import numpy as np
X = np.random.randn(10,3)
Y = np.random.randn(10,)
# create model
model1 = Sequential()
model1.add(Dense(12, input_dim=3, activation='relu'))
model1.add(Dense(1, activation='sigmoid'))
print(model1.get_weights())
# create model
model2 = Sequential()
model2.add(Dense(12, input_dim=3, kernel_initializer='zero', activation='relu'))
model2.add(Dense(1, kernel_initializer='zero', activation='sigmoid'))
print(model2.get_weights())
Here's the output I'm seeing:
[
array([[-0.08758801, -0.20260376, 0.23681498, -0.59153044, -0.26144034,
0.48446459, -0.02285194, 0.0874517 , 0.0555284 , -0.14660612,
0.05574059, -0.14752924],
[ 0.20496374, -0.4272995 , 0.07676286, -0.38965166, 0.47710329,
-0.26640627, -0.33820981, -0.48640659, 0.11153179, -0.01180136,
-0.52833426, 0.56279379],
[-0.12849617, 0.2982074 , 0.38974017, -0.58133346, -0.09883761,
0.56037289, 0.57482034, 0.08853614, 0.14282584, -0.52498174,
-0.35414279, -0.49750996]], dtype=float32), array([ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], dtype=float32), array([[-0.65539688],
[-0.58926439],
[ 0.6232332 ],
[-0.6493122 ],
[ 0.57437611],
[-0.42971158],
[ 0.66621709],
[-0.17393446],
[ 0.57196724],
[-0.01042461],
[ 0.32426012],
[-0.08326346]], dtype=float32), array([ 0.], dtype=float32)]
[array([[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]], dtype=float32), array([ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.], dtype=float32), array([[ 0.],
[ 0.],
[ 0.],
[ 0.],
[ 0.],
[ 0.],
[ 0.],
[ 0.],
[ 0.],
[ 0.],
[ 0.],
[ 0.]], dtype=float32), array([ 0.], dtype=float32)]