mmdetection2.x windows下 PermissionError:

mmcv造成的shutil.copyfile(),复制文件,在复制的时候目标 文件是不能存在的,但是打印发现复制之前.py就已经存在。先将.py删掉,然后再复制就能出结果了。

可以先打印一下文件夹下存在的文件:

图片

修改:

                temp_config_file = tempfile.NamedTemporaryFile(
                    dir=temp_config_dir, suffix='.py')
                temp_config_name = osp.basename(temp_config_file.name)
                
                if os.path.exists(osp.join(temp_config_dir, temp_config_name)):
                    os.remove(osp.join(temp_config_dir, temp_config_name))

                shutil.copyfile(filename,
                                osp.join(temp_config_dir, temp_config_name))

测试:

import time
import cv2
import os
import numpy as np
from mmdet.apis import init_detector, inference_detector
from mmdet.datasets.voc import VOCDataset

s=time.time()
class_data = VOCDataset
class_dic = class_data.CLASSES
class_color = [(0, 255, 0), (0, 0, 255), (255, 0, 255), (0, 255, 255), (255, 255, 0), ]

config_file = r'./configs\faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py'
checkpoint_file = r'D:\0_code\2_highmm\tools/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth'
result_path = "./result/"
img_path = r'D:\0_code\2_highmm/'

if not os.path.exists(result_path):
    os.makedirs(result_path)
model = init_detector(config_file, checkpoint_file)

print("init_detector_use time :", time.time()-s)

filelist = os.listdir(img_path)
for item in filelist:
    if item.endswith('.jpg'):
        img = img_path+item
        print("------")
        print(item)
        img = cv2.imread(img)
        star = time.time()
        result = inference_detector(model, img)
        for i in range(len(class_dic)):
            sores = result[i][:, -1]
            if len(sores) > 0:
                for j in range(len(sores)):
                    score_ = round(sores[j], 3)
                    if score_ > 0.2:
                        # print("图像:", item, "第 ", i, "类, 得分: ", sores[j])
                        label_text = class_dic[i] + "::"+str(score_)
                        bboxes = result[i][j, :-1]
                        # print(bboxes)
                        bbox_int = bboxes.astype(np.int32)
                        left_top = (bbox_int[0], bbox_int[1])
                        right_bottom = (bbox_int[2], bbox_int[3])
                        cv2.rectangle(img, left_top, right_bottom, color=class_color[1],thickness=2)
                        cv2.putText(img, label_text, (bbox_int[0], bbox_int[1] - 4),
                                    cv2.FONT_HERSHEY_COMPLEX, 0.8, class_color[1])
            else:
                continue
        cv2.imwrite(result_path+item, img)
        cv2.imshow("result: ", img)
        cv2.waitKey(100000)
        print("Test one pic use time:", time.time()-star)

print("time", time.time()-s)

结果

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值