Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. from chainer.functions.caffe import CaffeFunction
  2. import pickle, logging
  3. from os.path import isfile
  4.  
  5. class CaffeNetWrapper(object):
  6. def __init__(self, caffe_model, chainer_model, force_caffe_load = False):
  7. super(CaffeNetWrapper, self).__init__()
  8.  
  9. if not force_caffe_load and isfile(chainer_model):
  10. logging.info("loading chainer model from \"{}\"".format(chainer_model))
  11. self.net = pickle.load(open(chainer_model, "rb"))
  12. else:
  13. logging.info("loading caffe model from \"{}\"".format(caffe_model))
  14. self.net = CaffeFunction(caffe_model)
  15. try:
  16. logging.info("saving loaded model to \"{}\"".format(chainer_model))
  17. with open(chainer_model, "wb") as f:
  18. pickle.dump(self.net, f)
  19. except Exception as e:
  20. logging.warn("could not save loadded model to \"{}\" Error: {}".format(chainer_model, e))
  21.  
  22.  
  23. def __call__(self, *args, **kw):
  24. return self.net(*args, **kw)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement