2

I have a model that generated by "chainer",but I need to convert it to "caffe" model.I have searched around the Internet,but don't have any idea.Anyone could give some advice?Thanks a lot.

huoyan
  • 141
  • 1
  • 5
  • This is a very old issue but adding a comment for the sake of a reference for those who are looking for similar options. One way to go about these transformations is to convert your model to an intermediate representation and then convert it to the format you want it in. ONNX seems to be quite a popular choice in general. So it is -> ONNX -> . Some links for reference - https://github.com/chainer/onnx-chainer, https://github.com/onnx/tutorials. – Astha Sharma Oct 18 '18 at 07:01

1 Answers1

0

Chainer now uses an export function for exporting chainer computational graph to caffe format

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')

You can go to this Chainer Documentation Link!

TulakHord
  • 422
  • 7
  • 15