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

caffe: model definition: write same layer with different phase using python #4044

Open
LinHungShi opened this issue Apr 25, 2016 · 8 comments
Labels

Comments

@LinHungShi
Copy link

I want to set up a caffe CNN with python. Although I saw we can put test net in solver.prototxt, I would like to write it in model.prototxt with different phase using caffe.NetSpec(). For example, caffe model prototxt implement two data layer with different phases:

layer {
  name: "data"
  type: "Data"
  top: "data"
  top: "label"
  include {
    phase: TRAIN
  }
....
}
layer {
  name: "data"
  type: "Data"
  top: "data"
  top: "label"
  include {
    phase: TEST
  }
....
}

How should I do to get two layers with same name, but different phases?

@shaibagon
Copy link
Member

shaibagon commented May 31, 2016

related stackoverflow thread: this and this

@raaaaaymond
Copy link

I want to do exactly the same thing but haven't figured out how yet. You can pass name= and top= arguments when creating the layers (which must have different names in Python), but then I don't know how to make the next layer take, as input (bottom), those layers under their name= name (NOT their Python name).

@shaibagon
Copy link
Member

@raaaaaymond there is a workaround, you can find it here.

@raaaaaymond
Copy link

Ah yes. I didn't fully understand your answer there the first time I read it. I do now. Thank you. Still the solution is a little bit hacky (as you pointed out). But luckily in my case it does solve my problem.

@shaibagon
Copy link
Member

I see this issue was raised also here. Any chance this will be addressed soon?

@shaibagon
Copy link
Member

I find the solution proposed in this SO answer to be quite nice and elegant. I believe this solution may close this issue.

Here's the proposed workaround (using top and ntop arguments):

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

ns = caffe.NetSpec()
ns.data = L.Data(name="data", 
                 include={'phase':caffe.TEST})
ns.test_data = L.Data(name="data", ntop = 0, top='data',
                 include={'phase':caffe.TEST})
print '{}'.format(ns.to_proto())

Results with

layer {
name: "data"
type: "Data"
top: "data"
include {
phase: TRAIN
}
}
layer {
name: "data"
type: "Data"
top: "data"
include {
phase: TEST
}
}

@whcjb
Copy link

whcjb commented Dec 22, 2017

what if I want to write this?
layer{
name: "m3@ssh_output_ohem"
type: "Concat"
bottom: "m3@ssh_3x3_output_ohem"
bottom: "m3@ssh_5x5_output_ohem"
bottom: "m3@ssh_7x7_output_ohem"
top: "m3@ssh_output_ohem"
concat_param{
axis: 1
}
propagate_down: false
propagate_down: false
propagate_down: false
}
There are three# propagate_down: false, and python can not receive the duplicate args.
How to write in python?

@whcjb
Copy link

whcjb commented Dec 22, 2017

I solved the problem by using propagate_down=[False, False, False]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants