This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modify the caffe_converter to use the new api. (#4655)
Compatible with python2 / 3 Specification naming
- Loading branch information
1 parent
3aaf94f
commit 3cfd2ba
Showing
4 changed files
with
93 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,38 @@ | ||
from google.protobuf import text_format | ||
import numpy as np | ||
import caffe_pb2 | ||
import caffe_parse.caffe_pb2 as caffe_pb2 | ||
|
||
def parse_caffemodel(filepath): | ||
''' | ||
|
||
def parse_caffemodel(file_path): | ||
""" | ||
parses the trained .caffemodel file | ||
filepath: /path/to/trained-model.caffemodel | ||
returns: layers | ||
''' | ||
f = open(filepath, 'rb') | ||
""" | ||
f = open(file_path, 'rb') | ||
contents = f.read() | ||
|
||
netparam = caffe_pb2.NetParameter() | ||
netparam.ParseFromString(contents) | ||
net_param = caffe_pb2.NetParameter() | ||
net_param.ParseFromString(contents) | ||
|
||
layers = find_layers(netparam) | ||
layers = find_layers(net_param) | ||
return layers | ||
|
||
def find_layers(netparam): | ||
if len(netparam.layers) > 0: | ||
return netparam.layers | ||
elif len(netparam.layer) > 0: | ||
return netparam.layer | ||
|
||
def find_layers(net_param): | ||
if len(net_param.layers) > 0: | ||
return net_param.layers | ||
elif len(net_param.layer) > 0: | ||
return net_param.layer | ||
else: | ||
raise Exception ("Couldn't find layers") | ||
raise Exception("Couldn't find layers") | ||
|
||
|
||
def main(): | ||
param_dict = parse_caffemodel('xxx.caffemodel') | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters