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

Adding Deconvolution Support #99

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Adding Deconvolution Support #99

wants to merge 2 commits into from

Conversation

RishabhMalviya
Copy link

I needed to convert the Deconvolution layers in some Caffe models for a paper I was implementing in Torch. I thought it would be a good idea to put in a pull request for the added support.

I've also updated the caffe.proto to match the one currently at https://github.com/BVLC/caffe/blob/master/src/caffe/proto/caffe.proto.

@RishabhMalviya
Copy link
Author

Okay wait, this actually might not be working perfectly. I tried loading a fully convolutionalized version of AlexNet from here (using train.prototxt and the model linked to in the caffemodel-url file) by running:

model = loadcaffe.load('train.prototxt', 'fcn-alexnet-pascal.caffemodel', 'cudnn')

The output is:

Successfully loaded fcn-alexnet-pascal.caffemodel
warning: module 'data [type Input]' not found
warning: module 'data_data_0_split [type Split]' not found
conv1: 96 3 11 11
conv2: 256 48 5 5
conv3: 384 256 3 3
conv4: 384 192 3 3
conv5: 256 192 3 3
fc6: 4096 256 6 6
fc7: 4096 4096 1 1
score_fr: 21 4096 1 1

There's no mention of the deconvolution layer named "upscore", present towards the end of the net (in the train.prototxt file);

...

layer {
  name: "upscore"
  type: "Deconvolution"
  bottom: "score_fr"
  top: "upscore"
  param {
    lr_mult: 0
  }
  convolution_param {
    num_output: 21
    bias_term: false
    kernel_size: 63
    stride: 32
  }
}
layer {
  name: "score"
  type: "Crop"
  bottom: "upscore"
  bottom: "data"
  top: "score"
  crop_param {
    axis: 2
    offset: 18
  }
}
layer {
  name: "loss"
  type: "SoftmaxWithLoss"
  bottom: "score"
  bottom: "label"
  top: "loss"
  loss_param {
    ignore_label: 255
    normalize: true
  }
}

Could this be because it's followed by another unrecognized layer type ('Crop')?

The only good news is that it's no longer complaining about not finding 'module 'data [type Deconvolution]'' anymore.

Copy link

@Naruto-Sasuke Naruto-Sasuke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In loadcaffe.cpp, line 203, break should be removed.
Also your pull cannot work for deconv layer as the bias copy
inconsistent. (I don't know how to directly comment the exact line..)

Copy link

@Naruto-Sasuke Naruto-Sasuke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hope can help you, we badly needs it now.

lines.emplace_back(layer.name(), buf);
}
}
break;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be removed

bool biasTerm = param.bias_term();
int groups = param.group() == 0 ? 1 : param.group();
auto &wB = layer.blobs(0);
int nInputPlane = (wB.has_shape() ? wB.shape().dim(1) : wB.channels())*groups;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know whether it is right to exchange nInputPlane with nOutputPlane. However it actually avoid mistakes in https://github.com/szagoruyko/loadcaffe/blob/master/loadcaffe.lua#L39 . However it also gives wrong loading info in
https://github.com/szagoruyko/loadcaffe/blob/master/loadcaffe.cpp#L692 . (Specially for FullConvolution, then printf("%s: %d %d %d %d\n", name, nInputPlane, nOutputPlane, kW, kH) is right....)

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

Successfully merging this pull request may close these issues.

2 participants