deep-learning - 如何在 Detectron2 中保存和加载自定义数据集的模型?

标签 deep-learning pytorch detectron

我尝试使用以下方法保存和加载模型:
所有键都已映射,但输出中没有预测
#1

from detectron2.modeling import build_model
model = build_model(cfg)
torch.save(model.state_dict(), 'checkpoint.pth') 
model.load_state_dict(torch.load(checkpoint_path,map_location='cpu'))
我也尝试使用官方文档来做,但无法理解输入格式部分
from detectron2.checkpoint import DetectionCheckpointer
DetectionCheckpointer(model).load(file_path_or_url)  # load a file, usually from cfg.MODEL.WEIGHTS
checkpointer = DetectionCheckpointer(model, save_dir="output")
checkpointer.save("model_999")  # save to output/model_999.pth

最佳答案

cfg = get_cfg()
cfg.merge_from_file(model_zoo.get_config_file('COCO-Detection/faster_rcnn_R_101_FPN_3x.yaml'))
cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.5 # Set threshold for this model
cfg.MODEL.WEIGHTS = '/content/model_final.pth' # Set path model .pth
cfg.MODEL.ROI_HEADS.NUM_CLASSES = 1
predictor = DefaultPredictor(cfg)
我加载自定义模型的代码有效。

关于deep-learning - 如何在 Detectron2 中保存和加载自定义数据集的模型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63166152/

相关文章:

python - 检查输入 : expected conv2d_input to have 4 dimensions, 但获得形状为 (28708, 1) 的数组时出错

python - Keras MSE 定义

python - 为什么我的模型准确率停留在 ~32%?

python - keras - 获取每个类别的概率

python - torch.autograd.Variable 的目的是什么?

tensorflow - keras.preprocessing.text.Tokenizer 在 Pytorch 中等效吗?

python - 在torch.distributed中,如何正确平均不同GPU上的梯度?

python - 在部分 COCO 数据集上训练 Detectron2

pytorch - 如何避免在推理过程中得到重叠的关键点?

python-3.x - 如何计算 Detectron2 中的并集交集?