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

Allowing netspec to have a phase #2861

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

philkr
Copy link
Contributor

@philkr philkr commented Aug 4, 2015

This is a first attempt to allow netspec to interact with phases. It is admittedly a bit ugly, so feedback would be welcome.
Here is an example how to use this:

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

ns = NetSpec()

A = L.ImageData(source="/tmp/test.txt", root_folder="/data/sintel_intrinsic/images/clean/", ntop=2, name='foo')
B = L.ImageData(source="/tmp/train.txt", root_folder="/data/sintel_intrinsic/images/clean/", ntop=2, name='bar')
ns.data, ns.ignore = phase(train=A, test=B)
print(ns.to_proto())

data, ignore = phase(train=A, test=B)
print( to_proto(data, ignore) )

and here is the expected output

layer {
  name: "foo"
  type: "ImageData"
  top: "data"
  top: "ignore"
  include {
    phase: TRAIN
  }
  image_data_param {
    source: "/tmp/test.txt"
    root_folder: "/data/sintel_intrinsic/images/clean/"
  }
}
layer {
  name: "bar"
  type: "ImageData"
  top: "data"
  top: "ignore"
  include {
    phase: TEST
  }
  image_data_param {
    source: "/tmp/train.txt"
    root_folder: "/data/sintel_intrinsic/images/clean/"
  }
}

layer {
  name: "foo"
  type: "ImageData"
  top: "ImageData1"
  top: "ImageData2"
  include {
    phase: TRAIN
  }
  image_data_param {
    source: "/tmp/test.txt"
    root_folder: "/data/sintel_intrinsic/images/clean/"
  }
}
layer {
  name: "bar"
  type: "ImageData"
  top: "ImageData1"
  top: "ImageData2"
  include {
    phase: TEST
  }
  image_data_param {
    source: "/tmp/train.txt"
    root_folder: "/data/sintel_intrinsic/images/clean/"
  }
}

@longjon longjon added the Python label Aug 8, 2015
@longjon
Copy link
Contributor

longjon commented Aug 24, 2015

My general feeling wrt phase (and stage, and level) is that these are ways to inject programmability into protobuf which are not necessary giving net spec, and in fact I wouldn't mind obsoleting these options and simplifying Net::Init and layer code accordingly. (Scan issues if you want to see some bugs that have resulted from failing to account for phase in all the right places.)

But I'm happy to hear other opinions and I don't object to merging code that exposes functionality that is already present. It seems like there are two ways to go about this:

  1. Implement the straightforward wrapping of protobuf syntax, e.g., L.Layer(include=dict(phase=?.TRAIN))
  2. Try to come up with some natural syntax for this functionality in the net spec language.

This PR takes the second path (q.v. #2959 (comment)). The syntax represented here feels pretty natural to me, cf. switch or case statements from other languages, or (very roughly) np.where and related functions.

Given the tone of the PR message, I'm going to tag sandbox and not look really carefully into the implementation, but happy to take another look if there's clamoring for merge.

Another thing to consider (though it's a different direction) is reifying this selection into a layer (cf. FilterLayer, which is related but not the same).

@bchu
Copy link
Contributor

bchu commented Dec 12, 2015

To chime in on an old issue, I'd very much be in favor of the first approach. It's quite simple and fits naturally into the mental model of how NetSpec works. So far I'm using a hacked together version of the first approach when I'm programmatically generating experiments with NetSpec.

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

Successfully merging this pull request may close these issues.

3 participants