detectron2 + ubuntu + cpu

一开始觉得找到的资料都是关于GPU下配置的,可能CPU会有很多坑

结果并没有,就清华conda源坑了我一下

#创建conda环境

#20.3.16. conda清华源怎么也弄不出来,好像是main还是free哪个包出问题了

#一开始以为是配了ss,ip有问题,ping也ping不通,学到了,ping域名不能加http这些

#换了中科大源解决了,底下安装pytorch还是可以用清华的镜像

conda create -n detectron2 python=3.7

#安装pytorch, cpu

#用清华源记得删掉 -c pytorch

#速度就是一切

pip install opencv-python(清华源

pip install cython(清华源

#这里也要下很多包,你看到哪个包下的慢,就crtl+c,然后用pip或者conda结合国内源下载

pip install 'git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI'

# 编译,同上,下包慢就手动来

#网上看到有的博客里编译的语句是啥啥setup.py,然后还要手动下载fvcore,3.16这个版本已经改变了,就按照github最新的命令来

python -m pip install -e .

#接下来看一下人家给出的demo,我一句一句理一下

Inference Demo with Pre-trained Models

  #选择model zoo里面的一个模型,实际上也都保存在configs里面了吧

  #不知道啊,.yaml文件是干嘛的,pkl文件可以是模型也可以是模型参数

  #去model_zoo里面找到mask_rcnn_R_50_FPN_3x/137849600/model_final_f10217.pkl这个文件,下载到本地,可以新建个什么文件夹叫model_zoo之类的,文件夹结构可以像他提供的这样,但是如果你下载的不是特别多,也可以用一个文件夹

  #不知道r_50_fpn_3x到底是啥意思,反正都和训练相关吧,我就先用着了

  1. Pick a model and its config file from model zoo, for example, mask_rcnn_R_50_FPN_3x.yaml.
  2. We provide demo.py that is able to run builtin standard models. Run it with:

cd demo/
--input input1.jpg input2.jpg \ 制定了输入,可以自己找一张input1.jpg放在demo文件夹下。
# [--other-options] 别的选项的占位,没有就把这句删了
# --opts MODEL.WEIGHTS 你存储model_final_f10217.pkl的路径 MODEL.DEVICE cpu
# 这一句指明了model weights的地址,你用原来的路径是会去网上下载的,model.device cpu,一定不能少,我们就cpu。 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

The configs are made for training, therefore we need to specify MODEL.WEIGHTS to a model from model zoo for evaluation. This command will run the inference and show visualizations in an OpenCV window.

For details of the command line arguments, see demo.py -h or look at its source code to understand its behavior. Some common arguments are:

  • To run on your webcam, replace --input files with --webcam.
  • To run on a video, replace --input files with --video-input video.mp4.
  • To run on cpu, add MODEL.DEVICE cpu after --opts.
  • To save outputs to a directory (for images) or a file (for webcam or video), use --output.

 #demo运行后会有这种输出,还有控制界面啥的,无所谓了,我奇怪的一点是,怎么都没办法退出运行,就一直卡在那里,ctrl+c也没有反应,奇怪。

下一篇熟悉一下detectron2的API,因为我只需要使用它训练好的模型,所以关于训练的部分不会涉及

我写的应该都是关于推理部分的代码

猜你喜欢

转载自www.cnblogs.com/zherlock/p/12508328.html