(self,
            *in_arrays: Tuple[Union[np.ndarray, None], ...],
            input_transform: dict = None,
            output_transform: dict = None,
            return_as_list: bool = False,
            print_progress: bool = False,
            minibatch_size: int = None,
            num_gpus: int = 1,
            assume_frozen: bool = False,
            **dynamic_kwargs)
return out_arrays
Run this network for the given NumPy array(s), and return the output(s) as NumPy array(s).

        Args:
            input_transform:    A dict specifying a custom transformation to be applied to the input tensor(s) before evaluating the network.
                                The dict must contain a 'func' field that points to a top-level function. The function is called with the input
                                TensorFlow expression(s) as positional arguments. Any remaining fields of the dict will be passed in as kwargs.
            output_transform:   A dict specifying a custom transformation to be applied to the output tensor(s) after evaluating the network.
                                The dict must contain a 'func' field that points to a top-level function. The function is called with the output
                                TensorFlow expression(s) as positional arguments. Any remaining fields of the dict will be passed in as kwargs.
            return_as_list:     True = return a list of NumPy arrays, False = return a single NumPy array, or a tuple if there are multiple outputs.
            print_progress:     Print progress to the console? Useful for very large input arrays.
            minibatch_size:     Maximum minibatch size to use, None = disable batching.
            num_gpus:           Number of GPUs to use.
            assume_frozen:      Improve multi-GPU performance by assuming that the trainable parameters will remain changed between calls.
            dynamic_kwargs:     Additional keyword arguments to be passed into the network build function.
Run this network for the given NumPy array(s), and return the output(s) as NumPy array(s).
Run this network for the given NumPy array ( s ) and return the output ( s ) as NumPy array ( s ) .
def run(self,
            *in_arrays: Tuple[Union[np.ndarray, None], ...],
            input_transform: dict = None,
            output_transform: dict = None,
            return_as_list: bool = False,
            print_progress: bool = False,
            minibatch_size: int = None,
            num_gpus: int = 1,
            assume_frozen: bool = False,
            **dynamic_kwargs) -> Union[np.ndarray, Tuple[np.ndarray, ...], List[np.ndarray]]:
        """Run this network for the given NumPy array(s), and return the output(s) as NumPy array(s).

        Args:
            input_transform:    A dict specifying a custom transformation to be applied to the input tensor(s) before evaluating the network.
                                The dict must contain a 'func' field that points to a top-level function. The function is called with the input
                                TensorFlow expression(s) as positional arguments. Any remaining fields of the dict will be passed in as kwargs.
            output_transform:   A dict specifying a custom transformation to be applied to the output tensor(s) after evaluating the network.
                                The dict must contain a 'func' field that points to a top-level function. The function is called with the output
                                TensorFlow expression(s) as positional arguments. Any remaining fields of the dict will be passed in as kwargs.
            return_as_list:     True = return a list of NumPy arrays, False = return a single NumPy array, or a tuple if there are multiple outputs.
            print_progress:     Print progress to the console? Useful for very large input arrays.
            minibatch_size:     Maximum minibatch size to use, None = disable batching.
            num_gpus:           Number of GPUs to use.
            assume_frozen:      Improve multi-GPU performance by assuming that the trainable parameters will remain changed between calls.
            dynamic_kwargs:     Additional keyword arguments to be passed into the network build function.
        """
        assert len(in_arrays) == self.num_inputs
        assert not all(arr is None for arr in in_arrays)
        assert input_transform is None or util.is_top_level_function(input_transform["func"])
        assert output_transform is None or util.is_top_level_function(output_transform["func"])
        output_transform, dynamic_kwargs = _handle_legacy_output_transforms(output_transform, dynamic_kwargs)
        num_items = in_arrays[0].shape[0]
        if minibatch_size is None:
            minibatch_size = num_items

        # Construct unique hash key from all arguments that affect the TensorFlow graph.
        key = dict(input_transform=input_transform, output_transform=output_transform, num_gpus=num_gpus, assume_frozen=assume_frozen, dynamic_kwargs=dynamic_kwargs)
        def unwind_key(obj):
            if isinstance(obj, dict):
                return [(key, unwind_key(value)) for key, value in sorted(obj.items())]
            if callable(obj):
                return util.get_top_level_function_name(obj)
            return obj
        key = repr(unwind_key(key))

        # Build graph.
        if key not in self._run_cache:
            with tfutil.absolute_name_scope(self.scope + "/_Run"), tf.control_dependencies(None):
                with tf.device("/cpu:0"):
                    in_expr = [tf.placeholder(tf.float32, name=name) for name in self.input_names]
                    in_split = list(zip(*[tf.split(x, num_gpus) for x in in_expr]))

                out_split = []
                for gpu in range(num_gpus):
                    with tf.device("/gpu:%d" % gpu):
                        net_gpu = self.clone() if assume_frozen else self
                        in_gpu = in_split[gpu]

                        if input_transform is not None:
                            in_kwargs = dict(input_transform)
                            in_gpu = in_kwargs.pop("func")(*in_gpu, **in_kwargs)
                            in_gpu = [in_gpu] if tfutil.is_tf_expression(in_gpu) else list(in_gpu)

                        # assert len(in_gpu) == self.num_inputs
                        out_gpu = net_gpu.get_output_for(*in_gpu, return_as_list=True, **dynamic_kwargs)

                        if output_transform is not None:
                            out_kwargs = dict(output_transform)
                            out_gpu = out_kwargs.pop("func")(*out_gpu, **out_kwargs)
                            out_gpu = [out_gpu] if tfutil.is_tf_expression(out_gpu) else list(out_gpu)

                        # assert len(out_gpu) == self.num_outputs
                        out_split.append(out_gpu)

                with tf.device("/cpu:0"):
                    out_expr = [tf.concat(outputs, axis=0) for outputs in zip(*out_split)]
                    self._run_cache[key] = in_expr, out_expr

        # Run minibatches.
        in_expr, out_expr = self._run_cache[key]
        out_arrays = [np.empty([num_items] + expr.shape.as_list()[1:], expr.dtype.name) for expr in out_expr]

        for mb_begin in range(0, num_items, minibatch_size):
            if print_progress:
                print("\r%d / %d" % (mb_begin, num_items), end="")

            mb_end = min(mb_begin + minibatch_size, num_items)
            mb_num = mb_end - mb_begin
            mb_in = [src[mb_begin : mb_end] if src is not None else np.zeros([mb_num] + shape[1:]) for src, shape in zip(in_arrays, self.input_shapes)]
            mb_out = tf.get_default_session().run(out_expr, dict(zip(in_expr, mb_in)))

            for dst, src in zip(out_arrays, mb_out):
                dst[mb_begin: mb_end] = src

        # Done.
        if print_progress:
            print("\r%d / %d" % (num_items, num_items))

        if not return_as_list:
            out_arrays = out_arrays[0] if len(out_arrays) == 1 else tuple(out_arrays)
        return out_arrays
