Python keras.utils 模块,Sequence() 实例源码

我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用keras.utils.Sequence()

项目:keras-text    作者:raghakot    | 项目源码 | 文件源码
def __init__(self, X, y, batch_size, process_fn=None):
        """A `Sequence` implementation that returns balanced `y` by undersampling majority class.

        Args:
            X: The numpy array of inputs.
            y: The numpy array of targets.
            batch_size: The generator mini-batch size.
            process_fn: The preprocessing function to apply on `X`
        """
        self.X = X
        self.y = y
        self.batch_size = batch_size
        self.process_fn = process_fn or (lambda x: x)

        self.pos_indices = np.where(y == 1)[0]
        self.neg_indices = np.where(y == 0)[0]
        self.n = min(len(self.pos_indices), len(self.neg_indices))
        self._index_array = None
项目:keras-transform    作者:Dref360    | 项目源码 | 文件源码
def __getitem__(self, index):
        assert self.sequence, "This transformer {} has not been called with a Sequence object".format(
            self.__class__.__name__)
        batch = self.sequence[index]
        if self.batch_size is None:
            # The first batch should be the maximum batch_size i.e. not the last.
            self.batch_size = get_batch_size(batch)

        args = self.get_args()
        for arg in args:
            arg.update(self.common_args)

        return apply_fun(batch, self.apply_transformation, self.mask, transformation=self.transformation, args=args)
项目:keras-text    作者:raghakot    | 项目源码 | 文件源码
def __init__(self, X, y, batch_size, process_fn=None):
        """A `Sequence` implementation that can pre-process a mini-batch via `process_fn`

        Args:
            X: The numpy array of inputs.
            y: The numpy array of targets.
            batch_size: The generator mini-batch size.
            process_fn: The preprocessing function to apply on `X`
        """
        self.X = X
        self.y = y
        self.batch_size = batch_size
        self.process_fn = process_fn or (lambda x: x)