{
  "id": 20805,
  "title": "neon question",
  "url": "/competitions/state-farm-distracted-driver-detection/discussion/20805",
  "author_name": "",
  "post_date": "2016-05-08T11:51:47.733Z",
  "votes": 2,
  "comment_count": 7,
  "views": 1319,
  "content": "<p>I'm trying to use pretrained model like <a href=\"https://gist.github.com/nervanazoo/14bb75d2bb5f20d9c482\">Alexnet</a> in neon. <br>\nI'd like to extract features from intermediate layer and do fine-tuning, but have some troubles.</p>\n\n<p>These are problems:</p>\n\n<ul>\n<li>how to get output values of intermediate layer?</li>\n<li>how can I know proper input shape and preprocess (cf. subtract mean values, RGB or GBR, divide by 255.0)?</li>\n<li>how to change CV split in ImageLoader?</li>\n</ul>\n\n<p>I'd appreciate suggesting solutions.</p>",
  "messages": [
    {
      "id": "119246",
      "postDate": "05/08/2016 11:51:47",
      "content": "<p>I'm trying to use pretrained model like <a href=\"https://gist.github.com/nervanazoo/14bb75d2bb5f20d9c482\">Alexnet</a> in neon. <br>\nI'd like to extract features from intermediate layer and do fine-tuning, but have some troubles.</p>\n\n<p>These are problems:</p>\n\n<ul>\n<li>how to get output values of intermediate layer?</li>\n<li>how can I know proper input shape and preprocess (cf. subtract mean values, RGB or GBR, divide by 255.0)?</li>\n<li>how to change CV split in ImageLoader?</li>\n</ul>\n\n<p>I'd appreciate suggesting solutions.</p>",
      "rawMarkdown": "I'm trying to use pretrained model like [Alexnet][1] in neon.  \r\nI'd like to extract features from intermediate layer and do fine-tuning, but have some troubles.\r\n\r\n\r\nThese are problems:\r\n\r\n - how to get output values of intermediate layer?\r\n - how can I know proper input shape and preprocess (cf. subtract mean values, RGB or GBR, divide by 255.0)?\r\n - how to change CV split in ImageLoader?\r\n\r\nI'd appreciate suggesting solutions.\r\n\r\n\r\n  [1]: https://gist.github.com/nervanazoo/14bb75d2bb5f20d9c482",
      "votes": null
    },
    {
      "id": "119301",
      "postDate": "05/09/2016 00:39:39",
      "content": "<p>I will add here:</p>\n\n<ul>\n<li>How to replace last layer, so that number of output classes was 10.</li>\n<li>How to freeze weights on some layers.</li>\n</ul>",
      "rawMarkdown": "I will add here:\r\n\r\n - How to replace last layer, so that number of output classes was 10.\r\n - How to freeze weights on some layers.",
      "votes": null
    },
    {
      "id": "119416",
      "postDate": "05/10/2016 04:15:24",
      "content": "<p>The neon ModelZoo was moved recently.  To get the newest code please go to the <a href=\"https://github.com/NervanaSystems/ModelZoo\">Model Zoo GitHub repo</a>.  Also, please download the newest Alexnet, the LRN layer has been added improving performance.</p>\n\n<p>If you upgrade to the newest neon version you can use this <a href=\"https://gist.github.com/nervetumer/6c5777f31f0951bb2a1a54b10d9e3b42\">code snippet</a> as a guide for transferring the trained Alexnet to a model in which the last layer has been swapped out.  You can remove other layers as well if need be, it would just require adding more names to the layers that are ignored.</p>\n\n<p>For the Alexnet model in the model zoo, the images should be in BGR order.  You can checkout <a href=\"https://gist.github.com/nervetumer/a66cb01b9055351a87e959bf16fb473c\">this snippet</a> which shows how to run inference on a single image for more information on the input data format.  The mean values for the ILSVCR2012 data set used for training the neon alexnet is \nR: 104.412277\nG: 119.213318\nB: 126.806091</p>\n\n<p>For a Sequential model, you can access the outputs for the layers from the model.layers.layers list.  For example, the first conv layer, you can get that from model.layers.layers[0].outputs.  To get this as a numpy array use the get() method:</p>\n\n<pre><code>  # after the forward propagation\n  out = model.layers.layers[0].outputs.get()  \n</code></pre>\n\n<p>Keep in mind that bias and activation layers are done in place so you can not separate those out.  Conv layer will output an array with shape (K*H*W, N).</p>",
      "rawMarkdown": "The neon ModelZoo was moved recently.  To get the newest code please go to the [Model Zoo GitHub repo][1].  Also, please download the newest Alexnet, the LRN layer has been added improving performance.\r\n\r\nIf you upgrade to the newest neon version you can use this [code snippet][2] as a guide for transferring the trained Alexnet to a model in which the last layer has been swapped out.  You can remove other layers as well if need be, it would just require adding more names to the layers that are ignored.\r\n\r\nFor the Alexnet model in the model zoo, the images should be in BGR order.  You can checkout [this snippet][3] which shows how to run inference on a single image for more information on the input data format.  The mean values for the ILSVCR2012 data set used for training the neon alexnet is \r\nR: 104.412277\r\nG: 119.213318\r\nB: 126.806091\r\n\r\nFor a Sequential model, you can access the outputs for the layers from the model.layers.layers list.  For example, the first conv layer, you can get that from model.layers.layers[0].outputs.  To get this as a numpy array use the get() method:\r\n\r\n      # after the forward propagation\r\n      out = model.layers.layers[0].outputs.get()  \r\n\r\nKeep in mind that bias and activation layers are done in place so you can not separate those out.  Conv layer will output an array with shape (K*H*W, N).\r\n\r\n  [1]: https://github.com/NervanaSystems/ModelZoo\r\n  [2]: https://gist.github.com/nervetumer/6c5777f31f0951bb2a1a54b10d9e3b42\r\n  [3]: https://gist.github.com/nervetumer/a66cb01b9055351a87e959bf16fb473c",
      "votes": null
    },
    {
      "id": "119477",
      "postDate": "05/10/2016 15:41:42",
      "content": "<p>@nervet</p>\n\n<p>Thank you very much for creating educational snippets.  </p>\n\n<p>I tried alexnet_inference.py. <br>\nI don't have access to ImageNet, so used synset_words.txt obtained through caffe example. <br>\ntop 5 classes are below:</p>\n\n<blockquote>\n  <p>top 5 index [127 123 179   4 112] <br>\n  Top 5 classes for this image:\n  ['n02002556 white stork, Ciconia ciconia', 'n01984695 spiny lobster, langouste, rock lobster, crawfish, crayfish, sea crawfish', 'n02093256 Staffordshire bullterrier, Staffordshire bull terrier', 'n01494475 hammerhead, hammerhead shark', 'n01943899 conch']</p>\n</blockquote>\n\n<p>synset_words.txt is not corresponding? or inference did not work? <br>\nhere is <a href=\"https://gist.github.com/threecourse/012ed7cb48ca8c473d726a263e1f5bf9\">my fork script</a>.</p>",
      "rawMarkdown": "nervet\r\n\r\nThank you very much for creating educational snippets.  \r\n\r\nI tried alexnet_inference.py.  \r\nI don't have access to ImageNet, so used synset_words.txt obtained through caffe example.  \r\ntop 5 classes are below:\r\n\r\n> top 5 index [127 123 179   4 112]  \r\nTop 5 classes for this image:\r\n['n02002556 white stork, Ciconia ciconia', 'n01984695 spiny lobster, langouste, rock lobster, crawfish, crayfish, sea crawfish', 'n02093256 Staffordshire bullterrier, Staffordshire bull terrier', 'n01494475 hammerhead, hammerhead shark', 'n01943899 conch']\r\n\r\nsynset_words.txt is not corresponding? or inference did not work?   \r\nhere is [my fork script][1].\r\n\r\n\r\n  [1]: https://gist.github.com/threecourse/012ed7cb48ca8c473d726a263e1f5bf9",
      "votes": null
    },
    {
      "id": "119487",
      "postDate": "05/10/2016 17:26:16",
      "content": "<p>I believe the category order in caffe is done differently than the order in the devkit.  I posted a text file with the order used by neon <a href=\"https://s3-us-west-1.amazonaws.com/nervana-modelzoo/example_images/synsets.txt\">here</a></p>",
      "rawMarkdown": "I believe the category order in caffe is done differently than the order in the devkit.  I posted a text file with the order used by neon [here][1]\r\n\r\n\r\n  [1]: https://s3-us-west-1.amazonaws.com/nervana-modelzoo/example_images/synsets.txt",
      "votes": null
    },
    {
      "id": "119579",
      "postDate": "05/11/2016 14:27:24",
      "content": "<p>Thank you, this time classes are below:</p>\n\n<blockquote>\n  <p>top 5 index [127 123 179   4 112]\n  Top 5 classes for this image: <br>\n  ['Border collie', 'collie', 'bluetick', 'English springer, English springer spaniel', 'Boston bull, Boston terrier']</p>\n</blockquote>\n\n<p>synsets.txt has 1860 items, is that right?</p>",
      "rawMarkdown": "Thank you, this time classes are below:\r\n\r\n> top 5 index [127 123 179   4 112]\r\nTop 5 classes for this image:  \r\n['Border collie', 'collie', 'bluetick', 'English springer, English springer spaniel', 'Boston bull, Boston terrier']\r\n\r\nsynsets.txt has 1860 items, is that right?",
      "votes": null
    },
    {
      "id": "119595",
      "postDate": "05/11/2016 17:14:02",
      "content": "<p>I put them all in there the first 1000 should be the low level synsets that you need.</p>",
      "rawMarkdown": "I put them all in there the first 1000 should be the low level synsets that you need.",
      "votes": null
    },
    {
      "id": "119758",
      "postDate": "05/12/2016 16:55:26",
      "content": "<p>The top class is 'Border collie', so it seems inference is not the best. <br>\n<a href=\"https://gist.github.com/threecourse/012ed7cb48ca8c473d726a263e1f5bf9\">my updated script</a> is here, <br>\ndid I do something wrong? or is that expected alexnet inference?</p>",
      "rawMarkdown": "The top class is 'Border collie', so it seems inference is not the best.  \r\n[my updated script][1] is here,   \r\ndid I do something wrong? or is that expected alexnet inference?\r\n\r\n  [1]: https://gist.github.com/threecourse/012ed7cb48ca8c473d726a263e1f5bf9",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 119301,
      "author_name": "iglovikov",
      "author_url": "",
      "post_date": "05/09/2016 00:39:39",
      "content": "<p>I will add here:</p>\n\n<ul>\n<li>How to replace last layer, so that number of output classes was 10.</li>\n<li>How to freeze weights on some layers.</li>\n</ul>",
      "votes": null,
      "replies": []
    },
    {
      "id": 119416,
      "author_name": "nervet",
      "author_url": "",
      "post_date": "05/10/2016 04:15:24",
      "content": "<p>The neon ModelZoo was moved recently.  To get the newest code please go to the <a href=\"https://github.com/NervanaSystems/ModelZoo\">Model Zoo GitHub repo</a>.  Also, please download the newest Alexnet, the LRN layer has been added improving performance.</p>\n\n<p>If you upgrade to the newest neon version you can use this <a href=\"https://gist.github.com/nervetumer/6c5777f31f0951bb2a1a54b10d9e3b42\">code snippet</a> as a guide for transferring the trained Alexnet to a model in which the last layer has been swapped out.  You can remove other layers as well if need be, it would just require adding more names to the layers that are ignored.</p>\n\n<p>For the Alexnet model in the model zoo, the images should be in BGR order.  You can checkout <a href=\"https://gist.github.com/nervetumer/a66cb01b9055351a87e959bf16fb473c\">this snippet</a> which shows how to run inference on a single image for more information on the input data format.  The mean values for the ILSVCR2012 data set used for training the neon alexnet is \nR: 104.412277\nG: 119.213318\nB: 126.806091</p>\n\n<p>For a Sequential model, you can access the outputs for the layers from the model.layers.layers list.  For example, the first conv layer, you can get that from model.layers.layers[0].outputs.  To get this as a numpy array use the get() method:</p>\n\n<pre><code>  # after the forward propagation\n  out = model.layers.layers[0].outputs.get()  \n</code></pre>\n\n<p>Keep in mind that bias and activation layers are done in place so you can not separate those out.  Conv layer will output an array with shape (K*H*W, N).</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 119477,
      "author_name": "threecourse",
      "author_url": "",
      "post_date": "05/10/2016 15:41:42",
      "content": "<p>@nervet</p>\n\n<p>Thank you very much for creating educational snippets.  </p>\n\n<p>I tried alexnet_inference.py. <br>\nI don't have access to ImageNet, so used synset_words.txt obtained through caffe example. <br>\ntop 5 classes are below:</p>\n\n<blockquote>\n  <p>top 5 index [127 123 179   4 112] <br>\n  Top 5 classes for this image:\n  ['n02002556 white stork, Ciconia ciconia', 'n01984695 spiny lobster, langouste, rock lobster, crawfish, crayfish, sea crawfish', 'n02093256 Staffordshire bullterrier, Staffordshire bull terrier', 'n01494475 hammerhead, hammerhead shark', 'n01943899 conch']</p>\n</blockquote>\n\n<p>synset_words.txt is not corresponding? or inference did not work? <br>\nhere is <a href=\"https://gist.github.com/threecourse/012ed7cb48ca8c473d726a263e1f5bf9\">my fork script</a>.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 119487,
      "author_name": "nervet",
      "author_url": "",
      "post_date": "05/10/2016 17:26:16",
      "content": "<p>I believe the category order in caffe is done differently than the order in the devkit.  I posted a text file with the order used by neon <a href=\"https://s3-us-west-1.amazonaws.com/nervana-modelzoo/example_images/synsets.txt\">here</a></p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 119579,
      "author_name": "threecourse",
      "author_url": "",
      "post_date": "05/11/2016 14:27:24",
      "content": "<p>Thank you, this time classes are below:</p>\n\n<blockquote>\n  <p>top 5 index [127 123 179   4 112]\n  Top 5 classes for this image: <br>\n  ['Border collie', 'collie', 'bluetick', 'English springer, English springer spaniel', 'Boston bull, Boston terrier']</p>\n</blockquote>\n\n<p>synsets.txt has 1860 items, is that right?</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 119595,
      "author_name": "nervet",
      "author_url": "",
      "post_date": "05/11/2016 17:14:02",
      "content": "<p>I put them all in there the first 1000 should be the low level synsets that you need.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 119758,
      "author_name": "threecourse",
      "author_url": "",
      "post_date": "05/12/2016 16:55:26",
      "content": "<p>The top class is 'Border collie', so it seems inference is not the best. <br>\n<a href=\"https://gist.github.com/threecourse/012ed7cb48ca8c473d726a263e1f5bf9\">my updated script</a> is here, <br>\ndid I do something wrong? or is that expected alexnet inference?</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "119246": "I'm trying to use pretrained model like [Alexnet][1] in neon.  \r\nI'd like to extract features from intermediate layer and do fine-tuning, but have some troubles.\r\n\r\n\r\nThese are problems:\r\n\r\n - how to get output values of intermediate layer?\r\n - how can I know proper input shape and preprocess (cf. subtract mean values, RGB or GBR, divide by 255.0)?\r\n - how to change CV split in ImageLoader?\r\n\r\nI'd appreciate suggesting solutions.\r\n\r\n\r\n  [1]: https://gist.github.com/nervanazoo/14bb75d2bb5f20d9c482",
    "119301": "I will add here:\r\n\r\n - How to replace last layer, so that number of output classes was 10.\r\n - How to freeze weights on some layers.",
    "119416": "The neon ModelZoo was moved recently.  To get the newest code please go to the [Model Zoo GitHub repo][1].  Also, please download the newest Alexnet, the LRN layer has been added improving performance.\r\n\r\nIf you upgrade to the newest neon version you can use this [code snippet][2] as a guide for transferring the trained Alexnet to a model in which the last layer has been swapped out.  You can remove other layers as well if need be, it would just require adding more names to the layers that are ignored.\r\n\r\nFor the Alexnet model in the model zoo, the images should be in BGR order.  You can checkout [this snippet][3] which shows how to run inference on a single image for more information on the input data format.  The mean values for the ILSVCR2012 data set used for training the neon alexnet is \r\nR: 104.412277\r\nG: 119.213318\r\nB: 126.806091\r\n\r\nFor a Sequential model, you can access the outputs for the layers from the model.layers.layers list.  For example, the first conv layer, you can get that from model.layers.layers[0].outputs.  To get this as a numpy array use the get() method:\r\n\r\n      # after the forward propagation\r\n      out = model.layers.layers[0].outputs.get()  \r\n\r\nKeep in mind that bias and activation layers are done in place so you can not separate those out.  Conv layer will output an array with shape (K*H*W, N).\r\n\r\n  [1]: https://github.com/NervanaSystems/ModelZoo\r\n  [2]: https://gist.github.com/nervetumer/6c5777f31f0951bb2a1a54b10d9e3b42\r\n  [3]: https://gist.github.com/nervetumer/a66cb01b9055351a87e959bf16fb473c",
    "119477": "nervet\r\n\r\nThank you very much for creating educational snippets.  \r\n\r\nI tried alexnet_inference.py.  \r\nI don't have access to ImageNet, so used synset_words.txt obtained through caffe example.  \r\ntop 5 classes are below:\r\n\r\n> top 5 index [127 123 179   4 112]  \r\nTop 5 classes for this image:\r\n['n02002556 white stork, Ciconia ciconia', 'n01984695 spiny lobster, langouste, rock lobster, crawfish, crayfish, sea crawfish', 'n02093256 Staffordshire bullterrier, Staffordshire bull terrier', 'n01494475 hammerhead, hammerhead shark', 'n01943899 conch']\r\n\r\nsynset_words.txt is not corresponding? or inference did not work?   \r\nhere is [my fork script][1].\r\n\r\n\r\n  [1]: https://gist.github.com/threecourse/012ed7cb48ca8c473d726a263e1f5bf9",
    "119487": "I believe the category order in caffe is done differently than the order in the devkit.  I posted a text file with the order used by neon [here][1]\r\n\r\n\r\n  [1]: https://s3-us-west-1.amazonaws.com/nervana-modelzoo/example_images/synsets.txt",
    "119579": "Thank you, this time classes are below:\r\n\r\n> top 5 index [127 123 179   4 112]\r\nTop 5 classes for this image:  \r\n['Border collie', 'collie', 'bluetick', 'English springer, English springer spaniel', 'Boston bull, Boston terrier']\r\n\r\nsynsets.txt has 1860 items, is that right?",
    "119595": "I put them all in there the first 1000 should be the low level synsets that you need.",
    "119758": "The top class is 'Border collie', so it seems inference is not the best.  \r\n[my updated script][1] is here,   \r\ndid I do something wrong? or is that expected alexnet inference?\r\n\r\n  [1]: https://gist.github.com/threecourse/012ed7cb48ca8c473d726a263e1f5bf9"
  },
  "source": "meta"
}