Use an OrderedDict for caffe.Net.blobs
authorJonathan L Long <jonlong@cs.berkeley.edu>
Tue, 11 Mar 2014 03:33:31 +0000 (20:33 -0700)
committerJonathan L Long <jonlong@cs.berkeley.edu>
Thu, 13 Mar 2014 18:15:57 +0000 (11:15 -0700)
python/caffe/pycaffe.py

index f7a266b..5d36489 100644 (file)
@@ -1,4 +1,25 @@
+"""
+Wrap the internal caffe C++ module (_caffe.so) with a clean, Pythonic
+interface.
+"""
+
 from ._caffe import CaffeNet
+from collections import OrderedDict
 
 class Net(CaffeNet):
-    pass
+    """
+    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])
+
+    @property
+    def blobs(self):
+        """
+        An OrderedDict (bottom to top, i.e., input to output) of network
+        blobs indexed by name
+        """
+        return self._blobs