重塑茶叶
Theano Reshaping
我无法清楚地理解theano
的reshape
。我有一个形状的图像矩阵:
[batch_size, stack1_size, stack2_size, height, width]
,其中有 stack2_size
叠图像,每叠图像有 stack1_size
个通道。我现在想将它们转换成以下形状:
[batch_size, stack1_size*stack2_size, 1 , height, width]
这样所有的堆栈将被组合在一起成为所有通道的堆栈。我不确定重塑是否会为我做这件事。我看到如果像素在中间的尺寸中混合,则 reshape 似乎不会按字典顺序排列像素。我一直试图通过 dimshuffle
、reshape
和 concatenate
的组合来实现这一点,但无济于事。我将不胜感激。
谢谢。
Theano reshape works just like numpy reshape 及其默认值 order
,即 'C'
:
‘C’ means to read / write the elements using C-like index order, with
the last axis index changing fastest, back to the first axis index
changing slowest.
这是一个示例,显示图像像素在通过 numpy 或 Theano 重塑后保持相同的顺序。
import numpy
import theano
import theano.tensor
def main():
batch_size = 2
stack1_size = 3
stack2_size = 4
height = 5
width = 6
data = numpy.arange(batch_size * stack1_size * stack2_size * height * width).reshape(
(batch_size, stack1_size, stack2_size, height, width))
reshaped_data = data.reshape([batch_size, stack1_size * stack2_size, 1, height, width])
print data[0, 0, 0]
print reshaped_data[0, 0, 0]
x = theano.tensor.TensorType('int64', (False,) * 5)()
reshaped_x = x.reshape((x.shape[0], x.shape[1] * x.shape[2], 1, x.shape[3], x.shape[4]))
f = theano.function(inputs=[x], outputs=reshaped_x)
print f(data)[0, 0, 0]
main()
我无法清楚地理解theano
的reshape
。我有一个形状的图像矩阵:
[batch_size, stack1_size, stack2_size, height, width]
,其中有 stack2_size
叠图像,每叠图像有 stack1_size
个通道。我现在想将它们转换成以下形状:
[batch_size, stack1_size*stack2_size, 1 , height, width]
这样所有的堆栈将被组合在一起成为所有通道的堆栈。我不确定重塑是否会为我做这件事。我看到如果像素在中间的尺寸中混合,则 reshape 似乎不会按字典顺序排列像素。我一直试图通过 dimshuffle
、reshape
和 concatenate
的组合来实现这一点,但无济于事。我将不胜感激。
谢谢。
Theano reshape works just like numpy reshape 及其默认值 order
,即 'C'
:
‘C’ means to read / write the elements using C-like index order, with the last axis index changing fastest, back to the first axis index changing slowest.
这是一个示例,显示图像像素在通过 numpy 或 Theano 重塑后保持相同的顺序。
import numpy
import theano
import theano.tensor
def main():
batch_size = 2
stack1_size = 3
stack2_size = 4
height = 5
width = 6
data = numpy.arange(batch_size * stack1_size * stack2_size * height * width).reshape(
(batch_size, stack1_size, stack2_size, height, width))
reshaped_data = data.reshape([batch_size, stack1_size * stack2_size, 1, height, width])
print data[0, 0, 0]
print reshaped_data[0, 0, 0]
x = theano.tensor.TensorType('int64', (False,) * 5)()
reshaped_x = x.reshape((x.shape[0], x.shape[1] * x.shape[2], 1, x.shape[3], x.shape[4]))
f = theano.function(inputs=[x], outputs=reshaped_x)
print f(data)[0, 0, 0]
main()