コード例 #1
0
    def function(self):
        """Returns the function the ``ForwardBackward``.

        Returns
        -------
        lambda
            The function.

        See Also
        --------
        `theano.function(*args, **kwargs)`_ - How to make a graph. [**Theano Style**]

        References
        ----------
        The implementation of `ForwardBackward(net.cpp, L85)`_.

        """
        if hasattr(self, '_function'): return self._function

        for loss in self.losses:
            for var in self.trainable_variables:
                _Grad(loss, var)

        self._function = _Function(
            outputs=[self.blobs[key].data
                for key in self.outputs])

        if hasattr(self, '_model'):
            _workspace.Restore(self._model, format='caffe')

        return self._function
コード例 #2
0
ファイル: net.py プロジェクト: zhangkaij/Dragon
    def function(self):
        """ the CC Graph will create only once get this attr """
        if hasattr(self, '_function'): return self._function

        for cost in self._costs:
            for wrt in self._wrts:
                T.grad(cost, wrt)

        self._function = \
            theano.function(outputs=[self._blobs[name]['data']
                        for name in self._net_outputs], swaps=self._swap_blobs)

        if hasattr(self, '_model'): ws.Restore(self._model, format=1)
        return self._function
コード例 #3
0
    def copy_from(self, model):
        """Copy the parameters from the binary proto file. [**PyCaffe Style**]

        Parameters
        ----------
        model : str
            The path of the ``.caffemodel`` file.

        See Also
        --------
        `workspace.Restore(*args, **kwargs)`_ - How to restore tensors from a file.

        References
        ----------
        The implementation of `CopyTrainedLayersFromBinaryProto(net.cpp, L780)`_.

        """
        ws.Restore(model, format='caffe')
コード例 #4
0
    def function(self, givens=None):
        """Returns the function the ``ForwardBackward``.

        Parameters
        ----------
        givens : None or dict
            The givens to replace existing blobs.

        Returns
        -------
        lambda
            The function.

        See Also
        --------
        `theano.function(*args, **kwargs)`_ - How to make a graph. [**Theano Style**]

        References
        ----------
        The implementation of `ForwardBackward(net.cpp, L85)`_.

        """
        if hasattr(self, '_function'): return self._function

        for cost in self._costs:
            for wrt in self._wrts:
                T.grad(cost, wrt)

        if givens is not None:
            if not isinstance(givens, dict):
                raise TypeError('The givens should be a dict.')
            for k, v in givens.items():
                if not isinstance(v, Tensor):
                    raise ValueError('The value of givens should be a Tensor.')
                self._swap_tensors[k] = v

        self._function = \
            theano.function(outputs=[self._blobs[name]['data']
                        for name in self._net_outputs], givens=self._swap_tensors)

        if hasattr(self, '_model'): ws.Restore(self._model, format='caffe')
        return self._function
コード例 #5
0
 def restore(self, sess, save_path):
     ws.Restore(save_path)
コード例 #6
0
 def load(self):
     filename = 'checkpoints/%s_%08d.bin' % (self.model_name, Config.LOAD_EPISODE)
     ws.Restore(filename)
     return Config.LOAD_EPISODE
コード例 #7
0
ファイル: net.py プロジェクト: zhangkaij/Dragon
 def copy_from(self, model):
     """ simply follow the pycaffe style """
     ws.Restore(model, format=1)