机器学习备注:Windows上运行Mask_RCNN模型

准备工作

这些模型在Linux上运行比较方便,不过想起Windows便捷的各种工具,总是忍不住弄过来,

原模型的地址在这,
https://github.com/matterport/Mask_RCNN

需要用到的工具pycocotools在这
不过要注意,这个pycocotools工具有Linux版和windows版本的,不要弄错了,官网链接给出的都是Linux版本的
windows版本( Windows下用这个 :-o )
https://github.com/philferriere/cocoapi
linux版本,
https://github.com/waleedka/coco

前提:已经安装好anaconda, 搭建好tensorflow开发环境
提示:
conda create -n tensorflow python=3.6
activate tensorflow
pip3 install (numpy, skimage, scipy, pillow, cython, etc......)

运行时中途碰到一个错误:
ImportError: No module named cv2
原因就是因为没有安装opencv-python,此时在tensorflow环境安装即可
(tensorflow) (tensorflow) E:\AtensorflowDev>pip3 install opencv-python

操作步骤如下

step1 clone the Mask_RCNN repository
git clone https://github.com/matterport/Mask_RCNN.git
此时会在你的目录下生成一个Mask_RCNN的文件夹,这个就是你项目的ROOT_DIR,后面要用到
我的目录是:E:\AtensorflowDev\Mask_RCNN
该目录下有一个requirements.txt文件,此时还需要运行一下
pip3 install -r requirements.txt
以确保所需要的包都安装好

step2 下载已经训练好的COCO weights (mask_rcnn_coco.h5)
官网(https://github.com/matterport/Mask_RCNN/releases)给出的地址是
https://github.com/matterport/Mask_RCNN/releases/download/v2.1/mask_rcnn_balloon.h5
因为()的原因,下载起来好慢,我下载了10多次,差不多花了一天,如果你运气和我一样差,那就用这个包吧
链接:https://pan.baidu.com/s/12A0E6h-mP4zl9oqoTvj6Ig 密码:4eks

step3 把 mask_rcnn_coco.h5 放置到Mask_RCNN这个目录下面
E:\AtensorflowDev\Mask_RCNN\mask_rcnn_coco.h5

step4 安装coco工具
$ pip install git+https://github.com/philferriere/cocoapi.git#subdirectory=PythonAPI
我的输出界面是这样的

1.(执行命令)
(tensorflow) E:\AtensorflowDev>pip install git+https://github.com/philferriere/cocoapi.git#subdirectory=PythonAPI 
(然后回车)
2.(下面是运行后输出的结果,表示安装成功)
Collecting git+https://github.com/philferriere/cocoapi.git#subdirectory=PythonAPI
  Cloning https://github.com/philferriere/cocoapi.git to c:\users\admini~1\appdata\local\temp\pip-req-build-a4gugnlj
Building wheels for collected packages: pycocotools
  Running setup.py bdist_wheel for pycocotools ... done
  Stored in directory: C:\Users\ADMINI~1\AppData\Local\Temp\pip-ephem-wheel-cache-35xkjtfa\wheels\69\2b\12\2fa959e49f73d26cff202c2f4e5079096c9c57c8a8509fd75c
Successfully built pycocotools
Installing collected packages: pycocotools
Successfully installed pycocotools-2.0

step5 启动anaconda中的tensor开发环境,选择jupyter notebook,然后在jupyter中upload这个demo,
E:\AtensorflowDev\MaskRCNN\samples\demo.ipynb

最后给出一张本人运行的结果全图,注意包括了一些调试信息,有点啰嗦,还有那个ROOT_DIR路径,因为老是提示ModuleNotFoundError,我干脆写成绝对路径,另外说一下的是,我没有GPU,程序中的那个GPU_COUNT=1仅仅是用来计算每个批次图片的张数(这里就一张)和真实的GPU数量无关

参考:

Object Detection and Segmentation in Python with Mask-RCNN
http://bradsliz.com/2017-11-06-object-segmentation/
https://github.com/philferriere/cocoapi
https://github.com/matterport/Mask_RCNN
https://github.com/waleedka/coco

AI视像算法学习群: 824991413


 

猜你喜欢

转载自blog.csdn.net/tanmx219/article/details/82828727