caffe icon indicating copy to clipboard operation
caffe copied to clipboard

How to implement the GoogleNet?

Open shiorioxy opened this issue 12 years ago • 30 comments

Is caffe can implement the GoogleNet, which is excited me. The 9 Inception modules seems very difficult....

shiorioxy avatar Sep 18 '14 07:09 shiorioxy

I guess caffe can do it, which makes me excited too. You can reference some issues about DAG caffe. just multi-output and multi-input in CNN.

zgxiangyang avatar Sep 18 '14 09:09 zgxiangyang

I think that issues are used only for development right now and bug reports. Questions about usage, code and applications should be asked on caffe-users mailing list.

On the other hand, if you make an implementation of GoogleNet, then you might want to make a pull request to caffe, to include it as an additional example.

cNikolaou avatar Sep 18 '14 10:09 cNikolaou

The Inception modules are simple compositions of fundamental layers like convolution, pooling, and concatenation. The model can be defined and executed in Caffe, since DAGs architectures are fully understood by the framework in both multiple inputs and multiple outputs / losses, but the training should be accelerated by multi-GPU parallelism to make it reasonable. Reproducing the model is a worthwhile goal since the weights are not public.

shelhamer avatar Sep 19 '14 17:09 shelhamer

Below is an inception module in the form of a single net. In particular, this is my attempt at rendering inception (3a) as shown in Table 1 and Figure 3 of the paper. I've tested it in as far as I wrote some code that parses it and loads into a net, and then forward propagates a blob through it, and verified that its output blob has the correct dimensions ( 256 channels x 28 H x 28 W). The only trick was padding the convolutions so as to get the right dimensions of the resulting top blob. And some of the layer params are vestigial/extraneous (like the weight filler) from the lenet prototxt I copied from, not something specified by the paper.

One thing that might be wrong is I don't think the paper was explicit about whether there are relus inbetween the 3x3 max pool and the 1x1 pool proj. I didn't put a relu layer in there.

So if you wanted to implement the whole GoogLeNet, you have to make 9 copies of the layers in this hunk of prototxt, and adjust the layer and top and bottom names, and number of channels for the convolutions and max pools to match Table 1. Plus add all the non-inception layers. That seems... cumbersome... at best.

I expect repeated modules like inception are going to be a thing, and that what we need is a new layer type which is itself a network ("Network-in-network"?), so that a network could recursively include other networks. Such that you have a single layer standing in for the included network. It would need a param to identify the network that implements it, and specify the parameters that are distinctive in its instantiation (e.g. the # of output channels of the conv layers, which differ from inception module to inception module). Seems straightfoward in principle, but possibly tricky in making the implementation work for all scenarios.

[Edit: stuff deleted, now that I see they say they used DistBelief]

name: "Inception_3a"

input: "maxpool_2"
input_dim: 1
input_dim: 192
input_dim: 28
input_dim: 28

layers {
  name: "1x1_conv"
  type: CONVOLUTION
  bottom: "maxpool_2"
  top: "1x1_conv"
  blobs_lr: 1
  blobs_lr: 2
  convolution_param {
    num_output: 64
    kernel_size: 1
    stride: 1
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
    }
  }
}

layers {
  name: "1x1_relu"
  type: RELU
  bottom: "1x1_conv"
  top: "1x1_relu"
}

layers {
  name: "3x3reduce_conv"
  type: CONVOLUTION
  bottom: "maxpool_2"
  top: "3x3reduce_conv"
  blobs_lr: 1
  blobs_lr: 2
  convolution_param {
    num_output: 96
    kernel_size: 1
    stride: 1
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
    }
  }
}

layers {
  name: "3x3reduce_relu"
  type: RELU
  bottom: "3x3reduce_conv"
  top: "3x3reduce_relu"
}

layers {
  name: "3x3_conv"
  type: CONVOLUTION
  bottom: "3x3reduce_relu"
  top: "3x3_conv"
  blobs_lr: 1
  blobs_lr: 2
  convolution_param {
    num_output: 128
    pad: 1
    kernel_size: 3
    stride: 1
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
    }
  }
}

layers {
  name: "3x3_relu"
  type: RELU
  bottom: "3x3_conv"
  top: "3x3_relu"
}

layers {
  name: "5x5reduce_conv"
  type: CONVOLUTION
  bottom: "maxpool_2"
  top: "5x5reduce_conv"
  blobs_lr: 1
  blobs_lr: 2
  convolution_param {
    num_output: 16
    kernel_size: 1
    stride: 1
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
    }
  }
}

layers {
  name: "5x5reduce_relu"
  type: RELU
  bottom: "5x5reduce_conv"
  top: "5x5reduce_relu"
}

layers {
  name: "5x5_conv"
  type: CONVOLUTION
  bottom: "5x5reduce_relu"
  top: "5x5_conv"
  blobs_lr: 1
  blobs_lr: 2
  convolution_param {
    num_output: 32
    pad: 2
    kernel_size: 5
    stride: 1
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
    }
  }
}

layers {
  name: "5x5_relu"
  type: RELU
  bottom: "5x5_conv"
  top: "5x5_relu"
}

