1.padding test

input = tf.placeholder(tf.float32, shape=(1,2, 2,1))
simpleconv=slim.conv2d(input,1,[3,3],stride = 1,activation_fn = None,scope = 'simpleconv3')
sess.run(tf.global_variables_initializer())
weights=graph.get_tensor_by_name("simpleconv3/weights:0")
sess.run(tf.assign(weights,tf.constant(1.0,shape=weights.shape)))
a=np.ndarray(shape=(1,2,2,1),dtype='float',buffer=np.array([1.0,2,3,4]))
simpleconvout=sess.run(simpleconv,feed_dict={input:a.astype('float32')})
print simpleconvout
[[[[ 10.000000]
[ 10.000000]] [[ 10.000000]
[ 10.000000]]]] input1 = tf.placeholder(tf.float32, shape=(1,4, 4,1))
simpleconv=slim.conv2d(input1,1,[3,3],stride = 2,activation_fn = None,scope = 'simpleconv3')
sess.run(tf.global_variables_initializer())
weights=graph.get_tensor_by_name("simpleconv3/weights:0")
sess.run(tf.assign(weights,tf.constant(1.0,shape=weights.shape)))
a=np.ndarray(shape=(1,4,4,1),dtype='float',buffer=np.array([1.0,2,3,4,2,3,4,5,3,4,5,6,4,5,6,7]))
simpleconvout=sess.run(simpleconv,feed_dict={input1:a.astype('float32')}) print simpleconvout [[[[ 27.]
[ 27.]] [[ 27.]
[ 24.]]]] simpledeconv=slim.conv2d_transpose(input,1,[3,3],stride = 2,activation_fn = None,scope = 'simpledeconv')
sess.run(tf.global_variables_initializer())
weights=graph.get_tensor_by_name("simpledeconv/weights:0")
sess.run(tf.assign(weights,tf.constant(1.0,shape=weights.shape)))
a=np.ndarray(shape=(1,2,2,1),dtype='float',buffer=np.array([1.0,2,3,4]))
simpleconvout=sess.run(simpledeconv,feed_dict={input:a.astype('float32')})
print simpleconvout [[[[ 1.000000]
[ 1.000000]
[ 3.000000]
[ 2.000000]] [[ 1.000000]
[ 1.000000]
[ 3.000000]
[ 2.000000]] [[ 4.000000]
[ 4.000000]
[ 10.000000]
[ 6.000000]] [[ 3.000000]
[ 3.000000]
[ 7.000000]
[ 4.000000]]]] conv stride=1是四周padding 0,stride=2是down right padding 0 deconv是top left各插了两行0 而torch中的deconv是四周padding一圈0

参考http://blog.csdn.net/lujiandong1/article/details/53728053

'SAME' padding方式时,如果padding的数目是奇数,则多的padding在右边(下边)

2.实现custom-padding

https://stackoverflow.com/questions/37659538/custom-padding-for-convolutions-in-tensorflow

实现custom conv decon
def conv(input,num_outputs,kernel_size,stride=1,padW=0,padH=0,activation_fn=None,scope=None):
padded_input = tf.pad(input, [[0, 0], [padH, padH], [padW, padW], [0, 0]], "CONSTANT")
return slim.conv2d(padded_input,num_outputs,kernel_size,stride = stride,padding="VALID",activation_fn = activation_fn ,scope = scope)
input1 = tf.placeholder(tf.float32, shape=(1,4, 4,1))
a=np.ndarray(shape=(1,4,4,1),dtype='float',buffer=np.array([1.0,2,3,4,2,3,4,5,3,4,5,6,4,5,6,7]))
simpleconv=conv(input1,1,[3,3],stride = 2,padW=1,padH=1,activation_fn = None,scope = 'conv')
sess.run(tf.global_variables_initializer())
weights=graph.get_tensor_by_name("conv/weights:0")
sess.run(tf.assign(weights,tf.constant(1.0,shape=weights.shape)))
simpleconvout=sess.run(simpleconv,feed_dict={input1:a.astype('float32')})
print simpleconvout
[[[[ 8.]
[ 21.]] [[ 21.]
[ 45.]]]] def deconv(input,num_outputs,kernel_size,stride=2,activation_fn=None,scope=None):
N,H,W,C = [i.value for i in input.get_shape()]
out = slim.conv2d_transpose(input,num_outputs,kernel_size,stride = stride,padding="VALID",activation_fn = activation_fn ,scope = scope)
return tf.slice(out, [0, kernel_size[0]/2,kernel_size[1]/2, 0], [N, H*stride, W*stride,num_outputs]) input = tf.placeholder(tf.float32, shape=(1,2, 2,1))
a=np.ndarray(shape=(1,2,2,1),dtype='float',buffer=np.array([1.0,2,3,4]))
simpledeconv=deconv(input,1,[3,3],stride = 2,activation_fn = None,scope = 'simpledeconv1')
sess.run(tf.global_variables_initializer())
weights=graph.get_tensor_by_name("simpledeconv1/weights:0")
sess.run(tf.assign(weights,tf.constant(1.0,shape=weights.shape)))
out=sess.run(simpledeconv,feed_dict={input:a.astype('float32')})
print out [[[[ 1.]
[ 3.]
[ 2.]
[ 2.]] [[ 4.]
[ 10.]
[ 6.]
[ 6.]] [[ 3.]
[ 7.]
[ 4.]
[ 4.]] [[ 3.]
[ 7.]
[ 4.]
[ 4.]]]]

