{
  "id": 15807,
  "title": "Team o_O Competition Report and Code",
  "url": "/competitions/diabetic-retinopathy-detection/discussion/15807",
  "author_name": "",
  "post_date": "2015-08-06T17:09:09.137Z",
  "votes": 16,
  "comment_count": 20,
  "views": 8575,
  "content": "<p>Report and code are now available at <a href=\"https://github.com/sveitser/kaggle_diabetic\">https://github.com/sveitser/kaggle_diabetic</a> and the report is also attached below.</p>\n\n<p>Thanks again to teammate Stephan, Kaggle, the California Healthcare Foundation and EyePACS as well as everyone who competed!</p>",
  "messages": [
    {
      "id": "88693",
      "postDate": "08/06/2015 17:09:09",
      "content": "<p>Report and code are now available at <a href=\"https://github.com/sveitser/kaggle_diabetic\">https://github.com/sveitser/kaggle_diabetic</a> and the report is also attached below.</p>\n\n<p>Thanks again to teammate Stephan, Kaggle, the California Healthcare Foundation and EyePACS as well as everyone who competed!</p>",
      "rawMarkdown": "Report and code are now available at https://github.com/sveitser/kaggle_diabetic and the report is also attached below.\r\n\r\nThanks again to teammate Stephan, Kaggle, the California Healthcare Foundation and EyePACS as well as everyone who competed!",
      "votes": null
    },
    {
      "id": "88829",
      "postDate": "08/07/2015 16:18:49",
      "content": "<p>Congratulations and Thank you.</p>",
      "rawMarkdown": "Congratulations and Thank you.",
      "votes": null
    },
    {
      "id": "89054",
      "postDate": "08/10/2015 19:46:16",
      "content": "<p>You guys have done incredible research, great work!!  I am curious and asking the top 5 winners this question, did you stick with one framework and/or library for the whole competition, such as the torch library, theano or Caffe, or did you find yourselves re-gearing earlier for a better suited framework and/or library for this particular challenge? </p>",
      "rawMarkdown": "You guys have done incredible research, great work!!  I am curious and asking the top 5 winners this question, did you stick with one framework and/or library for the whole competition, such as the torch library, theano or Caffe, or did you find yourselves re-gearing earlier for a better suited framework and/or library for this particular challenge?",
      "votes": null
    },
    {
      "id": "89353",
      "postDate": "08/14/2015 10:24:51",
      "content": "<p>@Keaton. Thanks. For this competition we used nolearn and lasagne exclusively.</p>\n\n<p>The first conv nets I trained were for the plankton competition. I started using caffe but later changed to nolearn/lasagne because I found it much easier to do data augmentation (and almost anything else really) in python than in C++. I didn't get very far with the caffe python bindings at the time but I think they have undergone some changes recently. I'm still only starting to understand theano but most of the things I needed so far are available in lasagne or not much more than a google search away.</p>",
      "rawMarkdown": "Keaton. Thanks. For this competition we used nolearn and lasagne exclusively.\r\n\r\nThe first conv nets I trained were for the plankton competition. I started using caffe but later changed to nolearn/lasagne because I found it much easier to do data augmentation (and almost anything else really) in python than in C++. I didn't get very far with the caffe python bindings at the time but I think they have undergone some changes recently. I'm still only starting to understand theano but most of the things I needed so far are available in lasagne or not much more than a google search away.",
      "votes": null
    },
    {
      "id": "89373",
      "postDate": "08/14/2015 18:01:40",
      "content": "<p>Mathis - Thanks, this is really helpful. What is the reason for blurring the images before resizing? I don't understand how this can help, in fact it seems like it would reduce performance.</p>",
      "rawMarkdown": "Mathis - Thanks, this is really helpful. What is the reason for blurring the images before resizing? I don't understand how this can help, in fact it seems like it would reduce performance.",
      "votes": null
    },
    {
      "id": "89386",
      "postDate": "08/14/2015 19:22:42",
      "content": "<p>@James King, We ran into some issues when trying to separate the foreground from the background because some images are very dark and sometimes the background is not totally black. The first thing that worked well enough was computing a threshold value from the maximum of a thin left and right strip of  a blurred copy of the image. The bounding box is used to crop the original image so we don't blur the image that we crop and resize.</p>",
      "rawMarkdown": "James King, We ran into some issues when trying to separate the foreground from the background because some images are very dark and sometimes the background is not totally black. The first thing that worked well enough was computing a threshold value from the maximum of a thin left and right strip of  a blurred copy of the image. The bounding box is used to crop the original image so we don't blur the image that we crop and resize.",
      "votes": null
    },
    {
      "id": "90141",
      "postDate": "08/23/2015 02:42:49",
      "content": "<p>I have run the code and gotten a leaderboard score of 0.836/0.827 (using only 20 iterations in the transform step instead of 50). Some notes which might help anyone who wants to do the same:</p>\n\n<ol>\n<li>The <code>make_kaggle_solution.sh</code> is great, I wish everyone created a start to finish script like this.</li>\n<li>There are references to directory <code>config</code>  in the script; it should be <code>configs</code>.</li>\n<li>In <code>requirements.txt</code>, I got a public key error when trying to access <code>benanne/Lasagne.git</code>, so I cloned <a href=\"https://github.com/Lasagne/Lasagne.git\">https://github.com/Lasagne/Lasagne.git</a> and then checked out the appropriate commit. You have to use the older commit, since <code>lasagne.objectives.Objective</code> has been deprecated.</li>\n<li>The shell variable BEST_VALID_WEIGHTS needs to include the path of the file returned by <code>ls -t | head -n 1</code>.</li>\n<li>To change the feature files used for blending, edit <code>blend.yml</code>.</li>\n<li>Wall time to fit this was about a week on my GTX 980; but there was a lot of idle time since a step may have finished when I was away from the computer and I didn't start the next one for several hours. If I had a second gpu I could have done done multiple steps at the same time.</li>\n<li>There are about 1600 lines of code. It's well written and fairly easy to understand.</li>\n</ol>",
      "rawMarkdown": "I have run the code and gotten a leaderboard score of 0.836/0.827 (using only 20 iterations in the transform step instead of 50). Some notes which might help anyone who wants to do the same:\r\n\r\n1. The `make_kaggle_solution.sh` is great, I wish everyone created a start to finish script like this.\r\n2. There are references to directory `config`  in the script; it should be `configs`.\r\n3. In `requirements.txt`, I got a public key error when trying to access `benanne/Lasagne.git `, so I cloned https://github.com/Lasagne/Lasagne.git and then checked out the appropriate commit. You have to use the older commit, since `lasagne.objectives.Objective` has been deprecated.\r\n4. The shell variable BEST_VALID_WEIGHTS needs to include the path of the file returned by `ls -t | head -n 1`.\r\n4. To change the feature files used for blending, edit `blend.yml`.\r\n5. Wall time to fit this was about a week on my GTX 980; but there was a lot of idle time since a step may have finished when I was away from the computer and I didn't start the next one for several hours. If I had a second gpu I could have done done multiple steps at the same time.\r\n6. There are about 1600 lines of code. It's well written and fairly easy to understand.",
      "votes": null
    },
    {
      "id": "90144",
      "postDate": "08/23/2015 04:15:23",
      "content": "<p>Thanks @James. I fixed the requirements.txt file to not use the git protocol and fixed the bugs with the kaggle solution script you mentioned.</p>",
      "rawMarkdown": "Thanks @James. I fixed the requirements.txt file to not use the git protocol and fixed the bugs with the kaggle solution script you mentioned.",
      "votes": null
    },
    {
      "id": "91054",
      "postDate": "08/31/2015 16:35:07",
      "content": "<p>@Mathis. It is a very well-written code. However, I could not figure out how can I save the final trained model. In other words, how can we save a model, as a cPickle object for example, so we can load it for prediction on test images?</p>",
      "rawMarkdown": "Mathis. It is a very well-written code. However, I could not figure out how can I save the final trained model. In other words, how can we save a model, as a cPickle object for example, so we can load it for prediction on test images?",
      "votes": null
    },
    {
      "id": "91853",
      "postDate": "09/08/2015 14:39:28",
      "content": "<p>Hi Ali. Sorry for the late reply. For the convolutional networks you can load the parameters/weights from the files saved inside the sub-directories inside the <em>weights</em> directory. For the blend network I never saved the weights because it just took a few minutes to train these networks. </p>\n\n<p>You should also be able to do so with the save save_params_to method though: <a href=\"https://github.com/dnouri/nolearn/blob/master/nolearn/lasagne/base.py#L616-L619\">https://github.com/dnouri/nolearn/blob/master/nolearn/lasagne/base.py#L616-L619</a></p>\n\n<p>There is currently no convenient way to use both the convolutional network and the blend network together as one model. You could however load them both into memory and do something like,</p>\n\n<ol>\n<li>use the transform method of the convolutional network to extract features for the image</li>\n<li>scale and reshape the features from 1. (blend both eyes)</li>\n<li>use the predict method of the blend network on output from 2.</li>\n</ol>\n\n<p>Then if desired combine the two networks inside a single class and the three steps above into a single method of that class.</p>\n\n<p>Hope this helps.</p>",
      "rawMarkdown": "Hi Ali. Sorry for the late reply. For the convolutional networks you can load the parameters/weights from the files saved inside the sub-directories inside the *weights* directory. For the blend network I never saved the weights because it just took a few minutes to train these networks. \r\n\r\nYou should also be able to do so with the save save_params_to method though: https://github.com/dnouri/nolearn/blob/master/nolearn/lasagne/base.py#L616-L619\r\n\r\nThere is currently no convenient way to use both the convolutional network and the blend network together as one model. You could however load them both into memory and do something like,\r\n\r\n1. use the transform method of the convolutional network to extract features for the image\r\n2. scale and reshape the features from 1. (blend both eyes)\r\n3. use the predict method of the blend network on output from 2.\r\n\r\nThen if desired combine the two networks inside a single class and the three steps above into a single method of that class.\r\n\r\nHope this helps.",
      "votes": null
    },
    {
      "id": "93525",
      "postDate": "09/27/2015 07:48:34",
      "content": "<p>Hi Mathis. Thanks for the help, yet, I could not build the network and run the model on a CPU. I have implemented the convolutional network my self using a subset of 1000 images, almost equal number of images from each class. However, I have several questions regarding your architecture:</p>\n\n<p>1- In your convolutional network, the output of your network is a 512 element vector, the maxout layer. As far as I know from the NN, we need a label for every input to the network. So, what is the label here?</p>\n\n<p>2- The number of inputs to your blend network is 8193. How did you come with this number?</p>\n\n<p>I have also contacted you by email to obtain the weight matrices for the full trained network. I think it would be good for me as any other one, to be able to see the whole code working. So, I would like to ask you again for the weight matrices.</p>\n\n<p>Thanks in advance.</p>",
      "rawMarkdown": "Hi Mathis. Thanks for the help, yet, I could not build the network and run the model on a CPU. I have implemented the convolutional network my self using a subset of 1000 images, almost equal number of images from each class. However, I have several questions regarding your architecture:\r\n\r\n1- In your convolutional network, the output of your network is a 512 element vector, the maxout layer. As far as I know from the NN, we need a label for every input to the network. So, what is the label here?\r\n\r\n2- The number of inputs to your blend network is 8193. How did you come with this number?\r\n\r\nI have also contacted you by email to obtain the weight matrices for the full trained network. I think it would be good for me as any other one, to be able to see the whole code working. So, I would like to ask you again for the weight matrices.\r\n\r\nThanks in advance.",
      "votes": null
    },
    {
      "id": "93579",
      "postDate": "09/28/2015 12:57:08",
      "content": "<p>Awesome work, Congratulations.\nI have doubt, How did you handle class imbalance in the data ?</p>",
      "rawMarkdown": "Awesome work, Congratulations.\r\nI have doubt, How did you handle class imbalance in the data ?",
      "votes": null
    },
    {
      "id": "95764",
      "postDate": "10/11/2015 16:09:36",
      "content": "<p>[quote=Mathis Antony;89386]</p>\n\n<p>@James King, We ran into some issues when trying to separate the foreground from the background because some images are very dark and sometimes the background is not totally black. The first thing that worked well enough was computing a threshold value from the maximum of a thin left and right strip of  a blurred copy of the image. The bounding box is used to crop the original image so we don't blur the image that we crop and resize.</p>\n\n<p>[/quote]</p>\n\n<p>Hi Mathis,</p>\n\n<p>awesome work. The blurring is an interesting idea but its easier to find a way to crop the pictures which even works on very dark pictures.</p>\n\n<ol>\n<li>sum up the picture on every axis except height/width, depending what axis you want to find the border on.\nThe result is a 1D array length of either height or width in pixels.</li>\n<li>Find the maximum value in this array and take 10% of it, this is the threshhold</li>\n<li>find the value where it first is bigger than the threshhold-value, this is your boundary</li>\n</ol>\n\n<p>It works because dark pixels have lower values. By summing up on all except 1 axis you can see where the color is and have a kind of 2d plot.</p>\n\n<p>Here my code for it:</p>\n\n<pre><code>def find_border_dynamic_threshold(image, axis):\n    &quot;&quot;&quot;\n    Sums up the axis to one dimension only. The resulting 1 dimensional array has the property that\n    a higher number represents an overall brighter picture on the axis. This allows to find the border which is very dark\n    (black). The border is found by taking the maximum value of this summed up array and the border starts where the\n    image is a 1/10th of this value.\n\n    This relative approach is necessary because some of the images are very bright, others are very dark. So the border\n    and the pixel where they start differ a lot.\n    &quot;&quot;&quot;\n    im_array = np.sum(np.sum(image, axis=axis), axis=1)\n    threshold = im_array.max() / 10\n    indices = np.where(im_array &gt; threshold)\n    return indices[0][0], indices[0][-1]\n</code></pre>\n\n<p>After hat the cropping is easy:</p>\n\n<pre><code># finding min max indices\nmin_x, max_x = find_border_dynamic_threshold(image, 0)\nmin_y, max_y = find_border_dynamic_threshold(image, 1)\n\n# crop\nimage = image[min_y:max_y, min_x:max_x]\n</code></pre>",
      "rawMarkdown": "[quote=Mathis Antony;89386]\r\n\r\n@James King, We ran into some issues when trying to separate the foreground from the background because some images are very dark and sometimes the background is not totally black. The first thing that worked well enough was computing a threshold value from the maximum of a thin left and right strip of  a blurred copy of the image. The bounding box is used to crop the original image so we don't blur the image that we crop and resize.\r\n\r\n[/quote]\r\n\r\nHi Mathis,\r\n\r\nawesome work. The blurring is an interesting idea but its easier to find a way to crop the pictures which even works on very dark pictures.\r\n\r\n1. sum up the picture on every axis except height/width, depending what axis you want to find the border on.\r\nThe result is a 1D array length of either height or width in pixels.\r\n2. Find the maximum value in this array and take 10% of it, this is the threshhold\r\n3. find the value where it first is bigger than the threshhold-value, this is your boundary\r\n\r\nIt works because dark pixels have lower values. By summing up on all except 1 axis you can see where the color is and have a kind of 2d plot.\r\n\r\n\r\nHere my code for it:\r\n\r\n    def find_border_dynamic_threshold(image, axis):\r\n        \"\"\"\r\n        Sums up the axis to one dimension only. The resulting 1 dimensional array has the property that\r\n        a higher number represents an overall brighter picture on the axis. This allows to find the border which is very dark\r\n        (black). The border is found by taking the maximum value of this summed up array and the border starts where the\r\n        image is a 1/10th of this value.\r\n    \r\n        This relative approach is necessary because some of the images are very bright, others are very dark. So the border\r\n        and the pixel where they start differ a lot.\r\n        \"\"\"\r\n        im_array = np.sum(np.sum(image, axis=axis), axis=1)\r\n        threshold = im_array.max() / 10\r\n        indices = np.where(im_array > threshold)\r\n        return indices[0][0], indices[0][-1]\r\n\r\nAfter hat the cropping is easy:\r\n\r\n    # finding min max indices\r\n    min_x, max_x = find_border_dynamic_threshold(image, 0)\r\n    min_y, max_y = find_border_dynamic_threshold(image, 1)\r\n\r\n    # crop\r\n    image = image[min_y:max_y, min_x:max_x]",
      "votes": null
    },
    {
      "id": "96682",
      "postDate": "10/19/2015 17:12:56",
      "content": "<p>I'm a complete noob and I have been struggling to get this to work for a dissertation on applications of ML. Your solution is brilliant! \nCan anyone help me with a really stupid problem though? I cannot get SharedArray to install on Windows 7 using python 2.7.\nI have tried changing compilers, pip, conda, downloads everything i can think of?? Keep getting problems and I have been struggling for 2 weeks.\nAny help or advice would be hugely appreciated!!!</p>",
      "rawMarkdown": "I'm a complete noob and I have been struggling to get this to work for a dissertation on applications of ML. Your solution is brilliant! \r\nCan anyone help me with a really stupid problem though? I cannot get SharedArray to install on Windows 7 using python 2.7.\r\nI have tried changing compilers, pip, conda, downloads everything i can think of?? Keep getting problems and I have been struggling for 2 weeks.\r\nAny help or advice would be hugely appreciated!!!",
      "votes": null
    },
    {
      "id": "109670",
      "postDate": "02/29/2016 09:35:48",
      "content": "<p>@Mathis can you please tell me which lasagne.objectives should i use i am getting an import error which says cannot import name Objective. it is generating from nn.py line 7 </p>",
      "rawMarkdown": "Mathis can you please tell me which lasagne.objectives should i use i am getting an import error which says cannot import name Objective. it is generating from nn.py line 7",
      "votes": null
    },
    {
      "id": "109676",
      "postDate": "02/29/2016 10:31:29",
      "content": "<p>It should work if you install the lasagne commit in the requirements.txt file. If you want to make it work with a newer versions of lasagne this function might help: <a href=\"https://github.com/sveitser/kaggle_diabetic/blob/deterministic/nn.py#L55-L73\">https://github.com/sveitser/kaggle_diabetic/blob/deterministic/nn.py#L55-L73</a> .</p>",
      "rawMarkdown": "It should work if you install the lasagne commit in the requirements.txt file. If you want to make it work with a newer versions of lasagne this function might help: https://github.com/sveitser/kaggle_diabetic/blob/deterministic/nn.py#L55-L73 .",
      "votes": null
    },
    {
      "id": "109897",
      "postDate": "03/01/2016 13:02:02",
      "content": "<p>@Mathis I am running the deterministic branch now but i am getting an error which says TypeError: train_loop() got an unexpected keyword argument 'epochs' which is arising from 'train_nn.py' line 41 </p>",
      "rawMarkdown": "Mathis I am running the deterministic branch now but i am getting an error which says TypeError: train_loop() got an unexpected keyword argument 'epochs' which is arising from 'train_nn.py' line 41",
      "votes": null
    },
    {
      "id": "109899",
      "postDate": "03/01/2016 13:11:37",
      "content": "<p>Nolearn has undergone quite a few changes in the mean time. You could use the commit specified in the requirements.txt file (in the deterministic branch).</p>\n\n<p>If you want to use the current nolearn version you need to change the train_loop method to match the signature here <a href=\"https://github.com/dnouri/nolearn/blob/master/nolearn/lasagne/base.py#L529\">https://github.com/dnouri/nolearn/blob/master/nolearn/lasagne/base.py#L529</a> . It's also possible that you'd have to make other changes after that.</p>",
      "rawMarkdown": "Nolearn has undergone quite a few changes in the mean time. You could use the commit specified in the requirements.txt file (in the deterministic branch).\r\n\r\nIf you want to use the current nolearn version you need to change the train_loop method to match the signature here https://github.com/dnouri/nolearn/blob/master/nolearn/lasagne/base.py#L529 . It's also possible that you'd have to make other changes after that.",
      "votes": null
    },
    {
      "id": "110713",
      "postDate": "03/07/2016 19:35:18",
      "content": "<p>@Mathis I am stuck with the same problem as that of @shadaabkawnain. I am trying to clone the github link for Lasagna and nolearn but it says that the version is deprecated amd thus the cloning eventually fails. Can you please help me out with this because its continuously saying that 'no module named objective' </p>",
      "rawMarkdown": "Mathis I am stuck with the same problem as that of @shadaabkawnain. I am trying to clone the github link for Lasagna and nolearn but it says that the version is deprecated amd thus the cloning eventually fails. Can you please help me out with this because its continuously saying that 'no module named objective'",
      "votes": null
    },
    {
      "id": "126004",
      "postDate": "07/05/2016 13:09:00",
      "content": "<p>Hi Mathias,\nI have a problem running the train_nn.py.\nMy machine switches off (should be a memory issue) in the first epoch after running about 769 batches of size 32. (4*4 filter, 512*512 images)\nI am running on gpu (GTX980Ti, 6GB memory). </p>\n\n<p>My .theanorc file:\n[global]\nfloatX=float32\ndevice=gpu\n[lib]\ncnmem = 0.6 (It throws OUT OF MEMORY error when increased between &gt;0.6 and &lt;1)</p>\n\n<p>THEANO_FLAGS='cuda.root=/usr/local/cuda-7.0,device=gpu,floatX=float32,lib.cnmem=1,scan.allow_gc=True,scan.allow_output_prealloc=False,optimizer_excluding=more_mem,exception_verbosity=high'</p>\n\n<p>optimizer_including=cudnn\nCUDA_LAUNCH_BLOCKING=1</p>\n\n<p>Could you please suggest me a way to improve the memory handling or a different solution to this problem?  (I have tried reducing the training batch size between 16 and 48). Thanks in advance.</p>\n\n<p><strong>Resolved:</strong> Hardware issue</p>",
      "rawMarkdown": "Hi Mathias,\r\nI have a problem running the train_nn.py.\r\nMy machine switches off (should be a memory issue) in the first epoch after running about 769 batches of size 32. (4*4 filter, 512*512 images)\r\nI am running on gpu (GTX980Ti, 6GB memory). \r\n\r\nMy .theanorc file:\r\n[global]\r\nfloatX=float32\r\ndevice=gpu\r\n[lib]\r\ncnmem = 0.6 (It throws OUT OF MEMORY error when increased between >0.6 and <1)\r\n\r\nTHEANO_FLAGS='cuda.root=/usr/local/cuda-7.0,device=gpu,floatX=float32,lib.cnmem=1,scan.allow_gc=True,scan.allow_output_prealloc=False,optimizer_excluding=more_mem,exception_verbosity=high'\r\n\r\noptimizer_including=cudnn\r\nCUDA_LAUNCH_BLOCKING=1\r\n\r\nCould you please suggest me a way to improve the memory handling or a different solution to this problem?  (I have tried reducing the training batch size between 16 and 48). Thanks in advance.\r\n\r\n**Resolved:** Hardware issue",
      "votes": null
    },
    {
      "id": "224842",
      "postDate": "09/27/2017 19:08:56",
      "content": "<p>When I run the network B... python train_nn.py --cnf configs/c_128_4x4_32.py I got the error of Shape mismatch... Apply node that caused the error: Dot22(Flatten{2}.0, dense13.W),any idea?</p>",
      "rawMarkdown": "When I run the network B... python train_nn.py --cnf configs/c_128_4x4_32.py I got the error of Shape mismatch... Apply node that caused the error: Dot22(Flatten{2}.0, dense13.W),any idea?",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 88829,
      "author_name": "alishakiba",
      "author_url": "",
      "post_date": "08/07/2015 16:18:49",
      "content": "<p>Congratulations and Thank you.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 89054,
      "author_name": "kb0ard",
      "author_url": "",
      "post_date": "08/10/2015 19:46:16",
      "content": "<p>You guys have done incredible research, great work!!  I am curious and asking the top 5 winners this question, did you stick with one framework and/or library for the whole competition, such as the torch library, theano or Caffe, or did you find yourselves re-gearing earlier for a better suited framework and/or library for this particular challenge? </p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 89353,
      "author_name": "sveitser",
      "author_url": "",
      "post_date": "08/14/2015 10:24:51",
      "content": "<p>@Keaton. Thanks. For this competition we used nolearn and lasagne exclusively.</p>\n\n<p>The first conv nets I trained were for the plankton competition. I started using caffe but later changed to nolearn/lasagne because I found it much easier to do data augmentation (and almost anything else really) in python than in C++. I didn't get very far with the caffe python bindings at the time but I think they have undergone some changes recently. I'm still only starting to understand theano but most of the things I needed so far are available in lasagne or not much more than a google search away.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 89373,
      "author_name": "jfkingiii",
      "author_url": "",
      "post_date": "08/14/2015 18:01:40",
      "content": "<p>Mathis - Thanks, this is really helpful. What is the reason for blurring the images before resizing? I don't understand how this can help, in fact it seems like it would reduce performance.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 89386,
      "author_name": "sveitser",
      "author_url": "",
      "post_date": "08/14/2015 19:22:42",
      "content": "<p>@James King, We ran into some issues when trying to separate the foreground from the background because some images are very dark and sometimes the background is not totally black. The first thing that worked well enough was computing a threshold value from the maximum of a thin left and right strip of  a blurred copy of the image. The bounding box is used to crop the original image so we don't blur the image that we crop and resize.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 90141,
      "author_name": "jfkingiii",
      "author_url": "",
      "post_date": "08/23/2015 02:42:49",
      "content": "<p>I have run the code and gotten a leaderboard score of 0.836/0.827 (using only 20 iterations in the transform step instead of 50). Some notes which might help anyone who wants to do the same:</p>\n\n<ol>\n<li>The <code>make_kaggle_solution.sh</code> is great, I wish everyone created a start to finish script like this.</li>\n<li>There are references to directory <code>config</code>  in the script; it should be <code>configs</code>.</li>\n<li>In <code>requirements.txt</code>, I got a public key error when trying to access <code>benanne/Lasagne.git</code>, so I cloned <a href=\"https://github.com/Lasagne/Lasagne.git\">https://github.com/Lasagne/Lasagne.git</a> and then checked out the appropriate commit. You have to use the older commit, since <code>lasagne.objectives.Objective</code> has been deprecated.</li>\n<li>The shell variable BEST_VALID_WEIGHTS needs to include the path of the file returned by <code>ls -t | head -n 1</code>.</li>\n<li>To change the feature files used for blending, edit <code>blend.yml</code>.</li>\n<li>Wall time to fit this was about a week on my GTX 980; but there was a lot of idle time since a step may have finished when I was away from the computer and I didn't start the next one for several hours. If I had a second gpu I could have done done multiple steps at the same time.</li>\n<li>There are about 1600 lines of code. It's well written and fairly easy to understand.</li>\n</ol>",
      "votes": null,
      "replies": []
    },
    {
      "id": 90144,
      "author_name": "sveitser",
      "author_url": "",
      "post_date": "08/23/2015 04:15:23",
      "content": "<p>Thanks @James. I fixed the requirements.txt file to not use the git protocol and fixed the bugs with the kaggle solution script you mentioned.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 91054,
      "author_name": "alishakiba",
      "author_url": "",
      "post_date": "08/31/2015 16:35:07",
      "content": "<p>@Mathis. It is a very well-written code. However, I could not figure out how can I save the final trained model. In other words, how can we save a model, as a cPickle object for example, so we can load it for prediction on test images?</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 91853,
      "author_name": "sveitser",
      "author_url": "",
      "post_date": "09/08/2015 14:39:28",
      "content": "<p>Hi Ali. Sorry for the late reply. For the convolutional networks you can load the parameters/weights from the files saved inside the sub-directories inside the <em>weights</em> directory. For the blend network I never saved the weights because it just took a few minutes to train these networks. </p>\n\n<p>You should also be able to do so with the save save_params_to method though: <a href=\"https://github.com/dnouri/nolearn/blob/master/nolearn/lasagne/base.py#L616-L619\">https://github.com/dnouri/nolearn/blob/master/nolearn/lasagne/base.py#L616-L619</a></p>\n\n<p>There is currently no convenient way to use both the convolutional network and the blend network together as one model. You could however load them both into memory and do something like,</p>\n\n<ol>\n<li>use the transform method of the convolutional network to extract features for the image</li>\n<li>scale and reshape the features from 1. (blend both eyes)</li>\n<li>use the predict method of the blend network on output from 2.</li>\n</ol>\n\n<p>Then if desired combine the two networks inside a single class and the three steps above into a single method of that class.</p>\n\n<p>Hope this helps.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 93525,
      "author_name": "alishakiba",
      "author_url": "",
      "post_date": "09/27/2015 07:48:34",
      "content": "<p>Hi Mathis. Thanks for the help, yet, I could not build the network and run the model on a CPU. I have implemented the convolutional network my self using a subset of 1000 images, almost equal number of images from each class. However, I have several questions regarding your architecture:</p>\n\n<p>1- In your convolutional network, the output of your network is a 512 element vector, the maxout layer. As far as I know from the NN, we need a label for every input to the network. So, what is the label here?</p>\n\n<p>2- The number of inputs to your blend network is 8193. How did you come with this number?</p>\n\n<p>I have also contacted you by email to obtain the weight matrices for the full trained network. I think it would be good for me as any other one, to be able to see the whole code working. So, I would like to ask you again for the weight matrices.</p>\n\n<p>Thanks in advance.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 93579,
      "author_name": "shivang27",
      "author_url": "",
      "post_date": "09/28/2015 12:57:08",
      "content": "<p>Awesome work, Congratulations.\nI have doubt, How did you handle class imbalance in the data ?</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 95764,
      "author_name": "ktugan",
      "author_url": "",
      "post_date": "10/11/2015 16:09:36",
      "content": "<p>[quote=Mathis Antony;89386]</p>\n\n<p>@James King, We ran into some issues when trying to separate the foreground from the background because some images are very dark and sometimes the background is not totally black. The first thing that worked well enough was computing a threshold value from the maximum of a thin left and right strip of  a blurred copy of the image. The bounding box is used to crop the original image so we don't blur the image that we crop and resize.</p>\n\n<p>[/quote]</p>\n\n<p>Hi Mathis,</p>\n\n<p>awesome work. The blurring is an interesting idea but its easier to find a way to crop the pictures which even works on very dark pictures.</p>\n\n<ol>\n<li>sum up the picture on every axis except height/width, depending what axis you want to find the border on.\nThe result is a 1D array length of either height or width in pixels.</li>\n<li>Find the maximum value in this array and take 10% of it, this is the threshhold</li>\n<li>find the value where it first is bigger than the threshhold-value, this is your boundary</li>\n</ol>\n\n<p>It works because dark pixels have lower values. By summing up on all except 1 axis you can see where the color is and have a kind of 2d plot.</p>\n\n<p>Here my code for it:</p>\n\n<pre><code>def find_border_dynamic_threshold(image, axis):\n    &quot;&quot;&quot;\n    Sums up the axis to one dimension only. The resulting 1 dimensional array has the property that\n    a higher number represents an overall brighter picture on the axis. This allows to find the border which is very dark\n    (black). The border is found by taking the maximum value of this summed up array and the border starts where the\n    image is a 1/10th of this value.\n\n    This relative approach is necessary because some of the images are very bright, others are very dark. So the border\n    and the pixel where they start differ a lot.\n    &quot;&quot;&quot;\n    im_array = np.sum(np.sum(image, axis=axis), axis=1)\n    threshold = im_array.max() / 10\n    indices = np.where(im_array &gt; threshold)\n    return indices[0][0], indices[0][-1]\n</code></pre>\n\n<p>After hat the cropping is easy:</p>\n\n<pre><code># finding min max indices\nmin_x, max_x = find_border_dynamic_threshold(image, 0)\nmin_y, max_y = find_border_dynamic_threshold(image, 1)\n\n# crop\nimage = image[min_y:max_y, min_x:max_x]\n</code></pre>",
      "votes": null,
      "replies": []
    },
    {
      "id": 96682,
      "author_name": "mikethebike",
      "author_url": "",
      "post_date": "10/19/2015 17:12:56",
      "content": "<p>I'm a complete noob and I have been struggling to get this to work for a dissertation on applications of ML. Your solution is brilliant! \nCan anyone help me with a really stupid problem though? I cannot get SharedArray to install on Windows 7 using python 2.7.\nI have tried changing compilers, pip, conda, downloads everything i can think of?? Keep getting problems and I have been struggling for 2 weeks.\nAny help or advice would be hugely appreciated!!!</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 109670,
      "author_name": "kawnain04",
      "author_url": "",
      "post_date": "02/29/2016 09:35:48",
      "content": "<p>@Mathis can you please tell me which lasagne.objectives should i use i am getting an import error which says cannot import name Objective. it is generating from nn.py line 7 </p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 109676,
      "author_name": "sveitser",
      "author_url": "",
      "post_date": "02/29/2016 10:31:29",
      "content": "<p>It should work if you install the lasagne commit in the requirements.txt file. If you want to make it work with a newer versions of lasagne this function might help: <a href=\"https://github.com/sveitser/kaggle_diabetic/blob/deterministic/nn.py#L55-L73\">https://github.com/sveitser/kaggle_diabetic/blob/deterministic/nn.py#L55-L73</a> .</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 109897,
      "author_name": "kawnain04",
      "author_url": "",
      "post_date": "03/01/2016 13:02:02",
      "content": "<p>@Mathis I am running the deterministic branch now but i am getting an error which says TypeError: train_loop() got an unexpected keyword argument 'epochs' which is arising from 'train_nn.py' line 41 </p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 109899,
      "author_name": "sveitser",
      "author_url": "",
      "post_date": "03/01/2016 13:11:37",
      "content": "<p>Nolearn has undergone quite a few changes in the mean time. You could use the commit specified in the requirements.txt file (in the deterministic branch).</p>\n\n<p>If you want to use the current nolearn version you need to change the train_loop method to match the signature here <a href=\"https://github.com/dnouri/nolearn/blob/master/nolearn/lasagne/base.py#L529\">https://github.com/dnouri/nolearn/blob/master/nolearn/lasagne/base.py#L529</a> . It's also possible that you'd have to make other changes after that.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 110713,
      "author_name": "zsif09",
      "author_url": "",
      "post_date": "03/07/2016 19:35:18",
      "content": "<p>@Mathis I am stuck with the same problem as that of @shadaabkawnain. I am trying to clone the github link for Lasagna and nolearn but it says that the version is deprecated amd thus the cloning eventually fails. Can you please help me out with this because its continuously saying that 'no module named objective' </p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 126004,
      "author_name": "rmanuuu",
      "author_url": "",
      "post_date": "07/05/2016 13:09:00",
      "content": "<p>Hi Mathias,\nI have a problem running the train_nn.py.\nMy machine switches off (should be a memory issue) in the first epoch after running about 769 batches of size 32. (4*4 filter, 512*512 images)\nI am running on gpu (GTX980Ti, 6GB memory). </p>\n\n<p>My .theanorc file:\n[global]\nfloatX=float32\ndevice=gpu\n[lib]\ncnmem = 0.6 (It throws OUT OF MEMORY error when increased between &gt;0.6 and &lt;1)</p>\n\n<p>THEANO_FLAGS='cuda.root=/usr/local/cuda-7.0,device=gpu,floatX=float32,lib.cnmem=1,scan.allow_gc=True,scan.allow_output_prealloc=False,optimizer_excluding=more_mem,exception_verbosity=high'</p>\n\n<p>optimizer_including=cudnn\nCUDA_LAUNCH_BLOCKING=1</p>\n\n<p>Could you please suggest me a way to improve the memory handling or a different solution to this problem?  (I have tried reducing the training batch size between 16 and 48). Thanks in advance.</p>\n\n<p><strong>Resolved:</strong> Hardware issue</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 224842,
      "author_name": "zelpip",
      "author_url": "",
      "post_date": "09/27/2017 19:08:56",
      "content": "<p>When I run the network B... python train_nn.py --cnf configs/c_128_4x4_32.py I got the error of Shape mismatch... Apply node that caused the error: Dot22(Flatten{2}.0, dense13.W),any idea?</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "88693": "Report and code are now available at https://github.com/sveitser/kaggle_diabetic and the report is also attached below.\r\n\r\nThanks again to teammate Stephan, Kaggle, the California Healthcare Foundation and EyePACS as well as everyone who competed!",
    "88829": "Congratulations and Thank you.",
    "89054": "You guys have done incredible research, great work!!  I am curious and asking the top 5 winners this question, did you stick with one framework and/or library for the whole competition, such as the torch library, theano or Caffe, or did you find yourselves re-gearing earlier for a better suited framework and/or library for this particular challenge?",
    "89353": "Keaton. Thanks. For this competition we used nolearn and lasagne exclusively.\r\n\r\nThe first conv nets I trained were for the plankton competition. I started using caffe but later changed to nolearn/lasagne because I found it much easier to do data augmentation (and almost anything else really) in python than in C++. I didn't get very far with the caffe python bindings at the time but I think they have undergone some changes recently. I'm still only starting to understand theano but most of the things I needed so far are available in lasagne or not much more than a google search away.",
    "89373": "Mathis - Thanks, this is really helpful. What is the reason for blurring the images before resizing? I don't understand how this can help, in fact it seems like it would reduce performance.",
    "89386": "James King, We ran into some issues when trying to separate the foreground from the background because some images are very dark and sometimes the background is not totally black. The first thing that worked well enough was computing a threshold value from the maximum of a thin left and right strip of  a blurred copy of the image. The bounding box is used to crop the original image so we don't blur the image that we crop and resize.",
    "90141": "I have run the code and gotten a leaderboard score of 0.836/0.827 (using only 20 iterations in the transform step instead of 50). Some notes which might help anyone who wants to do the same:\r\n\r\n1. The `make_kaggle_solution.sh` is great, I wish everyone created a start to finish script like this.\r\n2. There are references to directory `config`  in the script; it should be `configs`.\r\n3. In `requirements.txt`, I got a public key error when trying to access `benanne/Lasagne.git `, so I cloned https://github.com/Lasagne/Lasagne.git and then checked out the appropriate commit. You have to use the older commit, since `lasagne.objectives.Objective` has been deprecated.\r\n4. The shell variable BEST_VALID_WEIGHTS needs to include the path of the file returned by `ls -t | head -n 1`.\r\n4. To change the feature files used for blending, edit `blend.yml`.\r\n5. Wall time to fit this was about a week on my GTX 980; but there was a lot of idle time since a step may have finished when I was away from the computer and I didn't start the next one for several hours. If I had a second gpu I could have done done multiple steps at the same time.\r\n6. There are about 1600 lines of code. It's well written and fairly easy to understand.",
    "90144": "Thanks @James. I fixed the requirements.txt file to not use the git protocol and fixed the bugs with the kaggle solution script you mentioned.",
    "91054": "Mathis. It is a very well-written code. However, I could not figure out how can I save the final trained model. In other words, how can we save a model, as a cPickle object for example, so we can load it for prediction on test images?",
    "91853": "Hi Ali. Sorry for the late reply. For the convolutional networks you can load the parameters/weights from the files saved inside the sub-directories inside the *weights* directory. For the blend network I never saved the weights because it just took a few minutes to train these networks. \r\n\r\nYou should also be able to do so with the save save_params_to method though: https://github.com/dnouri/nolearn/blob/master/nolearn/lasagne/base.py#L616-L619\r\n\r\nThere is currently no convenient way to use both the convolutional network and the blend network together as one model. You could however load them both into memory and do something like,\r\n\r\n1. use the transform method of the convolutional network to extract features for the image\r\n2. scale and reshape the features from 1. (blend both eyes)\r\n3. use the predict method of the blend network on output from 2.\r\n\r\nThen if desired combine the two networks inside a single class and the three steps above into a single method of that class.\r\n\r\nHope this helps.",
    "93525": "Hi Mathis. Thanks for the help, yet, I could not build the network and run the model on a CPU. I have implemented the convolutional network my self using a subset of 1000 images, almost equal number of images from each class. However, I have several questions regarding your architecture:\r\n\r\n1- In your convolutional network, the output of your network is a 512 element vector, the maxout layer. As far as I know from the NN, we need a label for every input to the network. So, what is the label here?\r\n\r\n2- The number of inputs to your blend network is 8193. How did you come with this number?\r\n\r\nI have also contacted you by email to obtain the weight matrices for the full trained network. I think it would be good for me as any other one, to be able to see the whole code working. So, I would like to ask you again for the weight matrices.\r\n\r\nThanks in advance.",
    "93579": "Awesome work, Congratulations.\r\nI have doubt, How did you handle class imbalance in the data ?",
    "95764": "[quote=Mathis Antony;89386]\r\n\r\n@James King, We ran into some issues when trying to separate the foreground from the background because some images are very dark and sometimes the background is not totally black. The first thing that worked well enough was computing a threshold value from the maximum of a thin left and right strip of  a blurred copy of the image. The bounding box is used to crop the original image so we don't blur the image that we crop and resize.\r\n\r\n[/quote]\r\n\r\nHi Mathis,\r\n\r\nawesome work. The blurring is an interesting idea but its easier to find a way to crop the pictures which even works on very dark pictures.\r\n\r\n1. sum up the picture on every axis except height/width, depending what axis you want to find the border on.\r\nThe result is a 1D array length of either height or width in pixels.\r\n2. Find the maximum value in this array and take 10% of it, this is the threshhold\r\n3. find the value where it first is bigger than the threshhold-value, this is your boundary\r\n\r\nIt works because dark pixels have lower values. By summing up on all except 1 axis you can see where the color is and have a kind of 2d plot.\r\n\r\n\r\nHere my code for it:\r\n\r\n    def find_border_dynamic_threshold(image, axis):\r\n        \"\"\"\r\n        Sums up the axis to one dimension only. The resulting 1 dimensional array has the property that\r\n        a higher number represents an overall brighter picture on the axis. This allows to find the border which is very dark\r\n        (black). The border is found by taking the maximum value of this summed up array and the border starts where the\r\n        image is a 1/10th of this value.\r\n    \r\n        This relative approach is necessary because some of the images are very bright, others are very dark. So the border\r\n        and the pixel where they start differ a lot.\r\n        \"\"\"\r\n        im_array = np.sum(np.sum(image, axis=axis), axis=1)\r\n        threshold = im_array.max() / 10\r\n        indices = np.where(im_array > threshold)\r\n        return indices[0][0], indices[0][-1]\r\n\r\nAfter hat the cropping is easy:\r\n\r\n    # finding min max indices\r\n    min_x, max_x = find_border_dynamic_threshold(image, 0)\r\n    min_y, max_y = find_border_dynamic_threshold(image, 1)\r\n\r\n    # crop\r\n    image = image[min_y:max_y, min_x:max_x]",
    "96682": "I'm a complete noob and I have been struggling to get this to work for a dissertation on applications of ML. Your solution is brilliant! \r\nCan anyone help me with a really stupid problem though? I cannot get SharedArray to install on Windows 7 using python 2.7.\r\nI have tried changing compilers, pip, conda, downloads everything i can think of?? Keep getting problems and I have been struggling for 2 weeks.\r\nAny help or advice would be hugely appreciated!!!",
    "109670": "Mathis can you please tell me which lasagne.objectives should i use i am getting an import error which says cannot import name Objective. it is generating from nn.py line 7",
    "109676": "It should work if you install the lasagne commit in the requirements.txt file. If you want to make it work with a newer versions of lasagne this function might help: https://github.com/sveitser/kaggle_diabetic/blob/deterministic/nn.py#L55-L73 .",
    "109897": "Mathis I am running the deterministic branch now but i am getting an error which says TypeError: train_loop() got an unexpected keyword argument 'epochs' which is arising from 'train_nn.py' line 41",
    "109899": "Nolearn has undergone quite a few changes in the mean time. You could use the commit specified in the requirements.txt file (in the deterministic branch).\r\n\r\nIf you want to use the current nolearn version you need to change the train_loop method to match the signature here https://github.com/dnouri/nolearn/blob/master/nolearn/lasagne/base.py#L529 . It's also possible that you'd have to make other changes after that.",
    "110713": "Mathis I am stuck with the same problem as that of @shadaabkawnain. I am trying to clone the github link for Lasagna and nolearn but it says that the version is deprecated amd thus the cloning eventually fails. Can you please help me out with this because its continuously saying that 'no module named objective'",
    "126004": "Hi Mathias,\r\nI have a problem running the train_nn.py.\r\nMy machine switches off (should be a memory issue) in the first epoch after running about 769 batches of size 32. (4*4 filter, 512*512 images)\r\nI am running on gpu (GTX980Ti, 6GB memory). \r\n\r\nMy .theanorc file:\r\n[global]\r\nfloatX=float32\r\ndevice=gpu\r\n[lib]\r\ncnmem = 0.6 (It throws OUT OF MEMORY error when increased between >0.6 and <1)\r\n\r\nTHEANO_FLAGS='cuda.root=/usr/local/cuda-7.0,device=gpu,floatX=float32,lib.cnmem=1,scan.allow_gc=True,scan.allow_output_prealloc=False,optimizer_excluding=more_mem,exception_verbosity=high'\r\n\r\noptimizer_including=cudnn\r\nCUDA_LAUNCH_BLOCKING=1\r\n\r\nCould you please suggest me a way to improve the memory handling or a different solution to this problem?  (I have tried reducing the training batch size between 16 and 48). Thanks in advance.\r\n\r\n**Resolved:** Hardware issue",
    "224842": "When I run the network B... python train_nn.py --cnf configs/c_128_4x4_32.py I got the error of Shape mismatch... Apply node that caused the error: Dot22(Flatten{2}.0, dense13.W),any idea?"
  },
  "source": "meta"
}