日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

使用mmdetection检测并存储结果

發布時間:2024/8/1 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用mmdetection检测并存储结果 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

使用mmdetection檢測并存儲結果

  • 使用voc格式樣本訓練
  • 檢測并保存結果(添加nms)

使用voc格式樣本訓練

修改mmdet/datasets/voc.py文件中類別,注意格式別出錯

CLASSES = ('bird-nest',)

然后修改配置文件,其中img_scale是你輸入圖片的寬高,num_classes=數據集類別數+1(背景),其他超參按照官網教程修改即可。

如果要做精度評價的話,要記得修改mmdet/core/evaluation/class_names.py中的類別跟數據集的類別一致。

檢測并保存結果(添加nms)

由于我在超算上運行,所以沒有做結果顯示,只是保存為了jpg
在根目錄下新建一個demo.py文件,并運行。

import mmcv import os import numpy as np from mmcv.runner import load_checkpoint from mmdet.models import build_detector from mmdet.apis import init_detector, inference_detector, show_resultmodel = init_detector('configs/pascal_voc/faster_rcnn_r50_fpn_1x_voc0712.py', 'work_dirs/faster_rcnn_r50_fpn_1x_voc0712/epoch_8.pth', device='cuda:0')input_dir = 'data/VOCdevkit/VOC2007/JPEGImages/' out_dir = 'results/'if not os.path.exists(out_dir):os.mkdir(out_dir)def py_cpu_nms(dets, thresh):"""Pure Python NMS baseline."""dets = np.array(dets)x1 = dets[:, 0]y1 = dets[:, 1]x2 = dets[:, 2]y2 = dets[:, 3]scores = dets[:, 4]areas = (x2 - x1 + 1) * (y2 - y1 + 1)order = scores.argsort()[::-1]keep = []while order.size > 0:i = order[0]keep.append(i)xx1 = np.maximum(x1[i], x1[order[1:]])yy1 = np.maximum(y1[i], y1[order[1:]])xx2 = np.minimum(x2[i], x2[order[1:]])yy2 = np.minimum(y2[i], y2[order[1:]])w = np.maximum(0.0, xx2 - xx1 + 1)h = np.maximum(0.0, yy2 - yy1 + 1)inter = w * hovr = inter / (areas[i] + areas[order[1:]] - inter + 0.000000000001)inds = np.where(ovr <= thresh)[0]order = order[inds + 1]return keepdef nms_cpu(total_detections, classnames, thresh=0.5):for i in range(len(classnames)):keep = py_cpu_nms(total_detections[i], thresh)total_detections[i] = total_detections[i][keep]return total_detectionsfiles = os.listdir(input_dir) if len(files) != 0:for file in files:name = os.path.splitext(file)[0]print ('detecting: ' + name)img = mmcv.imread(os.path.join(input_dir, file))img_resize = mmcv.imresize(img, (2000, 1500))result = inference_detector(model, img_resize)result = nms_cpu(result, model.CLASSES, 0.1)result_img = draw_result(img_resize, result, model.CLASSES, score_thr=0.3, out_file=os.path.join(out_dir, name + '.jpg'))

總結

以上是生活随笔為你收集整理的使用mmdetection检测并存储结果的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。