DETR类环境快速搭建

DINO下载地址:

git clone https://github.com/IDEA-Research/DINO.git
conda create -n detr python=3.8 -y

修改写入权限

 sudo chmod a+w /home/ubuntu/.conda/

激活环境

source activate detr

安装pytorch

conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 cudatoolkit=11.3 -c pytorch

随后切换到DINO目录,安装所需包,记得将requirements.txt 中的git clone下载删掉

 pip install -r requirements.txt 
 -i https://mirrors.bfsu.edu.cn/pypi/web/simple/

随后安装pycocotools

pip install pycocotools

配置CUDA算子

cd models/dino/ops
python setup.py build install
python test.py

随后修改pycocotools中配置使其输出多个类别的AP值
文件所在路径:

/home/ubuntu/.conda/envs/detr/lib/python3.8/site-packages/pycocotools/

在这里插入图片描述
修改coco.py:

def __init__(self, annotation_file=None):
    """
    Constructor of Microsoft COCO helper class for reading and visualizing annotations.
    :param annotation_file (str): location of annotation file
    :param image_folder (str): location to the folder that hosts images.
    :return:
    """
    # load dataset
    self.dataset,self.anns,self.cats,self.imgs = dict(),dict(),dict(),dict()
    self.imgToAnns, self.catToImgs = defaultdict(list), defaultdict(list)
    if not annotation_file == None:
        print('loading annotations into memory...')
        tic = time.time()
        with open(annotation_file, 'r') as f:
            dataset = json.load(f)
        assert type(dataset)==dict, 'annotation file format {} not supported'.format(type(dataset))
        print('Done (t={:0.2f}s)'.format(time.time()- tic))
        print(
            "category names: {}".format([e["name"] for e in sorted(dataset["categories"], key=lambda x: x["id"])]))
        self.dataset = dataset
        self.createIndex()

修改cocoeval.py:

def summarize(self):
        '''
        Compute and display summary metrics for evaluation results.
        Note this functin can *only* be applied on the default parameter setting
        '''
        def _summarize( ap=1, iouThr=None, areaRng='all', maxDets=100 ):
            p = self.params
            iStr = ' {:<18} {} @[ IoU={:<9} | area={:>6s} | maxDets={:>3d} ] = {:0.3f}'
            titleStr = 'Average Precision' if ap == 1 else 'Average Recall'
            typeStr = '(AP)' if ap==1 else '(AR)'
            iouStr = '{:0.2f}:{:0.2f}'.format(p.iouThrs[0], p.iouThrs[-1]) \
                if iouThr is None else '{:0.2f}'.format(iouThr)
 
            aind = [i for i, aRng in enumerate(p.areaRngLbl) if aRng == areaRng]
            mind = [i for i, mDet in enumerate(p.maxDets) if mDet == maxDets]
            if ap == 1:
                # dimension of precision: [TxRxKxAxM]
                s = self.eval['precision']
                # IoU
                if iouThr is not None:
                    t = np.where(iouThr == p.iouThrs)[0]
                    s = s[t]
                s = s[:,:,:,aind,mind]
            else:
                # dimension of recall: [TxKxAxM]
                s = self.eval['recall']
                if iouThr is not None:
                    t = np.where(iouThr == p.iouThrs)[0]
                    s = s[t]
                s = s[:,:,aind,mind]
            if len(s[s>-1])==0:
                mean_s = -1
            else:
                mean_s = np.mean(s[s>-1])
            #print(iStr.format(titleStr, typeStr, iouStr, areaRng, maxDets, mean_s))
            category_dimension = 1 + int(ap)
            if s.shape[category_dimension] > 1:
 
                iStr += ", per category = {}"
                mean_axis = (0,)
                if ap == 1:
                    mean_axis = (0, 1)
                per_category_mean_s = np.mean(s, axis=mean_axis).flatten()
                with np.printoptions(precision=3, suppress=True, sign=" ", floatmode="fixed"):
                    print(iStr.format(titleStr, typeStr, iouStr, areaRng, maxDets, mean_s, per_category_mean_s))
            else:
                print(iStr.format(titleStr, typeStr, iouStr, areaRng, maxDets, mean_s, ""))
            return mean_s

博主使用的是DINO-DETR,在第一次运行时会报错:

File “E:\graduate\programsnew\DINO_OTA\DINO-main\DINO-main\util\slconfig.py”, line 87, in _file2dict
osp.join(temp_config_dir, temp_config_name))
with open(dst, ‘wb’) as fdst: PermissionError: [Errno 13] Permission
denied:
‘C:\Users\PENGXI~1\AppData\Local\Temp\tmpimf43tng\tmp2gd8c8_8.py’

提示我们拒绝访问,解决方法:找到E:\graduate\programsnew\DINO_OTA\DINO-main\DINO-main\util\slconfig.py文件

if filename.lower().endswith('.py'):
    with tempfile.TemporaryDirectory() as temp_config_dir:
        temp_config_file = tempfile.NamedTemporaryFile(
            dir=temp_config_dir, suffix='.py')
        temp_config_file.close()#添加这行代码
        temp_config_name = osp.basename(temp_config_file.name)
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

彭祥.

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值