-
Notifications
You must be signed in to change notification settings - Fork 18.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #199 from longjon/pycaffe-ordereddict
Update Python interface, using OrderedDict for blobs and layers to expose activations, params, and diffs.
- Loading branch information
Showing
6 changed files
with
84 additions
and
37 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
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 +1 @@ | ||
from .pycaffe import * | ||
from .pycaffe import Net |
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
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
""" | ||
Wrap the internal caffe C++ module (_caffe.so) with a clean, Pythonic | ||
interface. | ||
""" | ||
|
||
from ._caffe import CaffeNet | ||
from collections import OrderedDict | ||
|
||
class Net(CaffeNet): | ||
""" | ||
The direct Python interface to caffe, exposing Forward and Backward | ||
passes, data, gradients, and layer parameters | ||
""" | ||
def __init__(self, param_file, pretrained_param_file): | ||
super(Net, self).__init__(param_file, pretrained_param_file) | ||
self._blobs = OrderedDict([(bl.name, bl) | ||
for bl in super(Net, self).blobs]) | ||
self.params = OrderedDict([(lr.name, lr.blobs) | ||
for lr in super(Net, self).layers | ||
if len(lr.blobs) > 0]) | ||
|
||
@property | ||
def blobs(self): | ||
""" | ||
An OrderedDict (bottom to top, i.e., input to output) of network | ||
blobs indexed by name | ||
""" | ||
return self._blobs |