我有 Keras 模型:預訓練的 CV 模型 + 頂部添加的一些層我希望能夠在 model.fit 之前進行 model.predict問:如何從屏幕截圖中實例化帶有一些權重(隨機、零或其他)的模型
1 回答

森欄
TA貢獻1810條經驗 獲得超5個贊
這是一個用一些權重(隨機、零或其他)初始化模型的虛擬示例
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()])
添加回答
舉報
0/150
提交
取消