nettrainer.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:deep-prior 作者: moberweger 项目源码 文件源码
def alignData(self, data):
        """
        Align data to a multiple of the macro batch size, pad last incomplete minibatch with random samples
        :param data: data for alignment
        :return: padded data
        """
        # pad with zeros to macro batch size, but only along dimension 0 ie samples
        topad = self.getNumSamplesPerMacroBatch() - data.shape[0] % self.getNumSamplesPerMacroBatch()
        sz = []
        sz.append((0, topad))
        for i in range(len(data.shape) - 1):
            sz.append((0, 0))
        padded = numpy.pad(data, sz, mode='constant', constant_values=0)

        # fill last incomplete minibatch with random samples
        if (data.shape[0] % self.cfgParams.batch_size) != 0:
            # start from same random seed every time the data is padded, otherwise labels and data mix up
            rng = numpy.random.RandomState(data.shape[0])
            for i in xrange(0, self.cfgParams.batch_size - (data.shape[0] % self.cfgParams.batch_size)):
                padded[data.shape[0]+i] = padded[rng.randint(0, data.shape[0])]
        return padded
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号