Caffe: Slice or split data using python NetSpec()

Created on 21 Jul 2016  ·  3Comments  ·  Source: BVLC/caffe

I need to split input some data into 3 blocks, process all it separately and join after. When I try to get knowing count of tops it gives me this error:

    n.lr, n.lg, n.lb = L.Slice(n.data, slice_param={'axis':1})
TypeError: 'Top' object is not iterable

When I changed code to

    n.lr = L.Slice(n.data, slice_param={'axis':1})

it seems to works and even produces block inside prototxt:

layer {
  name: "lr"
  type: "Slice"
  bottom: "data"
  top: "lr"
  slice_param {
    axis: 1
  }
}

but really it just leaves data unchanged:

I0722 01:55:31.749025 14994 net.cpp:160] Setting up data
I0722 01:55:31.749075 14994 net.cpp:168] Top shape: 32 3 8 1280 (983040)
I0722 01:55:31.749099 14994 layer_factory.hpp:78] Creating layer lr
I0722 01:55:31.749116 14994 net.cpp:109] Creating Layer lr
I0722 01:55:31.749145 14994 net.cpp:470] lr <- data
I0722 01:55:31.749157 14994 net.cpp:439] lr -> lr
I0722 01:55:31.749181 14994 net.cpp:160] Setting up lr
I0722 01:55:31.749191 14994 net.cpp:168] Top shape: 32 3 8 1280 (983040)

If I wrong somewhere, it would be nice to see example how to do it properly.

Most helpful comment

you should use

n.lr = L.Slice(n.data, slice_param={'axis':1}, ntop=3)

All 3 comments

I am having the same problem. I also tried
n.top = L.Slice(n.bottom, slice_param=dict(axis=0,slice_point=[batchsize,2*batchsize]), top=[n.top1,n.top2])
then there is keyError on n.top1

you should use

n.lr = L.Slice(n.data, slice_param={'axis':1}, ntop=3)

The write code is
n.lr, n.lg, n.lb = L.Slice(n.data, slice_param={'axis':1},ntop=3)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

LarsHH picture LarsHH  ·  3Comments

OpenHero picture OpenHero  ·  3Comments

malreddysid picture malreddysid  ·  3Comments

hawklucky picture hawklucky  ·  3Comments

sdemyanov picture sdemyanov  ·  3Comments