Advertisement
Guest User

Untitled

a guest
Nov 3rd, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. ## extract weights and biases from caffemodel to numpy arrays
  2. ## require pycaffe interface
  3.  
  4. import caffe
  5. import numpy as np
  6.  
  7. def caffemodel2npy(defFile, modelFile):
  8. net = caffe.Net(defFile, modelFile, caffe.TEST)
  9. newModel = {}
  10. for p in net.params:
  11. newModel[p] = {}
  12. if len(net.params[p]) != 2:
  13. print 'error in params', p
  14. continue
  15. for idx, name in enumerate(['weight', 'bias']):
  16. newModel[p][name] = net.params[p][idx].data
  17. print 'extract', p, name, net.params[p][idx].data.shape
  18. return newModel
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement