Yub*_*rel 2 image-processing tensorflow
我使用简单的tensorflow示例来翻转图像.我使用了reverse_sequence和reverse方法,结果是一样的.如果只使用reverse()方法,我们可以翻转图像,那么我们为什么要使用reverse_sequence()方法呢?我只是想知道这种方法的主要区别是什么?提前致谢 :)
import tensorflow as tf
import matplotlib.image as mpimg
import matplotlib.pyplot as plt
# First, load the image again
filename = "MarshOrchid.jpg"
image = mpimg.imread(filename)
# Create a TensorFlow Variable
x = tf.Variable(image, name='x')
height, width, depth = image.shape
model = tf.initialize_all_variables()
with tf.Session() as session:
# x= tf.reverse(x, dims=[False, True, False],name="reverse")
x = tf.reverse_sequence(x, [width] * height, 1, batch_dim=0)
session.run(model)
result = session.run(x)
print(session.run(x))
plt.imshow(result)
plt.show()
Run Code Online (Sandbox Code Playgroud)
该tf.reverse_sequence()运算被设计为在使用顺序已被数据填充,使密集的张量.考虑以下矩阵,x其中非零元素看起来是"左对齐":
x = [[1 2 3 4 0 0 0]
[1 2 3 0 0 0 0]
[1 2 3 4 5 6 7]]
seq_lens = [4, 3, 7]
Run Code Online (Sandbox Code Playgroud)
评估tf.reverse_sequence(x, seq_lens, seq_dim=1, batch_dim=0)给出:
result = [[4 3 2 1 0 0 0]
[3 2 1 0 0 0 0]
[7 6 5 4 3 2 1]]
Run Code Online (Sandbox Code Playgroud)
请注意,结果仍然显示为"左对齐".
相比之下,如果您进行评估tf.reverse(x, [False, True]),则会忽略序列长度,并获得"右对齐"结果:
result = [[0 0 0 4 3 2 1]
[0 0 0 0 3 2 1]
[7 6 5 4 3 2 1]]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1088 次 |
| 最近记录: |