【代码调试】《Frustratingly Simple Few-Shot Object Detection》

news2024/9/25 4:31:36

更多问题可参考:
https://blog.csdn.net/qiankendeNMY/article/details/128450196

论文地址:https://arxiv.org/abs/2003.06957
论文代码:https://github.com/ucbdrive/few-shot-object-detection

我的配置:
Python :3.8.16(ubuntu20.04)
Pytorch :1.8.1
Cuda :11.1
GPU:RTX 3090 Ti(24GB)

1、环境配置

1.1、安装pytorch

安装和CUDA版本匹配的pytorch,且pytorch版本和预购间的Detectron2版本匹配:

pip install torch==1.8.1+cu111 torchvision==0.9.1+cu111 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html

1.2、构建Detectron2

这里我选择的是v0.3版本:
https://github.com/facebookresearch/detectron2/releases/tag/v0.3

首先克隆仓库并标出正确版本:

git clone https://github.com/facebookresearch/detectron2.git
cd detectron2
git checkout v0.3

在这里插入图片描述在这里插入图片描述

然后,安装detectron2==0.3:

python -m pip install detectron2==0.3 -f https://dl.fbaipublicfiles.com/detectron2/wheels/cu110/torch1.7/index.html

根据requirements.txt安装其他库:

python3 -m pip install -r requirements.txt

2、准备数据集

下载小样本数据集:

wget -r -R index.html dl.yf.io/fs-det/datasets/

然后将下载好的vocsplit移动到datasets文件夹下:

3、基础训练

split1的基础训练

python3 -m tools.train_net --num-gpus 1 --config-file configs/PascalVOC-detection/split1/faster_rcnn_R_101_FPN_base1.yaml

1、报错