layers {
  name: "maxpool_3x3"
  type: POOLING
  bottom: "maxpool_2"
  top: "maxpool_3x3"
  pooling_param {
    pool: MAX
    pad: 1
    kernel_size: 3
    stride: 1
  }
}

layers {
  name: "poolproj_1x1conv"
  type: CONVOLUTION
  bottom: "maxpool_3x3"
  top: "poolproj_1x1conv"
  blobs_lr: 1
  blobs_lr: 2
  convolution_param {
    num_output: 32
    kernel_size: 1
    stride: 1
    weight_filler {
      type: "xavier"
    }
    bias_filler {
      type: "constant"
    }
  }
}

layers {
  name: "poolproj_relu"
  type: RELU
  bottom: "poolproj_1x1conv"
  top: "poolproj_relu"
}

layers {
  name: "DepthConcatenation"
  type: CONCAT
  concat_param {
    concat_dim: 1
  }
  bottom: "1x1_relu"
  bottom: "3x3_relu"
  bottom: "5x5_relu"
  bottom: "poolproj_relu"
  top: "inception3a_Output"
}

jyegerlehner avatar Sep 25 '14 21:09 jyegerlehner

@shelhamer @jyegerlehner I am very excited with your comment, especially the last part layer "DepthConcatenation", which is a multiple inputs layer. This gave me great enlightenment, I'll try it and using this method to design my models, thank you very much.

ouxinyu avatar Sep 25 '14 23:09 ouxinyu

FYI we have released the VGG team models in the Caffe format: https://github.com/BVLC/caffe/wiki/Model-Zoo#models-used-by-the-vgg-team-in-ilsvrc-2014

ksimonyan avatar Sep 26 '14 13:09 ksimonyan

@ksimonyan I have been read your paper, and very interested in the VGG. Thanks to your implementation, I was eager to go to follow your paper and some research, thank you

ouxinyu avatar Sep 26 '14 14:09 ouxinyu

@ksimonyan Hello, Dr. Ksimonyan, you are so nice to release the VGG model. And you wrote "matlab/caffe/matcaffe_demo_vgg.m" in the Note, I want to know where I could download "matlab/caffe/matcaffe_demo_vgg.m". Could you give me the link? Thanks a lot.

ghost avatar Sep 27 '14 01:09 ghost

@YanchengBai At the moment, there are two example Matlab scripts for the VGG models in the dev branch: matcaffe_demo_vgg is for BMVC-14 models, and matcaffe_demo_vgg_mean_pix is for ILSVRC-14 models (which rely on mean pixel, rather than mean image, subtraction).

Note that while our BMVC-14 models are currently supported by the dev branch, the ILSVRC-14 ones require https://github.com/BVLC/caffe/pull/1070.

ksimonyan avatar Sep 27 '14 12:09 ksimonyan

@ksimonyan Thanks a lot for you help. You are so nice.

ghost avatar Sep 27 '14 13:09 ghost

@ouxinyu Thanks for sharing the models. I'm interested in the training protobufs especially in the weights initialization. I've tried training VGG on my own data and it seems like the loss is stuck (I'm using Gaussian filler for weights and biases). Can you provide the training protobufs?

Thanks

amiralush avatar Sep 27 '14 20:09 amiralush

@ouxinyu I'm glad you found it useful. I am also excited! I think the Inception module, and the prospect of other networks within network, is rife with greater possibilities.

jyegerlehner avatar Sep 28 '14 03:09 jyegerlehner

Since cudnn does not support pooling layer with padding, I suggest to remove the pad param of maxpool_3x3 and add "pad: 1" for poolproj_1x1conv instead.

happynear avatar Sep 29 '14 13:09 happynear

https://github.com/BVLC/caffe/issues/1169#issuecomment-63248888

futurely avatar Nov 17 '14 01:11 futurely

Has anyone been able to replicate GoogleNet's results?

mmoghimi avatar Nov 24 '14 20:11 mmoghimi

The closest published result - http://arxiv.org/abs/1411.4038. "68.5% top-1 and 88.4% top-5" @shelhamer is stated as one of the authors, so he may confirm it.

ducha-aiki avatar Nov 25 '14 09:11 ducha-aiki

The GoogLeNet classifier replication in the linked paper is the work of @sguada -- thanks Sergio! The top-5 error for 1 crop and 1 model in the original GoogLeNet paper is 10.07% while the replication has a comparable top-5 error of 11.60%. The difference could be explained by differences in data augmentation -- the mentioned replication is only trained on mirrors and crops.

shelhamer avatar Nov 26 '14 22:11 shelhamer

@shelhamer @sguada could you guys give us some hint on implementing googlenet, since its accuracy is so charming. I think there'll be a lot of people who wanna learn or do some experiment on it.

sunbaigui avatar Nov 27 '14 09:11 sunbaigui

@sunbaigui it is already here #1367

ducha-aiki avatar Nov 27 '14 09:11 ducha-aiki

@ducha-aiki I've already run on it, but never reach the claimed accuracy. Have you tried it, bro?

sunbaigui avatar Nov 27 '14 09:11 sunbaigui