Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

why can't display deconv result,please help me solve it #126

Open
Eric-Zhang1990 opened this issue Aug 23, 2017 · 5 comments
Open

why can't display deconv result,please help me solve it #126

Eric-Zhang1990 opened this issue Aug 23, 2017 · 5 comments

Comments

@Eric-Zhang1990
Copy link

I can run deep-visualization-toolbox,but it can't display the deconv result on the bottom-left of the window, could you tell me why?
no_deconv_result

@larrycheungbai
Copy link

I have the same problem.
Below is my solution.

(1) copy codes below from "Deep Visualization Toolbox" branch pycaffe.py to current pycaffe.py.
#####################

JBY: Begin added code

#####################

def _Net_ForwardFrom(self, input_layer, output_layer, input_data, shape_ref=None):
"""
Set the layer with name input_layer to input_data, do a
forward pass to the layer with name output_layer, and return
the output of that layer. input_data must be the correct
shape.
"""

input_idx = self.complete_layers.index(input_layer)
output_idx = self.complete_layers.index(output_layer)

#input_blob = np.zeros(self.blobs[input_layer].data.shape, dtype=np.float32)
if shape_ref == None:
    shape_ref = output_layer
try:
    out_blob = self.blobs[shape_ref]
except KeyError:
    raise Exception('Cannot figure out the output shape from layer '
                    '%s. Instead, provide a shape_ref that exists in'
                    ' .blobs, i.e. one of these: %s)' % (shape_ref, self.blobs))
output_blob = np.zeros(out_blob.data.shape, dtype=np.float32)

self.ForwardPartial([input_data], [output_blob], input_idx, output_idx)

return output_blob

def _Net_BackwardFrom(self, input_layer, output_layer, input_data):
"""
Set the layer with name input_layer to input_data, do a
backward pass to the layer with name output_layer, and return
the diff at that output of that layer. input_data must be the correct
shape.
"""

input_idx = self.complete_layers.index(input_layer)
output_idx = self.complete_layers.index(output_layer)

shape_ref = output_layer
try:
    out_blob = self.blobs[shape_ref]
except KeyError:
    raise Exception('Cannot figure out the output shape from layer '
                    '%s. Instead, modify this function and provide a '
                    'shape_ref that exists in'
                    ' .blobs, i.e. one of these: %s)' % (shape_ref, self.blobs))
output_blob = np.zeros(out_blob.data.shape, dtype=np.float32)

#print '***p ', 'input_idx', input_idx, 'output_idx', output_idx
self.BackwardPartial([input_data], [output_blob], input_idx, output_idx)

return output_blob

def _Net_zero(self, zero_param_diffs = True):
"""
Set all activations (data and diffs) in the net to zero.
Take
zero_param_diffs: If True, also zero the parameter blob diffs,
else skip parameter blobs.
"""

for blob_name, blob in self.blobs.items():
    blob.data[...] = 0
    blob.diff[...] = 0
if zero_param_diffs:
    for param_name, blob_vec in self.params.items():
        for blob in blob_vec:
            blob.diff[...] = 0

def _Net_backward_from_layer(self, start_name, start_diff, diffs=None):
"""
Backward pass starting from somewhere in the middle of the
network, starting with the provided diffs.
Take
start_name: layer at which to begin the backward pass
start_diff: diff to set at start_name layer
diffs: list of diffs to return in addition to bottom diffs.
Give
outs: {blob name: diff ndarray} dict.
"""

if start_diff.shape != self.blobs[start_name].diff.shape:
    raise Exception('Expected start_diff of shape %s but got %s' % (self.blobs[start_name].diff.shape, start_diff.shape))

self.blobs[start_name].diff[...] = start_diff

return self.backward(start=start_name, diffs=diffs)

#####################

JBY: End added code

#####################

Net.ForwardFrom = _Net_ForwardFrom
Net.BackwardFrom = _Net_BackwardFrom
Net.zero = _Net_zero
Net.backward_from_layer = _Net_backward_from_layer

(2) Rebuilt pycaffe ( i.e., make pycaffe)

(3) in file "caffe_proc_thread.py"
modify self.net.backward_from_layer(backprop_layer, diffs, zero_higher = True) to self.net.backward_from_layer(backprop_layer, diffs)

image

@Eric-Zhang1990
Copy link
Author

Eric-Zhang1990 commented Sep 25, 2017 via email

@7LFB
Copy link

7LFB commented Sep 28, 2017

@larrycheungbai thanks for your kind help. it can show the results on backprop mode. But when I switch the mode to deconv, it still have something error: "classifeir" object has no attribute 'deconv_from_layer'. Can you help me that ?

@larrycheungbai
Copy link

larrycheungbai commented Sep 28, 2017 via email

@hongge831
Copy link

I have the same problem,lol

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants