Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## extract weights and biases from caffemodel to numpy arrays
- ## require pycaffe interface
- import caffe
- import numpy as np
- def caffemodel2npy(defFile, modelFile):
- net = caffe.Net(defFile, modelFile, caffe.TEST)
- newModel = {}
- for p in net.params:
- newModel[p] = {}
- if len(net.params[p]) != 2:
- print 'error in params', p
- continue
- for idx, name in enumerate(['weight', 'bias']):
- newModel[p][name] = net.params[p][idx].data
- print 'extract', p, name, net.params[p][idx].data.shape
- return newModel
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement