yosinski / deep-visualization-toolbox

DeepVis Toolbox
http://yosinski.com/deepvis
MIT License
4.02k stars 924 forks source link

Key error in max_tracker.py? #113

Closed matthewgiarra closed 7 years ago

matthewgiarra commented 7 years ago

I think this might be a bug, but this code obviously ran for you, so I'm trying to sort this out.

In max_tracker.py, on line 97, we have:

def _init_with_net(self, net):
        self.max_trackers = {}
        for layer,is_conv in zip(self.layers, self.is_conv):
            blob = net.blobs[layer].data
            self.max_trackers[layer] = MaxTracker(is_conv, blob.shape[1], n_top = self.n_top,
                                                  initial_val = self.initial_val,
                                                  dtype = blob.dtype)
        self.init_done = True

I'm concerned with the line:

blob = net.blobs[layer].data

net.blobs is an OrderedDict, so its keys are strings. However, layer is an object of type caffe.Layer and does not appear to be a valid key for an orderedDict. When I run the code as it's written, I get a KeyError, and the code crashes.

I feel like one fix could be to change the first block in this post to something like

def _init_with_net(self, net):
        self.max_trackers = {}
        for layer_name, is_conv in zip(net._layer_names, self.is_conv):
            blob = net.blobs[layer].data
            self.max_trackers[layer] = MaxTracker(is_conv, blob.shape[1], n_top = self.n_top,
                                                  initial_val = self.initial_val,
                                                  dtype = blob.dtype)
        self.init_done = True

i.e., change self.layers to net._layer_names

Am I missing something?

matthewgiarra commented 7 years ago

Never mind, self.layers in this context is a list of strings. My mistake.