HF-NET使用记录
HF-Net是用来重定位的,也就是来一个查询帧query,去数据库中查找与哪一个图像匹配。
项目地址:https://github.com/ethz-asl/hfnet
环境配置
- 首先作者提供了一个训练好的模型可供下载
- 下载很慢,我提供个百度云,提取码: qiis
- 下载下来后放到saved_models目录下即可
- 要求的tensorflow版本是1.12
- 而且cudnn必须是7.1.4,这是运行是报错时提示的
- CUDA的版本9.0就好
Demo脚本
# coding: utf-8# In[ ]:import cv2
import numpy as np
from pathlib import Path
import picklefrom hfnet.settings import EXPER_PATH
from notebooks.utils import plot_images, plot_matches, add_frameimport tensorflow as tf
from tensorflow.python.saved_model import tag_constants
import tf.contrib.resampler # import C++ op !!这一行不能删除# # Load query (night) and database (day) images# In[2]:query_idx = 1 # also try with 2 and3
read_image = lambda n: cv2.imread('./doc/demo/' + n)[:, :, ::-1]
image_query = read_image(f'query{query_idx}.jpg')
images_db = [read_image(f'db{i}.jpg') for i in range(1, 5)]plot_images([image_query] + images_db, dpi=50)# # Create HF-Net model for inference# In[ ]:class HFNet:def __init__(self, model_path, outputs):self.session = tf.Session()self.image_ph = tf.placeholder(tf.float32, shape=(None, None, 3))net_input = tf.image.rgb_to_grayscale(self.image_ph[None])tf.saved_model.loader.load(self.session, [tag_constants.SERVING], str(model_path),clear_devices=True,input_map={'image:0': net_input})graph = tf.get_default_graph()self.outputs = {n: graph.get_tensor_by_name(n+':0')[0] for n in outputs}self.nms_radius_op = graph.get_tensor_by_name('pred/simple_nms/radius:0')self.num_keypoints_op = graph.get_tensor_by_name('pred/top_k_keypoints/k:0')def inference(self, image, nms_radius=4, num_keypoints=1000):inputs = {self.image_ph: image[..., ::-1].astype(np.float),self.nms_radius_op: nms_radius,self.num_keypoints_op: num_keypoints,}return self.session.run(self.outputs, feed_dict=inputs)model_path = Path(EXPER_PATH, 'saved_models/hfnet')
outputs = ['global_descriptor', 'keypoints', 'local_descriptors']
hfnet = HFNet(model_path, outputs)# # Compute global descriptors and local features for query and database
# In[4]:db = [hfnet.inference(i) for i in images_db]
global_index = np.stack([d['global_descriptor'] for d in db])
query = hfnet.inference(image_query)# # Perform a global search in the database
# In[5]:def compute_distance(desc1, desc2):# For normalized descriptors, computing the distance is a simple matrix multiplication.return 2 * (1 - desc1 @ desc2.T)# In[6]:nearest = np.argmin(compute_distance(query['global_descriptor'], global_index))
disp_db = [add_frame(im, (0, 255, 0)) if i == nearest else imfor i, im in enumerate(images_db)]
plot_images([image_query] + disp_db, dpi=50)# # Perform local matching with the retrieved image# In[7]:def match_with_ratio_test(desc1, desc2, thresh):dist = compute_distance(desc1, desc2)print(dist.shape)nearest = np.argpartition(dist, 2, axis=-1)[:, :2]dist_nearest = np.take_along_axis(dist, nearest, axis=-1)valid_mask = dist_nearest[:, 0] <= (thresh**2)*dist_nearest[:, 1]matches = np.stack([np.where(valid_mask)[0], nearest[valid_mask][:, 0]], 1)return matches# In[22]:matches = match_with_ratio_test(query['local_descriptors'],db[nearest]['local_descriptors'], 0.8)plot_matches(image_query, query['keypoints'],images_db[nearest], db[nearest]['keypoints'],matches, color=(0, 1, 0), dpi=50)
报错
- 我这边召回是可以运行的,但是进行特征点匹配时,那个np.take_along_axis函数始终无法运行,应该是numpy版本问题
HF-NET使用记录相关推荐
- Proxmark3常用命令
1.1常用类 help 显示帮助. hw help 与 hw 是等价的. data 图形窗口/缓冲区数据操作等等 exit 退出Proxmark3的终端环境 hf 高频相关命令 hw 硬件检测相关命令 ...
- 【记录】python3 tkinterUI编辑器应用之索尼walkmanA35播放列表编辑工具
tkinterUI编辑器应用(二) 前言 一.工具使用说明 二.分析播放列表文件 三.tinytag读取歌曲信息 四.treeview列表模式时点击标题进行排序 五.主文件代码,其他代码这里就不展示了 ...
- 浪潮HF系列闪存存储:不仅看性能,更看整体表现
背景:浪潮HF系列闪存存储是IT融合架构的基础,可支持核心数据库业务应用.服务器和桌面虚拟化架构.消息协同环境,并适应Microsoft.VMware.Citrix.Oracle.SAP.CISCO. ...
- 国产安路FPGA(一)-TD软件使用及问题记录
国产安路FPGA(一)-TD软件使用及问题记录 一.概述 本次博客为系列博客,仅是为了记录再使用国产安路各种芯片和软件使用工具上的问题以及解决方式. TD软件所使用的版本为TD5.0.5_SP1-64 ...
- 我今天给学习运维而英语不好的各位,提供一些计算机英语,感谢惨绿少年的原文和已经离开身边提供英标部分的小虾大佬,只是为了记录。...
1.file,n.文件:v.保存文件 [faɪl] 2.command,n.命令,指令 [kəˈmænd] 3.use,v.使用,用途 [jus] 4.program,n.程序 [ˈproʊgræm] ...
- 西门子et200 分布式i/o_西门子S7-1200/1500的硬件数据记录(1)-参数数据记录
通过使用分布式IO读指令(比如RDREC)或者写指令(比如WRREC),可以读取或写入西门子S7-1200/1500/ET200SP/ET200MP等硬件模块的数据记录.数据记录是模块硬件的固有属性, ...
- csr8670--不能不知道的基本知识,长期记录
1.设备的状态 设备上电之后,系统会用相应的状态标志来描述设备的状态 Limbo:逻辑上关,物理上开,可以理解为手机安装了电池但是没有开机,这个状态下是不能处理任务的,所以上电之后首先要做的就是开机 ...
- 实验5 基于stm32的HF高频RFID通信协议
实验5 基于stm32的HF高频RFID通信协议 实验目的 1.1 掌握高频读卡器的通讯协议 1.2 掌握本平台高频模块的操作过程 1.3 掌握高频模块工作原理 实验设备 硬件:RFID实验箱套 ...
- Access VBA 代码记录
Option Compare DatabasePrivate Sub Combo4_AfterUpdate()Dim index As StringDim county As Stringindex ...
- 微软收购暴雪计划遭拒/ Edge被曝泄露浏览记录/ 微信小程序可用数字人民币...今日更多新鲜事在此...
日报君 发自 凹非寺 量子位 | 公众号 QbitAI 大家好,今天是4月27日星期四,是这个月倒数第二天上班了~ 在假期可以翘首以待的日子里,还是来和日报君看看今天的科技圈资讯吧~ 微信支持数字人民 ...
最新文章
- WebStorm 2018版本破解方法
- akb48_AKB48里历史——六年的终结
- 技术人员必备的学习工具
- 基础知识的困惑让BUG更隐蔽
- 申报指南大全!湖北省各市科技型中小企业申报流程6步走
- ZZULIOJ1010
- 英伟达显卡最新驱动安装过程
- html测试身高体重,【 身高体重测试】_如何测试_注意事项-大众养生网
- 蚂蚁上市招股书:员工持股40%月薪人均5万,直奔财富自由
- ckplayer无法播放问题?
- 【记录】关于编码格式导致的中文乱码问题
- 2022春招第一波投递时间预测,早看早知道
- JavaScript 计算地下城堡2资源何时满仓
- 通过LiveNVS(免费使用)集中化管理多个LiveNVR-数据透传摆脱局域网的公网IP限制
- 擎天哥as3教程系列第四回——设计模式运用自如
- Java 获取当前年,前几年(之前年),后几年(之后年)
- camera申请buf流程
- autocad 2021 mac中文版
- 没有乔布斯的MacWorld :8个瞬间
- 如何准备大厂技术面试?偷学「大师兄」秘籍!
热门文章
- Ipopt开发环境安装
- 如何解决企业生产计划做不好,生产管理混乱?
- tensorflow分类图片预处理
- The following packages have unmet dependencies: deepin.com.wechat:i386 : Depends: deepin-wine:i386
- Mondrian 4 测试的简单demo(Saiku简单测试Schema文件)
- 【无标题】鱼池转发命令
- cadence元件库文件位置
- oa是什么意思?oa系统哪个好用?
- RSRP/RSRQ/RSSI/RS-SINR/RS-CINR/RSCP
- python 实现简单的session登录