Partial Eltwise Layer in Caffe

174 views
Skip to first unread message

Xinyu Pan

unread,
Oct 23, 2016, 3:04:44 AM10/23/16
to Caffe Users
Hi,

I want to implement a partial eltwise layer as follows:

Bottom_0: N * C * X * Y
Bottom_1: N * C * 1
Top_0: N * C * X * Y
Top_0[n][c][x][y] = Bottom_1[n][c][1] * Bottom_0[n][c][x][y]

I wonder if this can be built by using other basic layers in some efficient way. I also found that scale_layer is very similar to this. 

Thank you very much.

Przemek D

unread,
Oct 26, 2016, 4:13:08 AM10/26/16
to Caffe Users
I would use TileLayer to "upscale" Bottom_1 so it matched the exact size of Bottom_0 and then perform Eltwise with PROD operation. Since TileLayer only works in one axis at a time, you'll need to do it like this:
layer {
  name
: "tile_x"
  type
: "Tile"
  bottom
: "Bottom_1"
  top
: "Bottom_1_tiled_x"
  tile_param
{
    axis
: 2
    tiles
: <X>
 
}
}
layer
{
  name
: "tile_y"
  type
: "Tile"
  bottom
: "Bottom_1_tiled_x"
  top
: "Bottom_1_tiled"
  tile_param
{
    axis
: 3
    tiles
: <Y>
 
}
}
<X> and <Y> should refer to your numbers in Bottom_0 blob. After those operations, your Bottom_1_tiled can be element-wise multiplied with Bottom_0.

PS: I just noticed your Bottom_1 is 3D instead of 4D - is this correct? In this case you might want to use ReshapeLayer to add another dimension in which you'll tile.
Reply all
Reply to author
Forward
0 new messages