tf.pad使用

匿名 (未验证) 提交于 2019-12-03 00:18:01
  • 函数定义
tf.pad(     tensor,     paddings,     mode='CONSTANT',     name=None,     constant_values=0 )
  • 参数说明
tensor      被填充的张量 paddings    填充的格式 mode        填充模式:"CONSTANT""REFLECT""SYMMETRIC" name        该操作张量的名称 constant_values 用于在"CONSTANT"模式下,设置的填充值
  • 使用例子
    (二维、三维、其他维度类推)
import tensorflow as tf  t1 = tf.constant([[1, 2, 3], [4, 5, 6]])     # # [1,1]代表在第一维度pad,即在t1的第一维上填充 # [2,2]代表在第二维度pad,即在t1的第二维上填充 paddings1 = tf.constant([[1, 1], [2, 2]])     t2 = tf.constant([[[1,2,3], [4,5,6], [7,8,9]]])     # # [0,0]代表在第一维度pad,即在t2的第一维上填充 # [2,2]代表在第二维度pad,即在t2的第二维上填充 # [1,1]代表在第二维度pad,即在t2的第三维上填充 paddings2 = tf.constant([[0, 0], [2, 2], [1, 1]])   with tf.Session() as sess:      # 例子1 二维     op = tf.pad(t1, paddings1, "CONSTANT")     print(t1.get_shape())     print(paddings1.get_shape())     print(sess.run(op))      # 例子2 三维     print(t2.get_shape())     print(paddings2.get_shape())     op = tf.pad(t2, paddings2, "CONSTANT")     print(sess.run(op))
文章来源: tf.pad使用
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!