Exemplo n.º 1
0
    def trace_training(self, path, flow, x, msg=None, stop_msg=None,
                       trace_name="training", debug=False, **kwargs):
        """Trace a single training phase and the stop_training.

        Return a tuple containing a list of the training slide filenames, the
        training node ids and the same for stop_training.

        path -- Path were the inspection files will be stored.
        trace_name -- Name prefix for this inspection (default is training).
        **kwargs -- Additional arguments for flow.train can be specified
            as keyword arguments.
        """
        self._reset()
        self._trace_path = path
        # train and stop filenames must be different
        self._trace_name = trace_name + "_t"
        self._flow = flow
        self._tracing_decorator.decorate_flow(flow)
        biflownode = BiFlowNode(BiFlow(flow.flow))
        try:
            biflownode.train(x=x, msg=msg, **kwargs)
            # reset is important for the following stop_training
            biflownode.bi_reset()
        # Note: this also catches legacy string exceptions (which are still
        #    used in numpy, e.g. np.core.multiarray.error)
        except:
            if debug:
                # insert the error slide and encapsulate the exception
                traceback.print_exc()
                self._write_error_frame()
                result = (self._slide_filenames, self._slide_node_ids,
                          None, None)
                raise TraceDebugException(result=result)
            else:
                raise
        train_filenames = self._slide_filenames
        train_node_ids = self._slide_node_ids
        self._reset()
        self._trace_name = trace_name + "_s"
        try:
            biflownode.stop_training(stop_msg)
        except:
            if debug:
                # insert the error slide and encapsulate the exception
                traceback.print_exc()
                self._write_error_frame()
                result = (train_filenames, train_node_ids,
                          self._slide_filenames, self._slide_node_ids)
                raise TraceDebugException(result=result)
            else:
                raise
        stop_filenames = self._slide_filenames
        stop_node_ids = self._slide_node_ids
        # restore undecorated flow
        self._tracing_decorator.decorate_flow(flow, undecorate_mode=True)
        return train_filenames, train_node_ids, stop_filenames, stop_node_ids
Exemplo n.º 2
0
    def trace_training(self, path, flow, x, msg=None, stop_msg=None,
                       trace_name="training", debug=False, **kwargs):
        """Trace a single training phase and the stop_training.

        Return a tuple containing a list of the training slide filenames, the
        training node ids and the same for stop_training.

        path -- Path were the inspection files will be stored.
        trace_name -- Name prefix for this inspection (default is training).
        **kwargs -- Additional arguments for flow.train can be specified
            as keyword arguments.
        """
        self._reset()
        self._trace_path = path
        # train and stop filenames must be different
        self._trace_name = trace_name + "_t"
        self._flow = flow
        self._tracing_decorator.decorate_flow(flow)
        biflownode = BiFlowNode(BiFlow(flow.flow))
        try:
            biflownode.train(x=x, msg=msg, **kwargs)
            # reset is important for the following stop_training
            biflownode.bi_reset()
        # Note: this also catches legacy string exceptions (which are still
        #    used in numpy, e.g. np.core.multiarray.error)
        except:
            if debug:
                # insert the error slide and encapsulate the exception
                traceback.print_exc()
                self._write_error_frame()
                result = (self._slide_filenames, self._slide_node_ids,
                          None, None)
                raise TraceDebugException(result=result)
            else:
                raise
        train_filenames = self._slide_filenames
        train_node_ids = self._slide_node_ids
        self._reset()
        self._trace_name = trace_name + "_s"
        try:
            biflownode.stop_training(stop_msg)
        except:
            if debug:
                # insert the error slide and encapsulate the exception
                traceback.print_exc()
                self._write_error_frame()
                result = (train_filenames, train_node_ids,
                          self._slide_filenames, self._slide_node_ids)
                raise TraceDebugException(result=result)
            else:
                raise
        stop_filenames = self._slide_filenames
        stop_node_ids = self._slide_node_ids
        # restore undecorated flow
        self._tracing_decorator.decorate_flow(flow, undecorate_mode=True)
        return train_filenames, train_node_ids, stop_filenames, stop_node_ids
Exemplo n.º 3
0
 def test_two_nodes1(self):
     """Test a TestBiFlowNode with two normal nodes."""
     sfa_node = mdp.nodes.SFANode(input_dim=10, output_dim=8)
     sfa2_node = mdp.nodes.SFA2Node(input_dim=8, output_dim=6)
     flownode = BiFlowNode(BiFlow([sfa_node, sfa2_node]))
     for _ in range(2):
         for _ in range(6):
             flownode.train(n.random.random((30,10)))
         flownode.stop_training()
     x = n.random.random([100,10])
     flownode.execute(x)
Exemplo n.º 4
0
 def test_two_nodes1(self):
     """Test a TestBiFlowNode with two normal nodes."""
     sfa_node = mdp.nodes.SFANode(input_dim=10, output_dim=8)
     sfa2_node = mdp.nodes.SFA2Node(input_dim=8, output_dim=6)
     flownode = BiFlowNode(BiFlow([sfa_node, sfa2_node]))
     for _ in range(2):
         for _ in range(6):
             flownode.train(n.random.random((30,10)))
         flownode.stop_training()
     x = n.random.random([100,10])
     flownode.execute(x)