小编Moa*_*hdi的帖子

tf.space_to_depth()在tensorflow中如何工作?

我是pytorch用户。我在张量流中有一个预训练的模型,我想将其转移到pytorch中。在模型架构的一部分中,我的意思是在张量流定义的模型中,有一个函数tf.space_to_depth将输入大小(None,38,38,64)转换为(None,19,19,256)。(https://www.tensorflow.org/api_docs/python/tf/space_to_depth)是此功能的文档。但我不明白此功能的实际作用。您能提供一些numpy代码为我说明一下吗?

实际上,我想在pytorch中制作一个完全相似的图层。

张量流中的一些代码揭示了另一个秘密:这是一些代码:

import numpy as np
import tensorflow as tf

norm = tf.random_normal([1, 2, 2, 1], mean=0, stddev=1)
trans = tf.space_to_depth(norm,2)

with tf.Session() as s:
    norm = s.run(norm)
    trans = s.run(trans)



print("Norm")
print(norm.shape)
for index,value in np.ndenumerate(norm):
    print(value)

print("Trans")
print(trans.shape)
for index,value in np.ndenumerate(trans):
    print(value)
Run Code Online (Sandbox Code Playgroud)

这是输出:

Norm
(1, 2, 2, 1)
0.695261
0.455764
1.04699
-0.237587
Trans
(1, 1, 1, 4)
1.01139
0.898777
0.210135
2.36742
Run Code Online (Sandbox Code Playgroud)

如上所示,除了数据重塑之外,张量值也已更改!

deep-learning keras tensorflow pytorch

5
推荐指数
1
解决办法
5539
查看次数

标签 统计

deep-learning ×1

keras ×1

pytorch ×1

tensorflow ×1