Colab运行detectron2 demo

8 篇文章 0 订阅
3 篇文章 0 订阅
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

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值