答案 0 :(得分:1)
这是一个虚拟示例,用于使用一些权重(随机,零或其他任何值)初始化模型
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()])