pytorch - 在 google colab 上使用 pytorch 在detectron2 中进行对象检测。重用已经训练的模型或导入现有的训练模型并预测对象
问题描述
- 首先,我下载了训练模型的输出文件夹,并将其导入到 google colab 服务器上的一个新项目中。
- 在没有训练模型的新项目中,我
model_final.pth
将现有输出文件夹的路径指定为cfg.MODEL.WEIGHTS
=/content/output/model_final.pth。但进入无限循环。3.我改变了模型的权重cfg.MODEL.WEIGHTS = "detectron2://COCO-Detection/faster_rcnn_R_101_FPN_3x/137851257/model_final_f6e8b1.pkl"
。但它仍然不能预测物体。 - 我更改了模型权重路径并提供了先前训练的模型指标
JSON
文件,但它仍然无法正常工作cfg.MODEL.WEIGHTS=/content/output/metrics.json 5.By using DetectionCheckpointer(model).load("/content/output/model_final.pth") DetectionCheckpointer(model).load("detectron2://COCO-Detection/faster_rcnn_R_101_FPN_3x/137851257/model_final_f6e8b1.pkl")
,它给出了错误模型未定义。这是什么model_final.pkl
文件?我们从哪里得到的?我们应该怎么做才能导入现有的火车模型并预测新项目中的对象?
cfg.MODEL.WEIGHTS = os.path.join(cfg.OUTPUT_DIR, "model_final.pth")
cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.5
cfg.DATASETS.TEST = ("microcontroller_test", )
predictor = DefaultPredictor(cfg)
上面的代码进入一个无限循环
DetectionCheckpointer(model).load("/content/output/model_final.pth")
DetectionCheckpointer(model).load("detectron2://COCO-Detection/faster_rcnn_R_101_FPN_3x/137851257/model_final_f6e8b1.pkl")
错误:
NameError Traceback (most recent call last)
<ipython-input-12-69f2a7846756> in <module>()
----> 1 DetectionCheckpointer(model).load("/content/output/model_final.pth")
2
3 DetectionCheckpointer(model).load("detectron2://COCO-Detection/faster_rcnn_R_101_FPN_3x/137851257/model_final_f6e8b1.pkl")
NameError: name 'model' is not defined
解决方案
推荐阅读
- jenkins - 无法在 jenkins v2.309 中创建“新工作”,确定按钮已禁用
- python - torch.gather(...) 调用的设置结果
- c++ - 为什么在堆中创建的数组上使用 AVX 会导致错误?
- python - 在所有级别上根据 XML 中的元素名称查找属性
- arrays - [Byte] 和 byte() 的区别
- c# - 在unity3d调试的同时我不能输入键盘/鼠标?
- android - 如何通过 ViewModel 在 Fragments 之间正确共享数据?
- flutter - 如何访问嵌套的静态类?
- vue.js - Vue3:如何使用组合 API 覆盖函数?
- python - 从 Excel 工作表中查找并替换所有文本文件中的字符串