提问人:POEY 提问时间:8/6/2019 更新时间:8/6/2019 访问量:142
在 CNN 中匹配频道形状的正确方法是什么?转置与重塑
what is the correct method to match channel shape in cnn? transpose vs reshape
问:
我试图构建我的 CNN 层。但我有一个问题。 CNN 层的输入是图像数据。我曾经在后端作为 TensorFlow。所以CNN层的输入形状必须是(数据数、高度、宽度、通道)!
我制作了数据以使用列表。 让我们举个例子。 图像是 2x2 文件。数据是 'a'、'b'、'c'。
a = np.zeros((2,2))
b = np.ones((2,2))
c = np.ones((2,2)) * 2
l = [a,b,c]
l = np.array(l)
print(l)
print(l.shape)
print is
[[[0. 0.]
[0. 0.]]
[[1. 1.]
[1. 1.]]
[[2. 2.]
[2. 2.]]]
(3, 2, 2)
我想输入“l”数据。但是我很困惑。
要匹配形状(数据数量、高度、宽度、通道), transpose() 或 reshape() 的正确方法是什么?
示例的方法输出如下。
new = np.transpose(l, (1,2,0))
print("=============================")
print(new)
print(new.shape)
print("=============================")
old = np.reshape(l, (2,2,3))
print(old)
print(old.shape)
[[[0. 1. 2.]
[0. 1. 2.]]
[[0. 1. 2.]
[0. 1. 2.]]]
(2, 2, 3)
=============================
[[[0. 0. 0.]
[0. 1. 1.]]
[[1. 1. 2.]
[2. 2. 2.]]]
(2, 2, 3)
Two Method 的形状是 (2, 2, 3),所以没有错误!但我有些怀疑。 我认为转置方法是对的。但没有证据支持使用这种方法。什么是正确的?
谢谢。
答: 暂无答案
评论
reshape
new
0,1,2