2015-09-17 13 views
1

我一直在用Lasagne訓練一些神經網絡和卷積網,並且正在使用Python處理大部分數據/圖像預處理。不過,我想將其中的一些內容納入我的千層麪,以使我的代碼更加靈活。Lasange的卷積網 - 圖像調整大小

有沒有可以調整輸入圖像大小的千層麪圖層?

回答

0

而不是在圖層中這樣做,您可以使用nolearn.lasagne.BatchIterator;下面的代碼片段我重新取樣我原來的一維信號,1000點的信號:

from nolearn.lasagne import BatchIterator 
from scipy.signal import resample 
import numpy as np 

class ResampleIterator(BatchIterator): 

    def __init__(self, batch_size, newSize): 
     super(ResampleIterator, self).__init__(batch_size) 
     self.newSize = newSize 

    def transform(self, Xb, yb): 
     X_new = resample(Xb, self.newSize, axis=2).astype(np.float32)  
     return X_new, yb 


myNet = NeuralNet(
# define your usual other parameters (layers, etc) here 

    # and these are the lines you are interested in: 
    batch_iterator_train=CropIterator(batch_size=128, newSize=1000), 
    batch_iterator_test=CropIterator(batch_size=128, newSize=1000), 
    ) 

我不知道,如果你已經使用nolearn的是,你可以閱讀更多關於它(安裝,例子)here