简体   繁体   中英

How to save a MASK RCNN model after training?

I am using matterport repository to train MASK RCNN on a custom dataset. I have been successful in training. Now I want to save the trained model and use it in a web application to detect objects. How do I save the mask rcnn model after training? Please guide me.

The link of the repository:

https://github.com/matterport/Mask_RCNN

Based on this discussion on GitHub , it appears that trained model or weights of matterport/Mask RCNN can be saved as a JSON file in a manner similar to those trained via standard Keras :

import keras
import json

def save_model(trained_model, out_fname="model.json"):
    jsonObj = trained_model.keras_model.to_json()
    with open(out_fname, "w") as fh:
        fj.write(jsonObj)
 
save_model(model, "mymodel.json")

Update: If you run into the error related to thread-like object, you might find this post helpful...

在“加载模型”主题下的Inspect_model.ipynb笔记本中,您可以在以推理模式加载模型后保存它。

在 Mask_RCNN/logs 文件夹中生成一个文件夹

I am not sure if we really need to save the whole model again since normally when we used the matterport git we just train new weights on the existing architecture and doesnt make changes to the architecture. When we used this for a pet project , post training - we defined a new model as the MASK RCNN object (from mrcnn.model import MaskRCNN) with the parameter mode as inference and then loaded the newly trained weights model.load_weights('<logpath/trainedweights.h5>', by_name=True)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM