mask-rcnn的解读(三):batch_slice()
我已用随机生产函数取模拟5张图片各有8个box的坐标值,而后验证batch_slice()函数的意义。
由于inputs_slice = [x[i] for x in inputs] output_slice = graph_fn(*inputs_slice)
代码一时蒙蔽,故而对其深入理解,如下: 代码如下:
import tensorflow as tf
import random
import numpy as np
sess=tf.Session()
input=np.array([random.randint(0,150) for i in range(5*8*4)]).reshape((5,8,4))
# print('show input=',input)
ax=np.array([random.randint(0,7) for i in range(5*6)]).reshape((5,6))
inputs=[input,ax]
print('true_inputs=',inputs) def batch_slice(inputs, graph_fn, batch_size, names=None):
"""Splits inputs into slices and feeds each slice to a copy of the given
computation graph and then combines the results. It allows you to run a
graph on a batch of inputs even if the graph is written to support one
instance only. inputs: list of tensors. All must have the same first dimension length
graph_fn: A function that returns a TF tensor that's part of a graph.
batch_size: number of slices to divide the data into.
names: If provided, assigns names to the resulting tensors.
"""
if not isinstance(inputs, list): # 判断inputs是否为list类型
inputs = [inputs] outputs = []
for i in range(batch_size):
inputs_slice = [x[i] for x in inputs] # 是一个二维矩阵(去掉了图片张数的维度)# 表示切batch_size,即原来有5个图片,现在截取batch_size=3个图片
output_slice = graph_fn(*inputs_slice) # 根据ax值取值
if not isinstance(output_slice, (tuple, list)):
output_slice = [output_slice]
outputs.append(output_slice)
# Change outputs from a list of slices where each is
# a list of outputs to a list of outputs and each has
# a list of slices
outputs = list(zip(*outputs))
if names is None:
names = [None] * len(outputs)
result = [tf.stack(o, axis=0, name=n) for o, n in zip(outputs, names)]
if len(result) == 1:
result = result[0]
return result d=pre_nms_anchors = batch_slice(inputs, lambda a, x: tf.gather(a, x), 3, names=["pre_nms_anchors"])
d=sess.run(d)
print('result',d) # 最终结果
print('show value=',[x for x in inputs]) # 与下面代码比较,理解inputs_slice = [x[i] for x in inputs]的意义
for i in range(2):
inputs_slice = [x[i] for x in inputs]
print('%id='%(i),inputs_slice)
print('show inputs_slice=',inputs_slice) 结果如下:
true_inputs= [array([[[102, 7, 45, 34],
[ 19, 105, 82, 83],
[ 84, 89, 70, 8],
[ 57, 81, 138, 122],
[ 69, 54, 61, 116],
[108, 120, 46, 122],
[102, 29, 39, 97],
[ 49, 92, 117, 52]],
[[ 52, 124, 86, 86],
[ 54, 9, 70, 104],
[102, 27, 29, 119],
[124, 82, 17, 4],
[ 53, 87, 69, 98],
[127, 106, 80, 40],
[ 78, 121, 84, 28],
[ 86, 111, 129, 149]],
[[112, 98, 89, 142],
[ 20, 134, 40, 50],
[139, 101, 99, 99],
[140, 60, 148, 49],
[ 49, 113, 26, 58],
[143, 85, 96, 142],
[ 42, 70, 16, 123],
[ 12, 92, 77, 143]],
[[136, 137, 31, 31],
[ 78, 28, 32, 87],
[ 39, 12, 124, 47],
[100, 96, 131, 12],
[111, 27, 28, 118],
[ 14, 130, 16, 43],
[ 77, 127, 69, 60],
[ 62, 53, 85, 95]],
[[ 17, 112, 122, 149],
[ 5, 89, 40, 105],
[ 49, 128, 128, 121],
[ 25, 1, 31, 52],
[127, 149, 9, 115],
[ 37, 103, 114, 119],
[130, 23, 29, 86],
[ 46, 111, 101, 69]]]), array([[3, 2, 6, 7, 2, 6],
[1, 1, 0, 6, 1, 7],
[1, 7, 0, 6, 6, 6],
[6, 3, 7, 7, 6, 0],
[0, 7, 4, 6, 3, 0]])]
result [[[ 57 81 138 122]
[ 84 89 70 8]
[102 29 39 97]
[ 49 92 117 52]
[ 84 89 70 8]
[102 29 39 97]]
[[ 54 9 70 104]
[ 54 9 70 104]
[ 52 124 86 86]
[ 78 121 84 28]
[ 54 9 70 104]
[ 86 111 129 149]]
[[ 20 134 40 50]
[ 12 92 77 143]
[112 98 89 142]
[ 42 70 16 123]
[ 42 70 16 123]
[ 42 70 16 123]]]
show value= [array([[[102, 7, 45, 34],
[ 19, 105, 82, 83],
[ 84, 89, 70, 8],
[ 57, 81, 138, 122],
[ 69, 54, 61, 116],
[108, 120, 46, 122],
[102, 29, 39, 97],
[ 49, 92, 117, 52]],
[[ 52, 124, 86, 86],
[ 54, 9, 70, 104],
[102, 27, 29, 119],
[124, 82, 17, 4],
[ 53, 87, 69, 98],
[127, 106, 80, 40],
[ 78, 121, 84, 28],
[ 86, 111, 129, 149]],
[[112, 98, 89, 142],
[ 20, 134, 40, 50],
[139, 101, 99, 99],
[140, 60, 148, 49],
[ 49, 113, 26, 58],
[143, 85, 96, 142],
[ 42, 70, 16, 123],
[ 12, 92, 77, 143]],
[[136, 137, 31, 31],
[ 78, 28, 32, 87],
[ 39, 12, 124, 47],
[100, 96, 131, 12],
[111, 27, 28, 118],
[ 14, 130, 16, 43],
[ 77, 127, 69, 60],
[ 62, 53, 85, 95]],
[[ 17, 112, 122, 149],
[ 5, 89, 40, 105],
[ 49, 128, 128, 121],
[ 25, 1, 31, 52],
[127, 149, 9, 115],
[ 37, 103, 114, 119],
[130, 23, 29, 86],
[ 46, 111, 101, 69]]]), array([[3, 2, 6, 7, 2, 6],
[1, 1, 0, 6, 1, 7],
[1, 7, 0, 6, 6, 6],
[6, 3, 7, 7, 6, 0],
[0, 7, 4, 6, 3, 0]])]
0d= [array([[102, 7, 45, 34],
[ 19, 105, 82, 83],
[ 84, 89, 70, 8],
[ 57, 81, 138, 122],
[ 69, 54, 61, 116],
[108, 120, 46, 122],
[102, 29, 39, 97],
[ 49, 92, 117, 52]]), array([3, 2, 6, 7, 2, 6])]
1d= [array([[ 52, 124, 86, 86],
[ 54, 9, 70, 104],
[102, 27, 29, 119],
[124, 82, 17, 4],
[ 53, 87, 69, 98],
[127, 106, 80, 40],
[ 78, 121, 84, 28],
[ 86, 111, 129, 149]]), array([1, 1, 0, 6, 1, 7])]
show inputs_slice= [array([[ 52, 124, 86, 86],
[ 54, 9, 70, 104],
[102, 27, 29, 119],
[124, 82, 17, 4],
[ 53, 87, 69, 98],
[127, 106, 80, 40],
[ 78, 121, 84, 28],
[ 86, 111, 129, 149]]), array([1, 1, 0, 6, 1, 7])]
Process finished with exit code 0
mask-rcnn的解读(三):batch_slice()的更多相关文章
- CVPR2019 | Mask Scoring R-CNN 论文解读
Mask Scoring R-CNN CVPR2019 | Mask Scoring R-CNN 论文解读 作者 | 文永亮 研究方向 | 目标检测.GAN 推荐理由: 本文解读的是一篇发表于CVPR ...
- 论文阅读笔记三十六:Mask R-CNN(CVPR2017)
论文源址:https://arxiv.org/pdf/1703.06870.pdf 开源代码:https://github.com/matterport/Mask_RCNN 摘要 Mask R-CNN ...
- 目标检测论文解读11——Mask R-CNN
目的 让Faster R-CNN能做实例分割的任务. 方法 模型的结构图如下. 与Faster R-CNN相比,主要有两点变化. (1) 用RoI Align替代RoI Pool. 首先回顾一下RoI ...
- CVPR2019 | Libra R-CNN 论文解读
作者 | 文永亮 学校 | 哈尔滨工业大学(深圳) 研究方向 | 目标检测.GAN 推荐理由 这是一篇发表于CVPR2019的paper,是浙江大学和香港中文大学的工作,这篇文章十分有趣,网友戏称 ...
- [Network Architecture]Mask R-CNN论文解析(转)
前言 最近有一个idea需要去验证,比较忙,看完Mask R-CNN论文了,最近会去研究Mask R-CNN的代码,论文解析转载网上的两篇博客 技术挖掘者 remanented 文章1 论文题目:Ma ...
- Mask RCNN 学习笔记
下面会介绍基于ResNet50的Mask RCNN网络,其中会涉及到RPN.FPN.ROIAlign以及分类.回归使用的损失函数等 介绍时所采用的MaskRCNN源码(python版本)来源于GitH ...
- 物体检测之FPN及Mask R-CNN
对比目前科研届普遍喜欢把问题搞复杂,通过复杂的算法尽量把审稿人搞蒙从而提高论文的接受率的思想,无论是著名的残差网络还是这篇Mask R-CNN,大神的论文尽量遵循著名的奥卡姆剃刀原理:即在所有能解决问 ...
- Mask R-CNN详解和安装
Detectron是Facebook的物体检测平台,今天宣布开源,它基于Caffe2,用Python写成,这次开放的代码中就包含了Mask R-CNN的实现. 除此之外,Detectron还包含了IC ...
- Mask R-CNN论文理解
摘要: Mask RCNN可以看做是一个通用实例分割架构. Mask RCNN以Faster RCNN原型,增加了一个分支用于分割任务. Mask RCNN比Faster RCNN速度慢一些,达到了5 ...
- [代码解析]Mask R-CNN介绍与实现(转)
文章来源 DFann 版权声明:如果你觉得写的还可以,可以考虑打赏一下.转载请联系. https://blog.csdn.net/u011974639/article/details/78483779 ...
随机推荐
- 最好用的koa2+mysql的RESTful API脚手架,mvc架构,支持node调试,pm2部署。
#基于webpack构建的 Koa2 restful API 服务器脚手架 这是一个基于 Koa2 的轻量级 RESTful API Server 脚手架,支持 ES6, 支持使用TypeSc ...
- SpringBoot(一):构建第一个SpringBoot工程
1.项目格式如下: 1.启动类: package com.monkey01.springbootstart; import org.springframework.boot.SpringApplica ...
- QP编码详解
- 原理 QP编码是一种使用可打印的ASCII字符 (如字母.数字与"=")表示各种编码格式下的字符.其方法是将一个8bit的字符表示成两个16进制数,并在前面加一个"= ...
- zabbix4.0搭建2
server端(ip 192.168.200.15) proxy端(ip 192.168.200.22) agent端(ip 192.168.200.12) server端: #安装数据库 [mari ...
- 【JavaScript】使用document.write输出覆盖HTML问题
您只能在 HTML 输出中使用 document.write.如果您在文档加载后使用该方法,会覆盖整个文档. 分析 HTML输出流是指当前数据形式是HTML格式的数据,这部分数据正在被导出.传输或显示 ...
- Linux PXE + Kickstart 自动装机
大规模装机时,使用无人值守装机便可大大简便人工操作,提高效率. PXE 网络安装 配置双网卡 这里ens33为nat网络,ens37为仅主机网络,配置ens37 [root@localhost ~]# ...
- [Go] imap收信非并发
待修正 package main import ( "flag" "fmt" "io/ioutil" "log" &qu ...
- CUDA -- 规约求矩阵的行和
求矩阵每行的和? 可以把每行放入一个不同线程块,这样行与行之间进行粗粒度的并行.而对于每行,其对应的线程块中分配n个线程(对应行宽),使用共享存储器,让每个线程从显存中读取一个数至shared mem ...
- assets文件夹与static文件夹的区别
assets文件夹与static文件夹的区别原地址==>https://www.cnblogs.com/x123811/p/9230700.html 相同点===>assets文件夹和st ...
- 6.Python网络编程_全局变量基础
变量作用域: 一般在函数体外定义的变量成为全局变量,在函数内部定义的变量称为局部变量.全局变量所有作用域都可用,局部变量只能在本函数可用,变量的使用顺序是,局部变量 > 全局变量, 也就是说:优 ...