Traceback (most recent call last):
  File "/home/test/anaconda3/envs/tfa/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/home/test/anaconda3/envs/tfa/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/test/code/TFA/tools/train_net.py", line 113, in <module>
    launch(
  File "/home/test/anaconda3/envs/tfa/lib/python3.8/site-packages/detectron2/engine/launch.py", line 62, in launch
    main_func(*args)
  File "/home/test/code/TFA/tools/train_net.py", line 105, in main
    trainer = Trainer(cfg)
  File "/home/test/code/TFA/fsdet/engine/defaults.py", line 304, in __init__
    data_loader = self.build_train_loader(cfg)
  File "/home/test/code/TFA/fsdet/engine/defaults.py", line 492, in build_train_loader
    return build_detection_train_loader(cfg)
  File "/home/test/anaconda3/envs/tfa/lib/python3.8/site-packages/detectron2/config/config.py", line 201, in wrapped
    explicit_args = _get_args_from_config(from_config, *args, **kwargs)
  File "/home/test/anaconda3/envs/tfa/lib/python3.8/site-packages/detectron2/config/config.py", line 238, in _get_args_from_config
    ret = from_config_func(*args, **kwargs)
  File "/home/test/anaconda3/envs/tfa/lib/python3.8/site-packages/detectron2/data/build.py", line 308, in _train_loader_from_config
    dataset = get_detection_dataset_dicts(
  File "/home/test/anaconda3/envs/tfa/lib/python3.8/site-packages/detectron2/data/build.py", line 227, in get_detection_dataset_dicts
    dataset_dicts = [DatasetCatalog.get(dataset_name) for dataset_name in names]
  File "/home/test/anaconda3/envs/tfa/lib/python3.8/site-packages/detectron2/data/build.py", line 227, in <listcomp>
    dataset_dicts = [DatasetCatalog.get(dataset_name) for dataset_name in names]
  File "/home/test/anaconda3/envs/tfa/lib/python3.8/site-packages/detectron2/data/catalog.py", line 58, in get
    return f()
  File "/home/test/code/TFA/fsdet/data/meta_pascal_voc.py", line 147, in <lambda>
    lambda: load_filtered_voc_instances(
  File "/home/test/code/TFA/fsdet/data/meta_pascal_voc.py", line 48, in load_filtered_voc_instances
    fileids = np.loadtxt(f, dtype=np.str)
  File "/home/test/anaconda3/envs/tfa/lib/python3.8/site-packages/numpy/__init__.py", line 305, in __getattr__
    raise AttributeError(__former_attrs__[attr])
AttributeError: module 'numpy' has no attribute 'str'.
`np.str` was a deprecated alias for the builtin `str`. To avoid this error in existing code, use `str` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.str_` here.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
    https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations

解决方案:
找到报错的位置,将 np.str 改为 np.str_:
在这里插入图片描述
评估:

python3 -m  tools.test_net --num-gpus 1  --config-file configs/PascalVOC-detection/split1/faster_rcnn_R_101_FPN_base1.yaml   --eval-only

在这里插入图片描述

4、随机初始化新类别的权重

python3 -m tools.ckpt_surgery --src1 checkpoints/voc/faster_rcnn/faster_rcnn_R_101_FPN_base1/model_final.pth --method randinit --save-dir checkpoints/voc/faster_rcnn/faster_rcnn_R_101_FPN_all1

5、微调

1、使用CosineSimOutputLayers

python3 -m tools.train_net --num-gpus 1 --config-file configs/PascalVOC-detection/split1/faster_rcnn_R_101_FPN_ft_all1_1shot.yaml --opts MODEL.WEIGHTS checkpoints/voc/faster_rcnn/faster_rcnn_R_101_FPN_all1/model_reset_surgery.pth

2、使用FastRCNNConvFCHead

python3 -m tools.train_net --num-gpus 1 --config-file configs/PascalVOC-detection/split1/faster_rcnn_R_101_FPN_ft_fc_all1_1shot.yaml --opts MODEL.WEIGHTS checkpoints/voc/faster_rcnn/faster_rcnn_R_101_FPN_all1/model_reset_surgery.pth

1、报错

/home/test/code/TFA/fsdet/data/meta_pascal_voc.py:37: FutureWarning: In the future `np.str` will be defined as the corresponding NumPy scalar.
  fileids_ = np.loadtxt(f, dtype=np.str).tolist()
Traceback (most recent call last):
  File "/home/test/anaconda3/envs/tfa/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/home/test/anaconda3/envs/tfa/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/test/code/TFA/tools/train_net.py", line 113, in <module>
    launch(
  File "/home/test/anaconda3/envs/tfa/lib/python3.8/site-packages/detectron2/engine/launch.py", line 62, in launch
    main_func(*args)
  File "/home/test/code/TFA/tools/train_net.py", line 105, in main
    trainer = Trainer(cfg)
  File "/home/test/code/TFA/fsdet/engine/defaults.py", line 304, in __init__
    data_loader = self.build_train_loader(cfg)
  File "/home/test/code/TFA/fsdet/engine/defaults.py", line 492, in build_train_loader
    return build_detection_train_loader(cfg)
  File "/home/test/anaconda3/envs/tfa/lib/python3.8/site-packages/detectron2/config/config.py", line 201, in wrapped
    explicit_args = _get_args_from_config(from_config, *args, **kwargs)
  File "/home/test/anaconda3/envs/tfa/lib/python3.8/site-packages/detectron2/config/config.py", line 236, in _get_args_from_config
    ret = from_config_func(*args, **kwargs)
  File "/home/test/anaconda3/envs/tfa/lib/python3.8/site-packages/detectron2/data/build.py", line 301, in _train_loader_from_config
    dataset = get_detection_dataset_dicts(
  File "/home/test/anaconda3/envs/tfa/lib/python3.8/site-packages/detectron2/data/build.py", line 220, in get_detection_dataset_dicts
    dataset_dicts = [DatasetCatalog.get(dataset_name) for dataset_name in dataset_names]
  File "/home/test/anaconda3/envs/tfa/lib/python3.8/site-packages/detectron2/data/build.py", line 220, in <listcomp>
    dataset_dicts = [DatasetCatalog.get(dataset_name) for dataset_name in dataset_names]
  File "/home/test/anaconda3/envs/tfa/lib/python3.8/site-packages/detectron2/data/catalog.py", line 58, in get
    return f()
  File "/home/test/code/TFA/fsdet/data/meta_pascal_voc.py", line 147, in <lambda>
    lambda: load_filtered_voc_instances(
  File "/home/test/code/TFA/fsdet/data/meta_pascal_voc.py", line 37, in load_filtered_voc_instances
    fileids_ = np.loadtxt(f, dtype=np.str).tolist()
  File "/home/test/anaconda3/envs/tfa/lib/python3.8/site-packages/numpy/__init__.py", line 305, in __getattr__
    raise AttributeError(__former_attrs__[attr])
AttributeError: module 'numpy' has no attribute 'str'.
`np.str` was a deprecated alias for the builtin `str`. To avoid this error in existing code, use `str` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.str_` here.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
    https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations

解决方案:
找到报错的位置,把 np.str 改为 np.str_:
在这里插入图片描述
微调结束:
1、CosineSimOutputLayers的结果
在这里插入图片描述

2、FastRCNNConvFCHead的结果:
在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/439520.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

从零开始,详解亚马逊店铺注册流程及技巧指南

近几年跨境电商的势头越来越猛&#xff0c;所以很多新手都想去闯荡一番。很多人的第一选择都是亚马逊&#xff0c;毕竟亚马逊是世界上最大的电商平台之一&#xff0c;因此今天东哥就跟大家分享亚马逊店铺的注册方法&#xff0c;想在亚马逊开店的朋友不要错过&#xff01; 亚马逊…

设计模式 -- 工厂方法模式以及抽象工厂模式

前言 月是一轮明镜,晶莹剔透,代表着一张白纸(啥也不懂) 央是一片海洋,海乃百川,代表着一块海绵(吸纳万物) 泽是一柄利剑,千锤百炼,代表着千百锤炼(输入输出) 月央泽,学习的一种过程,从白纸->吸收各种知识->不断输入输出变成自己的内容 希望大家一起坚持这个过程,也同…

Mysql MVCC实现

文章目录 背景MVCC定义快照读和当前读当前读快照读 MVCC实现原理隐式字段undo log版本链1.插入一条记录2.修改记录3.修改记录 Read View读视图属性&#xff1a;Read View可见性算法 隔离级别长事务为什么要避免长事务 背景 并发事务可能产生的问题&#xff1a; 读读&#xff…

zk111111111111111111

Zookeeper 1 zookeeper(作为 dubbo 的注册中心): 概述: zookeper 是 一个分布式的、开源的分布式应用程序的协调服务,管理分布式应 用 作用: 配置管理,分布式锁,集群管理 2 zookeeper 的安装 (dubbo 的资料中已经整理) 3 zookeeper 的数据模型 zookeeper 是一个树形的服…

微信小程序php+vue 校园租房指南房屋租赁系统

本着诚信的原则&#xff0c;平台必须要掌握出租方必要的真实可信的信息&#xff0c;这样就可以防止欺诈事件的发生&#xff0c;事后也可以联系找到出租方。并且租金等各方面规范标准化&#xff0c;在这易租房诚信可信的平台让承租方与出租方充分有效对接&#xff0c;既方便了承…

扫清盲点:带你学习 树状数组 这种数据结构

什么是树状数组 树状数组是一种用于维护数列前缀和的数据结构&#xff0c;它可以在 O(logn) 的时间复杂度内修改单个元素的值&#xff0c;以及查询某个区间的元素和。 树状数组的特点是什么&#xff1f; 树状数组的特点其实就是&#xff0c;在单点修改 &#xff0c;和区间查询…

rancher2.7丢失集群信息

使用Docker 单节点安装rancher&#xff0c;然后在rancher中创建了一个k8s的集群。重启rancher所在的虚拟机后&#xff0c;登录rancher发现这是新的实例&#xff0c;集群信息丢失了。但是k8s集群还是好好的。 检查k8s的日志&#xff0c;api server日志会报错 time"2023-0…

11 - 多平台适配

多平台适配 11-1&#xff1a;开篇 在上一章中&#xff0c;我们知道了&#xff0c;当【慕课热搜】运行到 h5 端的时候&#xff0c;那么会出现一些问题&#xff0c;这些问题具体有&#xff1a; hot 列表滚动&#xff0c;tabs 置顶效果消失在火狐浏览器中&#xff0c;横线出现非…

kafka-kafka集群配置、kafka集群启动创建kafka主题、获取主题数据

本文章使用三台主机&#xff0c;分别为&#xff1a;master、slave1、slave2 一、解压kafka安装包至目录下 tar -zxvf kafka_2.12-2.4.1.tgz -C /需要放置的路径/ 二、修改配置文件 server.properties 该配置在kafka目录的config目录下 #修改文件中id数值 broker.id0 kafka集群…

Linux -- Web服务器-Apache 快速安装及主配置文件分析

目录 快速安装 Apache : 预处理 &#xff1a; 关闭安全上下文检测 : 关闭防火墙 : 启动 Apache 服务 &#xff08; 启动 httpd &#xff09;: 测试 &#xff1a; 主配置文件分析 &#xff1a; 常见配置文件所在位置 &#xff1a; 目录文件结构 &#xff1a;…

购物车--订单模块,练习完成

目标&#xff1a; 在购物车页面&#xff0c;增加一个创建订单的超链接。通过创建订单&#xff0c;在Order表里新增一条数据&#xff0c;同时把session中的订单条目都保存到数据库中。 1、创建两个表&#xff0c;orders用来具体存储每一个订单的细节&#xff0c;order_用来存储…

基于MobileNetV2的Transfer Learning模型,实现物体检测(附源码)

文章目录 一、MobileNet1. 深度可分离卷积&#xff08;Depthwise separable convolution&#xff09;2. MobileNet V13. MobileNet V2 二、物体检测源码&#xff08;基于MobileNetV2&#xff09; 一、MobileNet 1. 深度可分离卷积&#xff08;Depthwise separable convolution…

智慧园区综合管理平台开发基本功能有哪些?

随着智慧城市建设与信息化发展&#xff0c;园区管理也需要更加智能便捷化&#xff0c;于是智慧园区管理系统开发应运而生。智慧园区综合管理系统就是利用物联网、大数据等技术工具&#xff0c;顺应产业园区升级发展需求&#xff0c;实现园区环境、设备、安全、基础管理、资源服…

【Linux】进程间通信——命名管道

文章目录 命名管道1. 见一见管道文件mkfifo函数管道文件的使用 2. 命名管道原理如何保证两个毫不相关的进程&#xff0c;看到的是同一个文件&#xff0c;并打开&#xff1f; 3. 用命名管道实现server&client通信如何使用makefile连续生成可执行程序comm.hpp文件server.cc 服…

如何通过 Baklib 平台实现知识共享(内含案例介绍)

在这个信息时代&#xff0c;知识被认为是最重要的资源之一。企业要想保持发展&#xff0c;就必须善于利用和管理知识。而知识管理则是一种涵盖人、过程和技术的活动&#xff0c;它通过收集、整理、传递和应用知识&#xff0c;使组织获得更高的效率、创造力和竞争力。本文将以知…

【Linux】八、Linux进程信号详解(一)

目录 一、认识信号 1.1 生活中的信号 1.2 将1.1的概念迁移到进程 1.3 信号概念 1.4 查看系统定义信号列表 1.5 man 7 signal 1.6 解释1.2的代码样例 1.7 信号处理常见方式概览 二、产生信号 2.1 signal函数 2.2 通过终端按键产生信号 2.3 调用系统函数向进程发信号…

前后端的身份认证【Node.js】

1. 前后端的身份认证 1.1 Web 开发模式 目前主流的 Web 开发模式有两种&#xff0c;分别是&#xff1a; &#xff08;1&#xff09;基于服务端渲染的传统 Web 开发模式 &#xff08;2&#xff09;基于前后端分离的新型 Web 开发模式 服务端渲染的传统 Web 开发模式 服务端渲染…

力扣面试题 08.06. 汉诺塔问题:思路分析+图文详解+代码实现

文章目录 第一部分&#xff1a;问题描述1.1 题目1.2 示例&#x1f340; 示例一&#x1f340; 示例二 1.3 提示 第二部分&#xff1a;思路分析第三部分&#xff1a;代码实现 第一部分&#xff1a;问题描述 1.1 题目 &#x1f3e0; 链接&#xff1a;面试题 08.06. 汉诺塔问题 -…

windows安装rabbitmq和环境erlang(最详细版,包括对应关系)

写在最前&#xff1a;不知何时起安装一个mq需要翻无数文章才能安上了&#xff0c;没有一个讲全的&#xff0c;这里写一个详细的教程。 删除旧版本对应关系: 1.在官方文档中找到RabbitMQ版本对应的Erlang版本重新下载安装包文档RabbitMQ Erlang Version Requirements — Rabbit…

大家副业都在做什么?csgo搬砖靠谱的副业推荐给你

从来没想过&#xff0c;以前只会玩CSGO的男孩子&#xff0c;现在居然能借助游戏赚到钱了&#xff01;甚至不需要什么专业的技巧&#xff0c;简简单单 在steam平台选择有利润的道具后&#xff0c;再上架到国内网易BUFF平台&#xff0c;赚取“信息差”差价而已&#xff01; 谁大…