前提条件是配置了pytorch18的linux环境
参考流程:配置pycharm环境
拷贝pycharm环境为mmdet
conda create -n mmdet --clone torch18
进入
conda activate mmdet
装mim
pip install -U openmim
使用mim装mmengine
mim install mmengine
使用mim装mmcv
mim install "mmcv>=2.0.0"
安装git详细步骤
git clone https://github.com/open-mmlab/mmdetection.git
致命错误:无法访问 ‘https://github.com/open-mmlab/mmdetection.git/’:OpenSSL SSL_read: error:0A000126:SSL routines::unexpected eof while reading, errno 0
解决方案:
git访问
git clone git://github.com/open-mmlab/mmdetection.git
如果还是连接不上:
gedit ~/.gitconfig
添加:
[url "[email protected]:"]
pushInsteadOf = git://github.com/
pushInsteadOf = https://github.com/
git clone https://github.com/open-mmlab/mmdetection.git
直接下载了。。。。
安装解压工具
sudo apt install unzip
解压缩
unzip mmdetection-main.zip
pip install -v -e .
版本信息:
mmdet-3.1.0
pycocotools-2.0.6 s
cipy-1.10.1
shapely-2.0.1
terminaltables-3.1.10
第一种方法
mim download mmdet --config rtmdet_tiny_8xb32-300e_coco --dest .
完成后,你会在当前文件夹中发现两个文件 rtmdet_tiny_8xb32-300e_coco.py 和 rtmdet_tiny_8xb32-300e_coco_20220902_112414-78e30dcc.pth。
python demo/image_demo.py demo/demo.jpg rtmdet_tiny_8xb32-300e_coco.py --weights rtmdet_tiny_8xb32-300e_coco_20220902_112414-78e30dcc.pth --device cpu
第二种方法
在pycharm中:
from mmdet.apis import init_detector, inference_detector
config_file = 'rtmdet_tiny_8xb32-300e_coco.py'
checkpoint_file = 'rtmdet_tiny_8xb32-300e_coco_20220902_112414-78e30dcc.pth'
model = init_detector(config_file, checkpoint_file, device='cpu') # or device='cuda:0'
#inference_detector(model, 'demo/demo.jpg')
result = inference_detector(model, 'demo/demo.jpg')
print(result)
将会看到一个包含 DetDataSample 的列表,预测结果在 pred_instance 里,包含有检测框,类别和得分。
<DetDataSample(
META INFORMATION
batch_input_shape: (640, 640)
ori_shape: (427, 640)
img_path: 'demo/demo.jpg'
scale_factor: (1.0, 1.0)
img_shape: (640, 640)
pad_shape: (640, 640)
img_id: 0
DATA FIELDS
gt_instances: <InstanceData(
META INFORMATION
DATA FIELDS
bboxes: tensor([], size=(0, 4))
labels: tensor([], dtype=torch.int64)
) at 0x7fc8ec94e040>
ignored_instances: <InstanceData(
META INFORMATION
DATA FIELDS
bboxes: tensor([], size=(0, 4))
labels: tensor([], dtype=torch.int64)
) at 0x7fc8ec945f70>
pred_instances: <InstanceData(
META INFORMATION
DATA FIELDS
bboxes: tensor([[221.3719, 176.1281, 456.2581, 383.2401],
[295.3506, 117.1835, 378.5715, 150.2712],
[190.5735, 109.7099, 299.5221, 155.0396],
...,
[373.1318, 133.4568, 432.5015, 188.4432],
[ 62.4457, 80.0291, 119.8074, 104.2917],
[141.4960, 94.1753, 184.4167, 107.8061]])
labels: tensor([13, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 56, 13, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 7, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 2, 7, 2, 7, 2, 7, 2, 2, 2, 2, 0, 2, 7, 2, 2, 7,
2, 2, 56, 2, 56, 2, 2, 2, 2, 2, 7, 2, 2, 2, 2, 2, 2, 2,
60, 13, 7, 2, 7, 2, 16, 2, 7, 2, 2, 2, 13, 2, 2, 2, 2, 2,
7, 2, 7, 7, 2, 7, 2, 2, 7, 7, 2, 2, 60, 13, 2, 2, 13, 2,
2, 2, 7, 2, 7, 2, 2, 2, 7, 2, 2, 7, 2, 2, 2, 2, 2, 2,
7, 2, 7, 2, 7, 13, 7, 7, 2, 7, 13, 0, 2, 17, 2, 2, 2, 2,
2, 7, 28, 56, 7, 7, 2, 1, 2, 7, 13, 2, 2, 7, 2, 13, 2, 2,
7, 2, 0, 2, 7, 7, 58, 7, 57, 9, 13, 2, 2, 2, 7, 56, 2, 2,
3, 13, 56, 7, 7, 13, 2, 2, 0, 16, 2, 7, 7, 0, 7, 0, 7, 7,
2, 7, 7, 7, 7, 2, 2, 2, 2, 13, 7, 5, 0, 0, 7, 0, 7, 2,
7, 1, 1, 2, 2, 7, 1, 2, 7, 2, 14, 13, 5, 3, 13, 7, 7, 56,
7, 7, 3, 7, 13, 0, 2, 2, 2, 2, 1, 13, 2, 13, 2, 13, 2, 7,
3, 2, 3, 2, 0, 2, 13, 60, 7, 7, 7, 56, 3, 0, 2, 13, 5, 0,
0, 7, 7, 2, 60, 59, 7, 0, 7, 7, 2, 2, 2, 2, 1, 7, 1, 2,
0, 7, 5, 0, 0, 7, 0, 7, 56, 3, 7, 1])
scores: tensor([0.8703, 0.7677, 0.7428, 0.6995, 0.6847, 0.6238, 0.6097, 0.6063, 0.5566,
0.5535, 0.5015, 0.4779, 0.4746, 0.4718, 0.4639, 0.4491, 0.4410, 0.4129,
0.3939, 0.3650, 0.3524, 0.3442, 0.3207, 0.3191, 0.3145, 0.3144, 0.3119,
0.2992, 0.2890, 0.2762, 0.2760, 0.2735, 0.2694, 0.2658, 0.2572, 0.2533,
0.2480, 0.2347, 0.2308, 0.2259, 0.2255, 0.2252, 0.2240, 0.2235, 0.2196,
0.2136, 0.2099, 0.2051, 0.1983, 0.1972, 0.1972, 0.1909, 0.1903, 0.1873,
0.1872, 0.1828, 0.1816, 0.1794, 0.1789, 0.1761, 0.1760, 0.1743, 0.1743,
0.1722, 0.1717, 0.1710, 0.1708, 0.1690, 0.1688, 0.1651, 0.1649, 0.1628,
0.1622, 0.1619, 0.1611, 0.1575, 0.1569, 0.1520, 0.1490, 0.1479, 0.1474,
0.1473, 0.1462, 0.1443, 0.1435, 0.1426, 0.1420, 0.1414, 0.1398, 0.1383,
0.1382, 0.1373, 0.1360, 0.1354, 0.1288, 0.1285, 0.1280, 0.1210, 0.1206,
0.1194, 0.1145, 0.1141, 0.1137, 0.1135, 0.1134, 0.1133, 0.1118, 0.1110,
0.1086, 0.1074, 0.1068, 0.1068, 0.1064, 0.1063, 0.1049, 0.1045, 0.1045,
0.1042, 0.1042, 0.1023, 0.1007, 0.1004, 0.0992, 0.0988, 0.0985, 0.0984,
0.0984, 0.0978, 0.0974, 0.0965, 0.0964, 0.0964, 0.0962, 0.0962, 0.0956,
0.0954, 0.0948, 0.0942, 0.0940, 0.0931, 0.0928, 0.0922, 0.0922, 0.0915,
0.0915, 0.0913, 0.0911, 0.0908, 0.0900, 0.0895, 0.0882, 0.0873, 0.0865,
0.0864, 0.0861, 0.0853, 0.0851, 0.0851, 0.0843, 0.0842, 0.0841, 0.0825,
0.0821, 0.0810, 0.0810, 0.0806, 0.0804, 0.0802, 0.0800, 0.0794, 0.0793,
0.0792, 0.0792, 0.0787, 0.0780, 0.0773, 0.0772, 0.0770, 0.0763, 0.0763,
0.0758, 0.0755, 0.0754, 0.0753, 0.0752, 0.0750, 0.0747, 0.0740, 0.0719,
0.0714, 0.0712, 0.0712, 0.0711, 0.0711, 0.0704, 0.0700, 0.0696, 0.0683,
0.0676, 0.0674, 0.0671, 0.0671, 0.0665, 0.0662, 0.0659, 0.0658, 0.0658,
0.0658, 0.0655, 0.0650, 0.0649, 0.0644, 0.0638, 0.0637, 0.0636, 0.0631,
0.0629, 0.0628, 0.0627, 0.0616, 0.0615, 0.0613, 0.0613, 0.0611, 0.0608,
0.0607, 0.0607, 0.0602, 0.0601, 0.0600, 0.0599, 0.0598, 0.0596, 0.0595,
0.0593, 0.0591, 0.0591, 0.0587, 0.0586, 0.0584, 0.0584, 0.0583, 0.0583,
0.0580, 0.0578, 0.0577, 0.0571, 0.0571, 0.0567, 0.0567, 0.0565, 0.0563,
0.0561, 0.0561, 0.0561, 0.0560, 0.0560, 0.0558, 0.0555, 0.0554, 0.0553,
0.0552, 0.0552, 0.0551, 0.0550, 0.0548, 0.0548, 0.0545, 0.0544, 0.0543,
0.0543, 0.0540, 0.0540, 0.0540, 0.0539, 0.0537, 0.0536, 0.0536, 0.0536,
0.0535, 0.0532, 0.0532, 0.0532, 0.0531, 0.0530, 0.0530, 0.0529, 0.0526,
0.0526, 0.0525, 0.0524, 0.0523, 0.0523, 0.0523, 0.0518, 0.0515, 0.0514,
0.0510, 0.0507, 0.0507])
) at 0x7fc8ec94e0d0>
) at 0x7fc8ec94e100>
使用jupyter:
安装Jupyter 和使用Jupyter查看说明文件
网站说明