KerasFileEditor
類別keras.saving.KerasFileEditor(filepath)
用於檢查、編輯和重新儲存 Keras 權重檔案的工具。
當您在對模型架構進行變更後,需要調整舊的已儲存權重檔案時,您會發現這個類別非常有用。
參數
範例
editor = KerasFileEditor("my_model.weights.h5")
# Displays current contents
editor.summary()
# Remove the weights of an existing layer
editor.delete_object("layers/dense_2")
# Add the weights of a new layer
editor.add_object("layers/einsum_dense", weights={"0": ..., "1": ...})
# Save the weights of the edited model
editor.resave_weights("edited_model.weights.h5")
summary
方法KerasFileEditor.summary()
印出已開啟檔案的權重結構。
compare
方法KerasFileEditor.compare(reference_model)
將已開啟的檔案與參考模型進行比較。
這個方法會列出目前已開啟的檔案與提供的參考模型之間的所有不匹配之處。
參數
回傳
'status'
、'error_count'
、'match_count'
。狀態可以是 'success'
或 'error'
。'error_count'
是找到的不匹配數量。'match_count'
是找到的匹配權重數量。save
方法KerasFileEditor.save(filepath)
儲存已編輯的權重檔案。
參數
.weights.h5
檔案。rename_object
方法KerasFileEditor.rename_object(object_name, new_name)
重新命名檔案中的物件 (例如:層)。
參數
"dense_2"
或 "layers/dense_2"
)。delete_object
方法KerasFileEditor.delete_object(object_name)
從檔案中移除物件 (例如:層)。
參數
"dense_2"
或 "layers/dense_2"
)。add_object
方法KerasFileEditor.add_object(object_path, weights)
在檔案中新增一個新物件 (例如:層)。
參數
"layers/dense_2"
)。{"0": kernel_value, "1": bias_value}
。delete_weight
方法KerasFileEditor.delete_weight(object_name, weight_name)
從現有物件中移除權重。
參數
"dense_2"
或 "layers/dense_2"
)。"0"
)。add_weights
方法KerasFileEditor.add_weights(object_name, weights)
在現有物件中新增一個或多個新權重。
參數
"dense_2"
或 "layers/dense_2"
)。{"0": kernel_value, "1": bias_value}
。