tesnorflow conv deconv,padding的更多相关文章

  1. 深度学习卷积网络中反卷积/转置卷积的理解 transposed conv/deconv

    搞明白了卷积网络中所谓deconv到底是个什么东西后,不写下来怕又忘记,根据参考资料,加上我自己的理解,记录在这篇博客里. 先来规范表达 为了方便理解,本文出现的举例情况都是2D矩阵卷积,卷积输入和核 ...

  2. 论文阅读(Xiang Bai——【arXiv2016】Scene Text Detection via Holistic, Multi-Channel Prediction)

    Xiang Bai--[arXiv2016]Scene Text Detection via Holistic, Multi-Channel Prediction 目录 作者和相关链接 方法概括 创新 ...

  3. 论文笔记:Mask R-CNN

    之前在一次组会上,师弟诉苦说他用 UNet 处理一个病灶分割的任务,但效果极差,我看了他的数据后发现,那些病灶区域比起整张图而言非常的小,而 UNet 采用的损失函数通常是逐像素的分类损失,如此一来, ...

  4. 本人AI知识体系导航 - AI menu

    Relevant Readable Links Name Interesting topic Comment Edwin Chen 非参贝叶斯   徐亦达老板 Dirichlet Process 学习 ...

  5. 【文献阅读】Densely Connected Convolutional Networks-best paper-CVPR-2017

    Densely Connected Convolutional Networks,CVPR-2017-best paper之一(共两篇,另外一篇是apple关于GAN的paper),早在去年八月 De ...

  6. 如何快速使用YOLO3进行目标检测

    本文目的:介绍一篇YOLO3的Keras实现项目,便于快速了解如何使用预训练的YOLOv3,来对新图像进行目标检测. 本文使用的是Github上一位大神训练的YOLO3开源的项目.这个项目提供了很多使 ...

  7. YOLO v3算法介绍

    图片来自https://towardsdatascience.com/yolo-v3-object-detection-with-keras-461d2cfccef6 数据前处理 输入的图片维数:(4 ...

  8. LCD: 2D-3D匹配算法

    LCD: 2D-3D匹配算法 标题:LCD:Learned Cross-Domain Descriptors for 2D-3D Matching 作者:Quang-Hieu Pham, Mikael ...

  9. dilated conv、deconv、fractional-strided conv

    deconv的其中一个用途是做upsampling,即增大图像尺寸. dilated convolution: dilated conv,中文可以叫做空洞卷积或者扩张卷积. 首先是诞生背景,在图像分割 ...

随机推荐

  1. JavaSE-08 封装

    学习要点 封装 访问控制符 包 封装 没有封装的代码有何缺陷? 例如:对狗狗的健康值赋值为-100.如何避免?——使用封装. 封装的概念 将类的某些信息隐藏在类内部,不允许外部程序直接访问,而是通过该 ...

  2. oracle调用存储过程和函数返回结果集

    在程序开发中,常用到返回结果集的存储过程,这个在mysql和sql server 里比较好处理,直接返回查询结果就可以了,但在oracle里面 要 out 出去,就多了一个步骤,对于不熟悉的兄弟们还得 ...

  3. Android获取屏幕的大小与密度的代码

    Android项目开发中很多时候需要获取手机屏幕的宽高以及屏幕密度来进行动态布局,这里总结了三种获取屏幕大小和屏幕密度的方法 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ...

  4. Linux安装64位Mysql5.7.22

    以安装在/usr/local目录下为例 1.下载安装包地址:https://dev.mysql.com/downloads/file/?id=476936,安装包保存到/usr/local 2.解压: ...

  5. MRC转ARC

    转载请注明出处:http://blog.csdn.net/cywn_d/article/details/18222671 1.删除所有retain,release和autorelease. 2.把原来 ...

  6. python 1-1模块介绍和使用

    1. 什么是模块 1.1 模块就是一系列功能的集合体 1.1.1 模块有三种来源 1.内置的模块 2.第三方的模块 3.自定义模块 1.1.2 模块的格式: 1.使用Python编写的.py文件 2. ...

  7. Swagger UI教程

    文档源地址 http://www.68idc.cn/help/makewebs/qitaasks/20160621620667.html Swagger-UI本身只提供在线测试功能,要集成它还需要告诉 ...

  8. C51 矩阵按键 个人笔记

    矩阵按键 电路 每个按键一端和同行一端相连(JP4的高4位),另一端和同列一端相连(JP4的低4位) 判断按键是否按下: 法一:逐行扫描 for(int i = 8 ; i>3 ; i-- ) ...

  9. CodeForcesGym 100512D Dynamic LCA

    Dynamic LCA Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForcesGym. ...

  10. BNUOJ 9870 Contestants Division

    Contestants Division Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVALiv ...