简体   繁体   中英

Caffe: concatenation layer in python (L.Concat)

I wonder how to perform a concatenation of two layers into one in python. More specifically, I want to join the output of a pooling (subsampling) layer with not-visual data to then put a fully connected layer on top of that.

Let's say the subsampling layer will output neurons with shape 64*2*2 (if we ignore the caffe batch_size) and that the data layer I want to join on contains only 1 feature (a speed float that ranges from 0 to 1).

Here is some dummy code to put you in context:

import numpy as np

import caffe
from caffe import layers as L
from caffe import params as P

# ...

n.conv4 = L.Convolution(n.relu3, kernel_size=3, num_output=64, weight_filler=dict(type='xavier'))
n.pool4 = L.Pooling(n.conv4, kernel_size=3, stride=2, pool=P.Pooling.AVE)
# Data of shape `batch_size*64*2*2` out of this layer (if dropout ignored). 
n.relu4 = L.ReLU(n.pool4, in_place=True)

###
# This is what I want to know how to do, yet this might not even be
# the good way to call the function:
n.join_speed = L.Concat([n.relu4, n.data_speed], in_place=True)
####

n.ip1 = L.InnerProduct(n.join_speed, num_output=512, weight_filler=dict(type='xavier'))
n.sig1 = L.Sigmoid(n.ip1, in_place=True)

# ...

I'm not sure if you have figured out the answer to your question, but if you haven't then you may want to try the following:

bottom_layers = [n.relu4, n.data_speed]
n.join_speed = L.Concat(*bottom_layers)

The above should allow you to call Concat layer via pycaffe/python layer.

I am similarly trying to do a python-generated deconv layer

n.deconv8 = L.Deconvolution(n.conv7)

works ok but

n.deconv8 = L.Deconvolution(n.conv7,kernel_size=2)

hits

AttributeError: 'LayerParameter' object has no attribute 'kernel_size'

and similarly for

n.deconv8 = L.Deconvolution(n.conv7,num_output=1024)

so is there some new syntax for indicating these parameters (also weight_filler, bias_filler,stride)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM