tf.pad()文档如下,

pad(tensor, paddings, mode='CONSTANT', name=None, constant_values=0)
    Pads a tensor.
    
    This operation pads a `tensor` according to the `paddings` you specify.
    `paddings` is an integer tensor with shape `[n, 2]`, where n is the rank of
    `tensor`. For each dimension D of `input`, `paddings[D, 0]` indicates how
    many values to add before the contents of `tensor` in that dimension, and
    `paddings[D, 1]` indicates how many values to add after the contents of
    `tensor` in that dimension. If `mode` is "REFLECT" then both `paddings[D, 0]`
    and `paddings[D, 1]` must be no greater than `tensor.dim_size(D) - 1`. If
    `mode` is "SYMMETRIC" then both `paddings[D, 0]` and `paddings[D, 1]` must be
    no greater than `tensor.dim_size(D)`.
    
    The padded size of each dimension D of the output is:
    
    `paddings[D, 0] + tensor.dim_size(D) + paddings[D, 1]`

实际使用注意,参数paddings元素数(rank)必须和输入维度一一对应,表示该维度前后填充的层数,文档示例验证如下,

import tensorflow as tf
config = tf.ConfigProto()
config.gpu_options.allow_growth = True
sess = tf.Session(config=config) t = tf.constant([[1, 2, 3], [4, 5, 6]])
paddings = tf.constant([[1, 1,], [2, 2]])
# 'constant_values' is 0.
# rank of 't' is 2.
res = tf.pad(t, paddings, "CONSTANT", constant_values=1) # [[0, 0, 0, 0, 0, 0, 0],
# [0, 0, 1, 2, 3, 0, 0],
# [0, 0, 4, 5, 6, 0, 0],
# [0, 0, 0, 0, 0, 0, 0]] print(sess.run(res)) '''
tf.pad(t, paddings, "REFLECT") # [[6, 5, 4, 5, 6, 5, 4],
# [3, 2, 1, 2, 3, 2, 1],
# [6, 5, 4, 5, 6, 5, 4],
# [3, 2, 1, 2, 3, 2, 1]] tf.pad(t, paddings, "SYMMETRIC") # [[2, 1, 1, 2, 3, 3, 2],
# [2, 1, 1, 2, 3, 3, 2],
# [5, 4, 4, 5, 6, 6, 5],
# [5, 4, 4, 5, 6, 6, 5]]
'''

『TensorFlow』pad图片的更多相关文章

  1. 『TensorFlow』专题汇总

    TensorFlow:官方文档 TensorFlow:项目地址 本篇列出文章对于全零新手不太合适,可以尝试TensorFlow入门系列博客,搭配其他资料进行学习. Keras使用tf.Session训 ...

  2. 『TensorFlow』TFR数据预处理探究以及框架搭建

    一.TFRecord文件书写效率对比(单线程和多线程对比) 1.准备工作 # Author : Hellcat # Time : 18-1-15 ''' import os os.environ[&q ...

  3. 『TensorFlow』SSD源码学习_其五:TFR数据读取&数据预处理

    Fork版本项目地址:SSD 一.TFR数据读取 创建slim.dataset.Dataset对象 在train_ssd_network.py获取数据操作如下,首先需要slim.dataset.Dat ...

  4. 『TensorFlow』DCGAN生成动漫人物头像_下

    『TensorFlow』以GAN为例的神经网络类范式 『cs231n』通过代码理解gan网络&tensorflow共享变量机制_上 『TensorFlow』通过代码理解gan网络_中 一.计算 ...

  5. 『TensorFlow』滑动平均

    滑动平均会为目标变量维护一个影子变量,影子变量不影响原变量的更新维护,但是在测试或者实际预测过程中(非训练时),使用影子变量代替原变量. 1.滑动平均求解对象初始化 ema = tf.train.Ex ...

  6. 『TensorFlow』流程控制

    『PyTorch』第六弹_最小二乘法对比PyTorch和TensorFlow TensorFlow 控制流程操作 TensorFlow 提供了几个操作和类,您可以使用它们来控制操作的执行并向图中添加条 ...

  7. 『TensorFlow』读书笔记_降噪自编码器

    『TensorFlow』降噪自编码器设计  之前学习过的代码,又敲了一遍,新的收获也还是有的,因为这次注释写的比较详尽,所以再次记录一下,具体的相关知识查阅之前写的文章即可(见上面链接). # Aut ...

  8. 『TensorFlow』梯度优化相关

    tf.trainable_variables可以得到整个模型中所有trainable=True的Variable,也是自由处理梯度的基础 基础梯度操作方法: tf.gradients 用来计算导数.该 ...

  9. 『TensorFlow』模型保存和载入方法汇总

    『TensorFlow』第七弹_保存&载入会话_霸王回马 一.TensorFlow常规模型加载方法 保存模型 tf.train.Saver()类,.save(sess, ckpt文件目录)方法 ...

随机推荐

  1. 深度学习基础(二)AlexNet_ImageNet Classification with Deep Convolutional Neural Networks

    该论文是深度学习领域的经典之作,因为自从Alex Krizhevsky提出AlexNet并使用GPUs大幅提升训练的效率之后,深度学习在图像识别等领域掀起了研究使用的热潮.在论文中,作者训练了一个含有 ...

  2. 转载:Linux下解压zip乱码问题的解决(unzip)

    https://blog.csdn.net/abyjun/article/details/48344379 在windows上压缩的文件,是以系统默认编码中文来压缩文件.由于zip文件中没有声明其编码 ...

  3. 面试题----入参两个Integer,无返回值,然后使这个两个值在调用函数后交换

    我最近看到过一个比较好玩的面试题. 写个方法,入参两个Integer,无返回值,然后使这个两个值在调用函数后交换 很有意思的一个题目,引发我的深思,根据一路的学习过来,下面把实现代码贴出来,方便学习. ...

  4. 2.1 Html

    一.Head中常用标签 <head>元素出现在文档的开头部分,会书写一些和浏览器中的配置信息. <head>与</head>之间的内容不会在浏览器的文档窗口显示,但 ...

  5. python中Hadamard product和matrix product的区分

    先简单说一下Hadamard product:  (参照维基百科:https://en.wikipedia.org/wiki/Hadamard_product_(matrices)) 而matrix ...

  6. poj 1164 深度优先搜索模板题

    #include<iostream> //用栈进行的解决: #include<cstdio> #include<algorithm> #include<cst ...

  7. django中的数据库迁移

    Django是用python写的web开发框架,其特点是: 1.重量级框架,内部封装了很多的功能组件,使开发变的简便快速, 2.MVT模式:前后端分离,高内聚低耦合,m:model,与mvc中的m功能 ...

  8. 去掉vim的BELL提示音

    title: date: 2017-11-09 15:07:08 tags: vim categories: 开发工具 --- 在vi/vim中使用 :set noeb 意思是noerrorbells ...

  9. fcrackzip (zip密码破解工具)

    现在做一个例子,首先生成一个带有密码的zip的包 zip -P hujhh test.zip test1.txt test2,txt 可以看到密码是5位的纯字母 现在就用我们的这个软件开始破解 fcr ...

  10. samba服务器笔记 (一)

    Samba安装 samba:主服务包:samba-client:客户端:samba-common:通用工具:samba4-libs:库:samba-winbind:windows域映射:samba-w ...