与Lasange的卷积网 - 图像调整大小

时间:2015-09-17 11:06:05

标签: python image-processing neural-network theano lasagne

我一直在用Lasagne训练一些神经和卷积网,并且正在使用Python进行大部分数据/图像预处理。但是,我想将其中的一部分纳入我的烤宽面条层,以使我的代码更加灵活。

是否有可以调整输入图像大小的烤宽面条层?

1 个答案:

答案 0 :(得分:0)

您可以使用nolearn.lasagne.BatchIterator;而不是在图层中执行此操作;在下面的片段中,我将原始1D信号重新采样为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