saliency/calculator/base_calculator.py
def _forward(self, data, fn=None, batchsize=16,
                 converter=concat_examples, retain_inputs=False,
                 preprocess_fn=None, postprocess_fn=None):
        """Forward data by iterating with batch

        Args:
            data: "train_x array" or "chainer dataset"
            fn (Callable): Main function to forward. Its input argument is
                either Variable, cupy.ndarray or numpy.ndarray, and returns
                Variable.
            batchsize (int): batch size
            converter (Callable): convert from `data` to `inputs`
            retain_inputs (bool): If True, this instance keeps inputs in
                `self.inputs` or not.
            preprocess_fn (Callable): Its input is numpy.ndarray or
                cupy.ndarray, it can return either Variable, cupy.ndarray or
                numpy.ndarray
            postprocess_fn (Callable): Its input argument is Variable,
                but this method may return either Variable, cupy.ndarray or
                numpy.ndarray.

        Returns (tuple or numpy.ndarray): forward result

        """
        input_list = None
        output_list = None
        it = SerialIterator(data, batch_size=batchsize, repeat=False,
                            shuffle=False)
        for batch in it:
            inputs = converter(batch, self._device)
            inputs = _to_tuple(inputs)

            if preprocess_fn:
                inputs = preprocess_fn(*inputs)
                inputs = _to_tuple(inputs)

            inputs = (_to_variable(x) for x in inputs)

            outputs = fn(*inputs)

            # Init
            if retain_inputs:
                if input_list is None:
                    input_list = [[] for _ in range(len(inputs))]
                for j, input in enumerate(inputs):
                    input_list[j].append(cuda.to_cpu(input))
            if output_list is None:
                output_list = [[] for _ in range(len(outputs))]

            if postprocess_fn:
                outputs = postprocess_fn(*outputs)
                outputs = _to_tuple(outputs)
            for j, output in enumerate(outputs):
                output_list[j].append(_extract_numpy(output))

        if retain_inputs:
            self.inputs = [numpy.concatenate(
                in_array) for in_array in input_list]

        result = [_concat(output) for output in output_list]

        # result = [numpy.concatenate(output) for output in output_list]
        if len(result) == 1:
            return result[0]
        else:
            return result
Forward data by iterating with batch

        Args:
            data: "train_x array" or "chainer dataset"
            fn (Callable): Main function to forward. Its input argument is
                either Variable, cupy.ndarray or numpy.ndarray, and returns
                Variable.
            batchsize (int): batch size
            converter (Callable): convert from `data` to `inputs`
            retain_inputs (bool): If True, this instance keeps inputs in
                `self.inputs` or not.
            preprocess_fn (Callable): Its input is numpy.ndarray or
                cupy.ndarray, it can return either Variable, cupy.ndarray or
                numpy.ndarray
            postprocess_fn (Callable): Its input argument is Variable,
                but this method may return either Variable, cupy.ndarray or
                numpy.ndarray.

        Returns (tuple or numpy.ndarray): forward result

        
Forward data by iterating with batch
Forward data by iterating with batch
def _forward(self, data, fn=None, batchsize=16,
                 converter=concat_examples, retain_inputs=False,
                 preprocess_fn=None, postprocess_fn=None):
        input_list = None
        output_list = None
        it = SerialIterator(data, batch_size=batchsize, repeat=False,
                            shuffle=False)
        for batch in it:
            inputs = converter(batch, self._device)
            inputs = _to_tuple(inputs)
            if preprocess_fn:
                inputs = preprocess_fn(*inputs)
                inputs = _to_tuple(inputs)
            inputs = (_to_variable(x) for x in inputs)
            outputs = fn(*inputs)
            if retain_inputs:
                if input_list is None:
                    input_list = [[] for _ in range(len(inputs))]
                for j, input in enumerate(inputs):
                    input_list[j].append(cuda.to_cpu(input))
            if output_list is None:
                output_list = [[] for _ in range(len(outputs))]
            if postprocess_fn:
                outputs = postprocess_fn(*outputs)
                outputs = _to_tuple(outputs)
            for j, output in enumerate(outputs):
                output_list[j].append(_extract_numpy(output))
        if retain_inputs:
            self.inputs = [numpy.concatenate(
                in_array) for in_array in input_list]
        result = [_concat(output) for output in output_list]
        if len(result) == 1:
            return result[0]
        else:
            return result
def _forward ( self , data , fn = None , batchsize = 16 , converter = concat_examples , retain_inputs = False , preprocess_fn = None , postprocess_fn = None ) : input_list = None output_list = None it = SerialIterator ( data , batch_size = batchsize , repeat = False , shuffle = False ) for batch in it : inputs = converter ( batch , self . _device ) inputs = _to_tuple ( inputs ) if preprocess_fn : inputs = preprocess_fn ( * inputs ) inputs = _to_tuple ( inputs ) inputs = ( _to_variable ( x ) for x in inputs ) outputs = fn ( * inputs ) if retain_inputs : if input_list is None : input_list = [ [ ] for _ in range ( len ( inputs ) ) ] for j , input in enumerate ( inputs ) : input_list [ j ] . append ( cuda . to_cpu ( input ) ) if output_list is None : output_list = [ [ ] for _ in range ( len ( outputs ) ) ] if postprocess_fn : outputs = postprocess_fn ( * outputs ) outputs = _to_tuple ( outputs ) for j , output in enumerate ( outputs ) : output_list [ j ] . append ( _extract_numpy ( output ) ) if retain_inputs : self . inputs = [ numpy . concatenate ( in_array ) for in_array in input_list ] result = [ _concat ( output ) for output in output_list ] if len ( result ) == 1 : return result [ 0 ] else : return result
Forward data by iterating with batch
Forward data by iterating with batch
"""Forward data by iterating with batch

        Args:
            data: "train_x array" or "chainer dataset"
            fn (Callable): Main function to forward. Its input argument is
                either Variable, cupy.ndarray or numpy.ndarray, and returns
                Variable.
            batchsize (int): batch size
            converter (Callable): convert from `data` to `inputs`
            retain_inputs (bool): If True, this instance keeps inputs in
                `self.inputs` or not.
            preprocess_fn (Callable): Its input is numpy.ndarray or
                cupy.ndarray, it can return either Variable, cupy.ndarray or
                numpy.ndarray
            postprocess_fn (Callable): Its input argument is Variable,
                but this method may return either Variable, cupy.ndarray or
                numpy.ndarray.

        Returns (tuple or numpy.ndarray): forward result

        """ # Init # result = [numpy.concatenate(output) for output in output_list]
self
data
"train_x array" or "chainer dataset"
" train_x array " or " chainer dataset "
fn
Main function to forward. Its input argument is
either Variable, cupy.ndarray or numpy.ndarray, and returns
Variable.
Main function to forward . Its input argument is either Variable cupy . ndarray or numpy . ndarray and returns Variable .
batchsize
None
converter
convert from `data` to `inputs`
convert from ` data ` to ` inputs `
retain_inputs
If True, this instance keeps inputs in
`self.inputs` or not.
If True this instance keeps inputs in ` self . inputs ` or not .
preprocess_fn
Its input is numpy.ndarray or
cupy.ndarray, it can return either Variable, cupy.ndarray or
numpy.ndarray
Its input is numpy . ndarray or cupy . ndarray it can return either Variable cupy . ndarray or numpy . ndarray
postprocess_fn
Its input argument is Variable,
but this method may return either Variable, cupy.ndarray or
numpy.ndarray.
Its input argument is Variable but this method may return either Variable cupy . ndarray or numpy . ndarray .