def run ( self , * in_arrays : Tuple [ Union [ np . ndarray , None ] , ... ] , input_transform : dict = None , output_transform : dict = None , return_as_list : bool = False , print_progress : bool = False , minibatch_size : int = None , num_gpus : int = 1 , assume_frozen : bool = False , * * dynamic_kwargs ) -> Union [ np . ndarray , Tuple [ np . ndarray , ... ] , List [ np . ndarray ] ] : assert len ( in_arrays ) == self . num_inputs assert not all ( arr is None for arr in in_arrays ) assert input_transform is None or util . is_top_level_function ( input_transform [ "func" ] ) assert output_transform is None or util . is_top_level_function ( output_transform [ "func" ] ) output_transform , dynamic_kwargs = _handle_legacy_output_transforms ( output_transform , dynamic_kwargs ) num_items = in_arrays [ 0 ] . shape [ 0 ] if minibatch_size is None : minibatch_size = num_items # Construct unique hash key from all arguments that affect the TensorFlow graph. key = dict ( input_transform = input_transform , output_transform = output_transform , num_gpus = num_gpus , assume_frozen = assume_frozen , dynamic_kwargs = dynamic_kwargs ) def unwind_key ( obj ) : if isinstance ( obj , dict ) : return [ ( key , unwind_key ( value ) ) for key , value in sorted ( obj . items ( ) ) ] if callable ( obj ) : return util . get_top_level_function_name ( obj ) return obj key = repr ( unwind_key ( key ) ) # Build graph. if key not in self . _run_cache : with tfutil . absolute_name_scope ( self . scope + "/_Run" ) , tf . control_dependencies ( None ) : with tf . device ( "/cpu:0" ) : in_expr = [ tf . placeholder ( tf . float32 , name = name ) for name in self . input_names ] in_split = list ( zip ( * [ tf . split ( x , num_gpus ) for x in in_expr ] ) ) out_split = [ ] for gpu in range ( num_gpus ) : with tf . device ( "/gpu:%d" % gpu ) : net_gpu = self . clone ( ) if assume_frozen else self in_gpu = in_split [ gpu ] if input_transform is not None : in_kwargs = dict ( input_transform ) in_gpu = in_kwargs . pop ( "func" ) ( * in_gpu , * * in_kwargs ) in_gpu = [ in_gpu ] if tfutil . is_tf_expression ( in_gpu ) else list ( in_gpu ) # assert len(in_gpu) == self.num_inputs out_gpu = net_gpu . get_output_for ( * in_gpu , return_as_list = True , * * dynamic_kwargs ) if output_transform is not None : out_kwargs = dict ( output_transform ) out_gpu = out_kwargs . pop ( "func" ) ( * out_gpu , * * out_kwargs ) out_gpu = [ out_gpu ] if tfutil . is_tf_expression ( out_gpu ) else list ( out_gpu ) # assert len(out_gpu) == self.num_outputs out_split . append ( out_gpu ) with tf . device ( "/cpu:0" ) : out_expr = [ tf . concat ( outputs , axis = 0 ) for outputs in zip ( * out_split ) ] self . _run_cache [ key ] = in_expr , out_expr # Run minibatches. in_expr , out_expr = self . _run_cache [ key ] out_arrays = [ np . empty ( [ num_items ] + expr . shape . as_list ( ) [ 1 : ] , expr . dtype . name ) for expr in out_expr ] for mb_begin in range ( 0 , num_items , minibatch_size ) : if print_progress : print ( "\r%d / %d" % ( mb_begin , num_items ) , end = "" ) mb_end = min ( mb_begin + minibatch_size , num_items ) mb_num = mb_end - mb_begin mb_in = [ src [ mb_begin : mb_end ] if src is not None else np . zeros ( [ mb_num ] + shape [ 1 : ] ) for src , shape in zip ( in_arrays , self . input_shapes ) ] mb_out = tf . get_default_session ( ) . run ( out_expr , dict ( zip ( in_expr , mb_in ) ) ) for dst , src in zip ( out_arrays , mb_out ) : dst [ mb_begin : mb_end ] = src # Done. if print_progress : print ( "\r%d / %d" % ( num_items , num_items ) ) if not return_as_list : out_arrays = out_arrays [ 0 ] if len ( out_arrays ) == 1 else tuple ( out_arrays ) return out_arrays