python how to know the object attributes(methods) and how to know the hierarchy of the dict
<p>I am working with the caffe Python wrapper. I have two questions about using Python to access the data details.</p>

<p>I first loaded the caffe net definition by:</p>

<pre><code>net = caffe.Net('deploy_full.prototxt',caffe.TEST)
</code></pre>

<p>I know the net will be a object in Python, and I want to know the attributes within it, so I use the bulit-in dir() methods:</p>

<pre><code>&gt;&gt;&gt; dir(net)
['__class__', '__delattr__', '__dict__', '__doc__',         '__format__','__getattribute__', '__hash__', '__init__', '__module__','__new__',    '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_backward', '_batch', '_blob_loss_weights', '_blob_names', '_blobs', '_forward', '_inputs', '_layer_names', '_outputs', '_set_input_arrays', 'backward', 'blob_loss_weights', 'blobs', 'copy_from', 'forward', 'forward_all', 'forward_backward_all', 'inputs', 'layers', 'outputs', 'params', 'reshape',     'save', 'set_input_arrays', 'share_with']
</code></pre>

<p>Then I used the params attribute to find the keys attribute of net.params:</p>

<pre><code>&gt;&gt;&gt; net.params.keys()
['conv1a', 'bn1a', 'conv1b', 'bn1b', 'conv2a', 'bn2a', 'conv2b', 'bn2b',  'conv3a', 'bn3a', 'conv3b', 'bn3b', 'fc8-conv']
</code></pre>

<p>So the problem is here, I want to know the detail about net.params['bn1a']:</p>

<pre><code>&gt;&gt;&gt; net.params['bn1a']
&lt;caffe._caffe.BlobVec object at 0x7f274b71fbb0&gt;
&gt;&gt;&gt; dir(net.params['bn1a'])
['__class__', '__contains__', '__delattr__', '__delitem__', '__dict__', '__doc__', '__format__', '__getattribute__', '__getitem__', '__hash__', '__init__', '__instance_size__', '__iter__', '__len__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'add_blob', 'append', 'extend']
</code></pre>

<p>These outputs are not what I want, after googling somehow, I found want I want to see is achieved by these commands:</p>

<pre><code>&gt;&gt;&gt; net.params['bn1a'][0].data.shape
(1, 16, 1, 1)
&gt;&gt;&gt; net.params['bn1a'][1].data.shape
(1, 16, 1, 1)
</code></pre>

<p>My problem is how could I know there should be [0], [1], and [x], in this dict? Since the net.params.keys() only told me there is key 'bn1a', but didn't tell me [num].</p>

<p>Moreover, if I didn't know there is [num] after ['bn1a'], I have no way to know the attributes of net.params['bn1a'][x], so I can't know the data and shape of these.</p>

<p>I would like to know what is the right way to peel the data/objects without knowledge beforehand.</p>

<p>Usually in that case I would just go and check <code>BlobVec</code> class source code and find out <code>__iter__</code> method implementation and all other. But in your case it will not so helpful since <code>caffe._caffe.BlobVec</code> is actually points to <a href="https://github.com/BVLC/caffe/blob/master/python/caffe/_caffe.cpp#L241" rel="nofollow">C++ implementation</a> when you can find that it's vector and fugure out about iterating over it etc if you know a thing about C++ and how it binds to Python and other awesome stuff :)</p>

<p>So in your case it's really better to check documentation. There under <a href="http://caffe.berkeleyvision.org/tutorial/interfaces.html" rel="nofollow">Python section</a> you'll find that</p>

<blockquote>
  <p>Caffe blobs are exposed as numpy ndarrays for ease-of-use and efficiency.</p>
</blockquote>

<p>Then you should just find docs about numpy arrays and you done.</p>

python object