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. 04Hibernate连接数据库环境配置

    Hibernate连接数据库环境配置

  2. 09C++指针

    指针 6.1 指针的概念 请务必弄清楚一个内存单元的地址与内存单元的内容这两个概念的区别.在程序中一般是通过变量名来对内存单元进行存取操作的.其实程序经过编译以后已经将变量名转换为变量的地址,对变量值 ...

  3. 查找BUG的方法

    1)测试环境 1)代码调试 2)问题重现 3)思考问题所在 2)生产环境 1)思考 2)测试本地环境是否存在问题 3)打开日志查看 4)思考是否是数据原因 5)拷贝数据到本地进行重现 3)未知错误 1 ...

  4. 使用ajax出现canceled情况

    在使用ajax的时候要注意,在只定义了一个ajax请求对象的全局变量时,如果同打开发送了一个请求,但在请求还未结束时,又利用这一个全局变量发送另外一个ajax请求,就会出现某一个请求的状态码为canc ...

  5. 零基础入门学习Python(30)--文件系统:介绍一个高大上的东西

    知识点 os,os.path模块中关于文件.目录常用的函数使用方法 在使用os模块,需要先进行import操作: import os os模块中关于文件/目录常用的函数使用方法 函数名 函数作用 示例 ...

  6. 【转】Delphi 文件拖放

    转自:万一的博客. 原理分析: 这需要用到 ShellAPI 单元的两个函数: DragAcceptFiles.DragQueryFile; 用 DragAcceptFiles(窗口句柄, True) ...

  7. Go:工厂模式

    Go的结构体没有构造函数,通常可以使用工厂模式来解决这个问题. 一个结构体的声明是这样的: package model type Student struct { Name string } 因为 S ...

  8. mysql查询排名

    student_work表 student_info表 sql语句:按grade从高到低排名 结果:

  9. 升级到Offiec 2016后 Power View 不见了的处理方法

    好吧 并不是没有了,而只是快捷方式需要手动的调整出来, 过程还是挺复杂,给一个官方文档吧. Turn on Power View in Excel 2016 for Windows https://s ...

  10. HDU 1525 Euclid Game

    题目大意: 给定2个数a , b,假定b>=a总是从b中取走一个a的整数倍,也就是让 b-k*a(k*a<=b) 每人执行一步这个操作,最后得到0的人胜利结束游戏 (0,a)是一个终止态P ...