一.配置TensorFlow 1.3
1.创建虚拟环境,取名为tensorflow1.3
virtualenv --system-site-packages -p python3 ~/tensorflow1.3
2.启用虚拟环境
source ~/tensorflow1.3/bin/activate
3.安装tensorflow1.3
pip install tensorflow-gpu==1.3.0
4.将cudnn5.1改为cudnn6.0(cuda保持为8.0)
下载对应版本的cudnn安装包
https://developer.nvidia.com/rdp/cudnn-archive
新建文件夹cudnn6.0
将安装包解压到该文件夹下
sudo rm -rf /usr/local/cuda/include/cudnn.h
sudo rm -rf /usr/local/cuda/lib64/libcudnn*
到cudnn6.0/cuda/对应文件夹下执行一下命令
sudo cp include/cudnn.h /usr/local/cuda/include/
sudo cp lib64/lib* /usr/local/cuda/lib64/
cd /usr/local/cuda/lib64/
sudo chmod +r libcudnn.so.6.0.21
sudo ln -sf libcudnn.so.6.0.21 libcudnn.so.6
sudo ln -sf libcudnn.so.6 libcudnn.so
sudo ldconfig
二.安装keras(在virtualenv下)
pip install keras==2.1
三.安装MASK_RCNN
1.git clone https://github.com/matterport/Mask_RCNN.git
2.Install dependencies(在虚拟环境下)
cd Mask_RCNN/
pip3 install -r requirements.txt
3.Run setup from the repository root directory
python3 setup.py install
4.Download pre-trained COCO weights (mask_rcnn_coco.h5) from the releases page.
放在根目录下。
5.下载安装pycocotools (我下载到了根目录下的coco下)
Linux: https://github.com/waleedka/coco
在PythonAPI中,将Makefile中python都改为python3,make
四.若想在jupyter notebook中使用virtualenv.
1.进入虚拟环境
source ~/tensorflow1.3/bin/activate
2.安装 IPykernel
< python2 >
pip install ipykernel
< python3 >
pip3 install ipykernel
3.将 Virtualenv 加入IPykernel
< python2 >
python2 -m ipykernel install --user --name=tensorflow1.3
< python3 >
python3 -m ipykernel install --user --name=tensorflow1.3
4.启动jupyter notebook并更改kernel
四.启动jupyter notebook
1.更改kernel
2.将pycocotools路径加入
sys.path.append(os.path.join(ROOT_DIR, “coco/PythonAPI/”))
3.运行
成功~
五.将FastMaskRCNN在Pycharm中运行
1.用jupyter notebook将.ipynb转化为.py
File—>Download as—>python(.py)
(jupyter nbconvert --to script *.ipynb )这条命令也可以,不过我没试过。
2.导入虚拟环境
3.改写部分代码
A.在visaualize.py的display_instances函数中:
if auto_show:
plt.savefig("filename.png")
plt.show()
可以保存最终显示的结果,显示什么保存什么。
plt.savefig('文件名')
用于plt显示结果的保存
B.在visaualize.py的display_instances函数中:
ax.imshow(masked_image.astype(np.uint8))
from PIL import Image
masked_image_save = Image.fromarray(masked_image.astype(np.uint8))
masked_image_save.save('mask.png')
将图像+掩膜的结果进行存储
masked_image.astype(np.uint8)是一个ndarray格式的对象
用PIL中的Image.fromarray(ndarray对象)可以将ndarray转换为image
image就可以直接save啦
获取文件夹下所有文件名
find /home/tom/data -name *.png > /home/tom/data/list.txt