deep-visualization-toolbox icon indicating copy to clipboard operation
deep-visualization-toolbox copied to clipboard

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

Open Eric-Zhang1990 opened this issue 6 years ago • 5 comments

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

Eric-Zhang1990 avatar Aug 23 '17 03:08 Eric-Zhang1990

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

larrycheungbai avatar Sep 25 '17 14:09 larrycheungbai

Thank you for your kind reply. On 2017-09-25 22:38 , larrycheungbai Wrote: 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) — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

Eric-Zhang1990 avatar Sep 25 '17 15:09 Eric-Zhang1990

@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 ?

7LFB avatar Sep 28 '17 06:09 7LFB

I have the same problem. But I have not solve it yet. Best, Lei.

On Thu, Sep 28, 2017 at 2:50 AM, 7LFB [email protected] wrote:

@larrycheungbai https://github.com/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 ?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/yosinski/deep-visualization-toolbox/issues/126#issuecomment-332744336, or mute the thread https://github.com/notifications/unsubscribe-auth/AP77pA3mHt1M-0S3e5lSZZg3m8SlO360ks5sm0G6gaJpZM4O_b5e .

larrycheungbai avatar Sep 28 '17 14:09 larrycheungbai

I have the same problem,lol

hongge831 avatar Jan 24 '18 06:01 hongge831