chainer.exporters.caffe.export

chainer.exporters.caffe.export(model, args, directory=None, export_params=True, graph_name='Graph')[source]

(Experimental) Export a computational graph as Caffe format.

Parameters
  • model (Chain) – The model object you want to export in Caffe format. It should have __call__() method because the second argument args is directly given to the model by the () accessor.

  • args (list of ~chainer.Variable) – The arguments which are given to the model directly.

  • directory (str) – The directory used for saving the resulting Caffe model. If None, nothing is saved to the disk.

  • export_params (bool) – If True, this function exports all the parameters included in the given model at the same time. If False, the exported Caffe model doesn’t include any parameter values.

  • graph_name (str) – A string to be used for the name field of the graph in the exported Caffe model.

Note

Currently, this function supports networks that created by following layer functions.

This function can export at least following networks.

  • GoogLeNet

  • ResNet

  • VGG

And, this function use testing (evaluation) mode.

Example

>>> from chainer.exporters import caffe
>>>
>>> class Model(chainer.Chain):
...    def __init__(self):
...        super(Model, self).__init__()
...        with self.init_scope():
...            self.l1 = L.Convolution2D(None, 1, 1, 1, 0)
...            self.b2 = L.BatchNormalization(1)
...            self.l3 = L.Linear(None, 1)
...
...    def __call__(self, x):
...        h = F.relu(self.l1(x))
...        h = self.b2(h)
...        return self.l3(h)
...
>>> x = chainer.Variable(np.zeros((1, 10, 10, 10), np.float32))
>>> caffe.export(Model(), [x], None, True, 'test')