这是一个用一些权重(随机、零或其他)初始化模型的虚拟示例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()])