1.创建虚拟环境,添加jupyter虚拟环境
conda create -n mmo python=3.7
conda activate mmo
conda install ipykernel
conda install nb_conda
p.s. 也是从这个地方发现之前的文章配的内核有问题,开始用这个方法配ju虚拟环境,还不错没啥问题了!
也可顺手升级一下pip至最新
python -m pip install --upgrade pip
2.装对应版本的torch,cuda110->pytorch1.7.0
conda install pytorch==1.7.0 torchvision==0.8.0 torchaudio==0.7.0 cudatoolkit=11.0 -c pytorch
3.装mmcv
pip install mmcv-full==1.3.17 -f https://download.openmmlab.com/mmcv/dist/cu110/torch1.7.0/index.html
mmcv版本选择:
https://mmcv.readthedocs.io/en/latest/get_started/installation.html
4.装mim
pip install openmim
测试:
!mim install mmdet==2.22.0
!mim search mmdet --model 'mask r-cnn'
!mim download mmdet --config mask_rcnn_r50_fpn_2x_coco --dest .
5.装mmdet
mim install mmdet==2.22.0
测试Demo:
import os
os.environ['CUDA_VISIBLE_DEVICES']='5'
from mmdet.apis import init_detector,inference_detector,show_result_pyplot
config_file = 'mask_rcnn_r50_fpn_2x_coco.py'
check_point_file = 'mask_rcnn_r50_fpn_2x_coco_bbox_mAP-0.392__segm_mAP-0.354_20200505_003907-3e542a40.pth'
model = init_detector(config_file,check_point_file)
print(model)
Demo='demo.jpeg'
result = inference_detector(model,Demo)
show_result_pyplot(model,Demo,result)
显示那张神椅就大功告成了!剩下的就是去搞数据训自己的模型了!
6.装mmocr
mmocr版本选择:
https://mmocr.readthedocs.io/en/latest/install.html
这里选择0.5.0
https://github.com/open-mmlab/mmocr/archive/refs/tags/v0.5.0.zip
直接github下载然后upload离线安装
cd mmocr0.5.0
pip install -r requirements.txt
pip install -v -e .
export PYTHONPATH=$(pwd):$PYTHONPATH
测试Demo:
from mmocr.utils.ocr import MMOCR
ocr = MMOCR()
results = ocr.readtext('demo/demo_text_ocr.jpg', details=True,print_result=True, imshow=False)
Ubuntu暂时还没弄懂怎么在jupyter显示图片展示,可以把imshow改为False,出现text识别就算大功告成!
今天暂时到这里吧,显示图片这个问题搞的opencv 删了又装,结果ocr又识别不了了,又得重装,特此记录,这次整理连写带装花了1个多小时,比第一次装mmd搞了一整个晚上快多了(就是昨天…)
赶紧睡觉去了,配环境搞的人都麻了,淦!2022-06-12 01:22:25
参考:SJTU open-mmlab 公开课B站,有手把手教芒果检测!