import os
path = "/content/drive/My Drive/detectron2-master"
os.chdir(path)
os.listdir(path)
!ls
进入云盘下载下来的代码文件夹中,本文跑FAIR给的github上的demo
按照官方给的install指南安装
然后getting started,在这一步中,
cd demo/
python demo.py --config-file ../configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml \
--input input1.jpg input2.jpg \
[--other-options]
--opts MODEL.WEIGHTS detectron2://COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x/137849600/model_final_f10217.pkl
报错
File "<ipython-input-19-f82ab9f72449>", line 1
python demo.py --config-file ../configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml \--input input1.jpg input2.jpg [--other-options]
^
SyntaxError: invalid syntax
colab运行python时,前面一定要加!
然后再运行又报错
Traceback (most recent call last):
File "demo.py", line 13, in <module>
from detectron2.config import get_cfg
ModuleNotFoundError: No module named 'detectron2'
找不到这个模块,这个是在demo同级文件夹中,但是现在我们在demo文件夹目录下运行的demo.py
导入上级目录的下一级文件,也需要使用sys.path
import sys
sys.path.append("..")
from dir4 import file4
加入前两行还是报错
翻了一堆博客,大多数说什么".."或者是"../A'路径方法,结果都不行,才发现得在.py
import sys
sys.path.append('/content/drive/My Drive/detectron2-master')
文件里加上这两句,完整路径名而不是上一句!
接下来报一堆错没有xxx,这个直接pip install就好,后来发现可以再加一句执行setup.py文件
终于开始正式跑demo.py了!
然后发现官方给的几行代码一直报错,
[07/15 19:29:32 detectron2]: Arguments: Namespace(confidence_threshold=0.5, config_file='../configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml', input=['input1.jpg', 'input2.jpg', '[--other-options]--opts', 'MODEL.WEIGHTS', 'detectron2://COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x/137849600/model_final_f10217.pkl'], opts=[], output=None, video_input=None, webcam=False)
Traceback (most recent call last):
File "demo/demo.py", line 106, in <module>
cfg = setup_cfg(args)
File "demo/demo.py", line 35, in setup_cfg
cfg.merge_from_file(args.config_file)
File "/content/drive/MyDrive/detectron2-master/detectron2/config/config.py", line 30, in merge_from_file
assert PathManager.isfile(cfg_filename), f"Config file '{cfg_filename}' does not exist!"
AssertionError: Config file '../configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml' does not exist!
文件不存在.......又来了,文件路径一定要写明白,现在是在项目大文件夹目录下,所以不用加"../"
找的一个hxd给的代码,加了output选项,结果直接覆盖原图
#https://blog.csdn.net/weixin_43013761/article/details/104022615
#COCO实例分割
!python demo/demo.py --config-file configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml --input input2.jpg --output . --opts MODEL.WEIGHTS detectron2://COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x/137849600/model_final_f10217.pkl
现在一个最简单的例子demo可以跑了,接下来跑panoptic,这个我先在https://github.com/facebookresearch/detectron2/blob/master/MODEL_ZOO.md
下了panoptic的1x版本的yaml放在目录下面的offical_model子文件夹里面
出现这种问题,没有json,运行下面一行代码即可
pip install git+https://github.com/cocodataset/panopticapi.git
跑成功图片的全景分割demo
接下来进行评估模型性能
https://blog.csdn.net/weixin_34910922/article/details/106932949