{"action":"opened","issue":{"url":"https://api.github.com/repos/BVLC/caffe/issues/3864","repository_url":"https://api.github.com/repos/BVLC/caffe","labels_url":"https://api.github.com/repos/BVLC/caffe/issues/3864/labels{/name}","comments_url":"https://api.github.com/repos/BVLC/caffe/issues/3864/comments","events_url":"https://api.github.com/repos/BVLC/caffe/issues/3864/events","html_url":"https://github.com/BVLC/caffe/issues/3864","id":142489861,"number":3864,"title":"[Discussion] How to specify all-in-one networks","user":{"login":"lukeyeager","id":687269,"avatar_url":"https://avatars.githubusercontent.com/u/687269?v=3","gravatar_id":"","url":"https://api.github.com/users/lukeyeager","html_url":"https://github.com/lukeyeager","followers_url":"https://api.github.com/users/lukeyeager/followers","following_url":"https://api.github.com/users/lukeyeager/following{/other_user}","gists_url":"https://api.github.com/users/lukeyeager/gists{/gist_id}","starred_url":"https://api.github.com/users/lukeyeager/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lukeyeager/subscriptions","organizations_url":"https://api.github.com/users/lukeyeager/orgs","repos_url":"https://api.github.com/users/lukeyeager/repos","events_url":"https://api.github.com/users/lukeyeager/events{/privacy}","received_events_url":"https://api.github.com/users/lukeyeager/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-03-21T22:31:00Z","updated_at":"2016-03-21T22:31:00Z","closed_at":null,"body":"#3211 did most of the hard work to enable all-in-one networks (i.e. just a single `network.prototxt` instead of both `train_val.prototxt` and `deploy.prototxt`). I see several ways that all-in-one networks could be specified. The flexibility is nice for advanced users, but could be confusing to novices. I'd like to eventually update all the examples to use all-in-one networks in a standard way, and I think we should have a discussion first about how to do it.\r\n\r\nThe trick is to find a way to distinguish between layers used for _validation_ and those used for _deployment_.\r\n\r\n## Option 1 - using not_phase\r\n\r\nThis is the least invasive option. The only interface that needs changing is the solver prototxt.\r\n\r\n**Train state** - `phase: TRAIN`\r\n**Val state** - `phase: TEST stage: \"val\"`\r\n**Deploy state** - `phase: TEST`\r\n\r\n**solver.prototxt**\r\n```sh\r\ntest_state { stage: \"val\" }\r\n```\r\n**network.prototxt**\r\n```sh\r\nlayer {\r\n  name: \"train_layer\"\r\n  include { phase: TRAIN }\r\n}\r\nlayer {\r\n  name: \"val_layer\"\r\n  include { stage: \"val\" }\r\n  # or (equivalent, but more explicit):\r\n  include { phase: TEST stage: \"val\" }\r\n}\r\nlayer {\r\n  name: \"deploy_layer\"\r\n  include { phase: TEST not_stage: \"val\" }\r\n}\r\n```\r\n\r\n## Option 2 - using level\r\n\r\nThis is the least user-friendly option. But it is also non-invasive like Option 1.\r\n\r\n**Train state** - `phase: TRAIN`\r\n**Val state** - `phase: TEST level: 1`\r\n**Deploy state** - `phase: TEST`\r\n\r\n**solver.prototxt**\r\n```sh\r\ntest_state { level: 1 }\r\n```\r\n**network.prototxt**\r\n```sh\r\nlayer {\r\n  name: \"train_layer\"\r\n  include { phase: TRAIN }\r\n}\r\nlayer {\r\n  name: \"val_layer\"\r\n  include { min_level: 1 }\r\n  # or (equivalent, but more explicit):\r\n  include { phase: TEST min_level: 1 }\r\n}\r\nlayer {\r\n  name: \"deploy_layer\"\r\n  include { max_level: 0 }\r\n  # or (equivalent, but more explicit):\r\n  include { phase: TEST max_level: 0 }\r\n}\r\n```\r\n\r\n## Option 3 - using phases\r\n\r\nThis is the most verbose option. It requires https://github.com/BVLC/caffe/pull/3863 (or something like it) in order to set the `stage` during deployment. I've already committed to it in DIGITS in hopes that this will be what Caffe chooses to go with (https://github.com/NVIDIA/DIGITS/pull/628).\r\n\r\n**Train state** - `phase: TRAIN stage: \"train\"`\r\n**Val state** - `phase: TEST stage: \"val\"`\r\n**Deploy state** - `phase: TEST stage: \"deploy\"`\r\n\r\n**solver.prototxt**\r\n```sh\r\ntrain_state { stage: \"train\" }\r\ntest_state { stage: \"val\" }\r\n```\r\n**network.prototxt**\r\n```sh\r\nlayer {\r\n  name: \"train_layer\"\r\n  include { stage: \"train\" }\r\n  # or (equivalent, but more explicit):\r\n  include { phase: TRAIN stage: \"train\" }\r\n}\r\nlayer {\r\n  name: \"val_layer\"\r\n  include { stage: \"val\" }\r\n  # or (equivalent, but more explicit):\r\n  include { phase: TEST stage: \"val\" }\r\n}\r\nlayer {\r\n  name: \"deploy_layer\"\r\n  include { stage: \"deploy\" }\r\n  # or (equivalent, but more explicit):\r\n  include { phase: TEST stage: \"deploy\" }\r\n}\r\n```\r\n\r\n## Other options?\r\n\r\nAny clever ideas? Anything I haven't thought of?"}}