2016-06-28 84 views
0

我正在學習卷積如何工作的話,我遇到了我this..when試試這個使用移調有什麼區別?

rng = numpy.random.RandomState(23455) 
input = T.tensor4(name='input') 
w_shp = (2, 3, 9, 9) 
w_bound = numpy.sqrt(3 * 9 * 9) 
print w_bound 
W = theano.shared(numpy.asarray(
      rng.uniform(
       low=-1.0/w_bound, 
       high=1.0/w_bound, 
       size=w_shp), 
      dtype=input.dtype), name ='W') 
b_shp = (2,) 
b = theano.shared(numpy.asarray(
      rng.uniform(low=-.5, high=.5, size=b_shp), 
      dtype=input.dtype), name ='b') 

conv_out = conv2d(input, W,subsample=(2,2)) 
pooled=downsample.max_pool_2d(conv_out,(2,2),ignore_border=True) 
output = T.nnet.sigmoid(pooled + b.dimshuffle('x', 0, 'x', 'x')) 
f = theano.function([input], output) 
img = Image.open('2.jpg') 
img = numpy.asarray(img, dtype='float64')/256. 
l,w,r=img.shape 
img_ = img.transpose(2, 0, 1).reshape(1, 3, l, w) 
print img_.shape 
filtered_img = f(img_) 
pylab.subplot(1, 3, 1); pylab.axis('off'); pylab.imshow(img) 
pylab.gray(); 
pylab.subplot(1, 3, 2); pylab.axis('off'); pylab.imshow(filtered_img[0, 1, :, :]) 
pylab.subplot(1, 3, 3); pylab.axis('off'); pylab.imshow(filtered_img[0, 0, :, :]) 

After convolution

當我不移調輸入圖像即...

img_ = img.reshape(1, 3, l, w) 

Without Tanspose

有人可以解釋有什麼區別?

回答

0

原始圖像是一個3d數組,具有尺寸(像素行,像素列,通道)。通道是顏色通道(例如RGB)。 img.transpose(2, 0, 1)重新排列陣列的尺寸(通道,像素行,像素列)。其餘的代碼需要這個初始順序。它確保卷積發生在每個通道的像素空間上。如果省略轉置,則像素座標和通道將相互混淆。

+0

是的,明白了!謝謝 – Sush