'Instantiate Keras model with some weights before training
Solution 1:[1]
here a dummy example to initialize the model with some weights (random, zero or whatever)
def base_model(xx):
x = Dense(32)(xx)
x = Dense(8)(x)
return Model(xx,x)
inp = Input((32,32,3))
x = base_model(inp)
x = GlobalAveragePooling2D()(x.output)
x = Dropout(0.3)(x)
out = Dense(10, activation='softmax')(x)
model = Model(inp,out)
model.summary()
# set weight with random number from a uniform... you can do the same also with zeros...
model.set_weights([np.random.uniform(0,1, i.shape) for i in model.get_weights()])
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Marco Cerliani |