{
  "id": 94183,
  "title": "Stuck at 0.002 somehow",
  "url": "/competitions/imet-2019-fgvc6/discussion/94183",
  "author_name": "",
  "post_date": "2019-06-03T01:58:15.939854300Z",
  "votes": 3,
  "comment_count": 26,
  "views": 0,
  "content": "<p>Hello everyone!</p>\n\n<p>I'm still relatively new to Kaggle, so I'm still learning a lot. I'm getting on this competition pretty late, but I've been working on it for the past 2 weeks roughly. I've been stuck since then on a super low score, and I just can't figure out what the problem is. Here is <a href=\"https://www.kaggle.com/maxlenormand/act-softmax-incresnetv2\">my Kernel </a> which is based upon several other kernels, but mostly <a href=\"https://www.kaggle.com/ateplyuk/keras-starter\">the Keras-Starter Kernel</a> which is basically what I was going for anyways.\nIn a nutshell, I'm using an InceptionResNetV2, with a last layer with 1103 nodes with a softmax activation.\nI think something is wrong with the way my model is learning as from what I display, the validation F2 score is already higher than the training one on the first epochs, which doesn't make much sense. The training F2 score is getting better as the epoch go on, and the training loss goes down, which seems correct. However the validation score and loss just don't seem to make sense, and I can't figure out why; hence after muliple days of searching, turning to the forum. If anybody would be willing to take a look at let me know what they think, I'd really appreciate it!</p>\n\n<p>I have some ideas I would have wanted to try out for this competition, but if I can't even get a simple model working, then it's not even worth trying those! My timing wasn't great on this one.\nThanks for the help!</p>",
  "messages": [
    {
      "id": "541763",
      "postDate": "06/03/2019 01:58:15",
      "content": "<p>Hello everyone!</p>\n\n<p>I'm still relatively new to Kaggle, so I'm still learning a lot. I'm getting on this competition pretty late, but I've been working on it for the past 2 weeks roughly. I've been stuck since then on a super low score, and I just can't figure out what the problem is. Here is <a href=\"https://www.kaggle.com/maxlenormand/act-softmax-incresnetv2\">my Kernel </a> which is based upon several other kernels, but mostly <a href=\"https://www.kaggle.com/ateplyuk/keras-starter\">the Keras-Starter Kernel</a> which is basically what I was going for anyways.\nIn a nutshell, I'm using an InceptionResNetV2, with a last layer with 1103 nodes with a softmax activation.\nI think something is wrong with the way my model is learning as from what I display, the validation F2 score is already higher than the training one on the first epochs, which doesn't make much sense. The training F2 score is getting better as the epoch go on, and the training loss goes down, which seems correct. However the validation score and loss just don't seem to make sense, and I can't figure out why; hence after muliple days of searching, turning to the forum. If anybody would be willing to take a look at let me know what they think, I'd really appreciate it!</p>\n\n<p>I have some ideas I would have wanted to try out for this competition, but if I can't even get a simple model working, then it's not even worth trying those! My timing wasn't great on this one.\nThanks for the help!</p>",
      "rawMarkdown": "Hello everyone!\n\nI'm still relatively new to Kaggle, so I'm still learning a lot. I'm getting on this competition pretty late, but I've been working on it for the past 2 weeks roughly. I've been stuck since then on a super low score, and I just can't figure out what the problem is. Here is [my Kernel ](https://www.kaggle.com/maxlenormand/act-softmax-incresnetv2) which is based upon several other kernels, but mostly [the Keras-Starter Kernel](https://www.kaggle.com/ateplyuk/keras-starter) which is basically what I was going for anyways.\nIn a nutshell, I'm using an InceptionResNetV2, with a last layer with 1103 nodes with a softmax activation.\nI think something is wrong with the way my model is learning as from what I display, the validation F2 score is already higher than the training one on the first epochs, which doesn't make much sense. The training F2 score is getting better as the epoch go on, and the training loss goes down, which seems correct. However the validation score and loss just don't seem to make sense, and I can't figure out why; hence after muliple days of searching, turning to the forum. If anybody would be willing to take a look at let me know what they think, I'd really appreciate it!\n\nI have some ideas I would have wanted to try out for this competition, but if I can't even get a simple model working, then it's not even worth trying those! My timing wasn't great on this one.\nThanks for the help!",
      "votes": null
    },
    {
      "id": "541766",
      "postDate": "06/03/2019 02:09:14",
      "content": "<p>Your early-stopping stops the model very early so it only trains for 4 epochs. It's probably best to get rid of the early stopping and train as long as you can</p>",
      "rawMarkdown": "Your early-stopping stops the model very early so it only trains for 4 epochs. It's probably best to get rid of the early stopping and train as long as you can",
      "votes": null
    },
    {
      "id": "541805",
      "postDate": "06/03/2019 03:43:07",
      "content": "<p>Yep, my early stopping isn't working very well, I agree.\nHowever I did train it over 15 epoch, and the result was no better, the score was still around 0.001 ~ 0.004. So the problem doesn't (only) come from that. And still, it doesn't explain why my validation loss and F2 score are higher than my train.</p>",
      "rawMarkdown": "Yep, my early stopping isn't working very well, I agree.\nHowever I did train it over 15 epoch, and the result was no better, the score was still around 0.001 ~ 0.004. So the problem doesn't (only) come from that. And still, it doesn't explain why my validation loss and F2 score are higher than my train.",
      "votes": null
    },
    {
      "id": "541824",
      "postDate": "06/03/2019 04:35:21",
      "content": "<p>Have you tried increasing your learning rate? Maybe 1e-2?</p>",
      "rawMarkdown": "Have you tried increasing your learning rate? Maybe 1e-2?",
      "votes": null
    },
    {
      "id": "541828",
      "postDate": "06/03/2019 04:41:59",
      "content": "<p>It's also weird that your validation f2 is higher than your training, but the loss is also higher.</p>",
      "rawMarkdown": "It's also weird that your validation f2 is higher than your training, but the loss is also higher.",
      "votes": null
    },
    {
      "id": "541840",
      "postDate": "06/03/2019 05:13:41",
      "content": "<p>Are you using pretrained imagenet weights or not?</p>\n\n<p>I also built one Siamese Net solution which was not properly learning without pretrained imagenet weights</p>",
      "rawMarkdown": "Are you using pretrained imagenet weights or not?\n\nI also built one Siamese Net solution which was not properly learning without pretrained imagenet weights",
      "votes": null
    },
    {
      "id": "541842",
      "postDate": "06/03/2019 05:16:13",
      "content": "<p>I did try at 0.001 and 0.0001, but not at 0.01. I could try it just to see, even though I don't think that's the core of the problem.\nAnd yes, the fact that the validation metrics are higher is what concerns me the most, and I can't figure what's wrong with it.</p>",
      "rawMarkdown": "I did try at 0.001 and 0.0001, but not at 0.01. I could try it just to see, even though I don't think that's the core of the problem.\nAnd yes, the fact that the validation metrics are higher is what concerns me the most, and I can't figure what's wrong with it.",
      "votes": null
    },
    {
      "id": "541845",
      "postDate": "06/03/2019 05:18:05",
      "content": "<p>Yep, using imagenet weights. But maybe not properly.\nI'll have another look!</p>",
      "rawMarkdown": "Yep, using imagenet weights. But maybe not properly.\nI'll have another look!",
      "votes": null
    },
    {
      "id": "541846",
      "postDate": "06/03/2019 05:18:27",
      "content": "<p>If you are not using imagenet weights, that could explain a lot of problems. Because training from scratch would take a really long time. See if there is any problems with that and let us know.</p>",
      "rawMarkdown": "If you are not using imagenet weights, that could explain a lot of problems. Because training from scratch would take a really long time. See if there is any problems with that and let us know.",
      "votes": null
    },
    {
      "id": "541847",
      "postDate": "06/03/2019 05:22:47",
      "content": "<p>I know that, but I am using the imagenet weights :-)</p>",
      "rawMarkdown": "I know that, but I am using the imagenet weights :-)",
      "votes": null
    },
    {
      "id": "541848",
      "postDate": "06/03/2019 05:27:19",
      "content": "<p>Are you generating labels for your preds properly? there could be a bug there</p>",
      "rawMarkdown": "Are you generating labels for your preds properly? there could be a bug there",
      "votes": null
    },
    {
      "id": "541858",
      "postDate": "06/03/2019 06:02:49",
      "content": "<p>I think that might be where the problem is coming from yeah\nBecause I tweaked my model, and the result looks much better already. (you can see it <a href=\"https://www.kaggle.com/maxlenormand/change-model-act-softmax-incresnetv2\">in this Kernel</a> or in the image attached)</p>",
      "rawMarkdown": "I think that might be where the problem is coming from yeah\nBecause I tweaked my model, and the result looks much better already. (you can see it [in this Kernel](https://www.kaggle.com/maxlenormand/change-model-act-softmax-incresnetv2) or in the image attached)",
      "votes": null
    },
    {
      "id": "541868",
      "postDate": "06/03/2019 06:16:21",
      "content": "<p>Indeed this looks better. BTW the kernel you linked is private.</p>",
      "rawMarkdown": "Indeed this looks better. BTW the kernel you linked is private.",
      "votes": null
    },
    {
      "id": "541882",
      "postDate": "06/03/2019 06:40:37",
      "content": "<p>My bad!\nAll public now!</p>",
      "rawMarkdown": "My bad!\nAll public now!",
      "votes": null
    },
    {
      "id": "541938",
      "postDate": "06/03/2019 08:09:33",
      "content": "<p>Just clone a working kernel. Btw, 4 epochs are not enough for training anyway. And you don't need InceptionResNetV2 for the start, take ResNet50 and make sure your training works as expected. </p>\n\n<p>FYI, InceptionResNetV2 achieves 0.605 on validation for me.</p>",
      "rawMarkdown": "Just clone a working kernel. Btw, 4 epochs are not enough for training anyway. And you don't need InceptionResNetV2 for the start, take ResNet50 and make sure your training works as expected. \n\nFYI, InceptionResNetV2 achieves 0.605 on validation for me.",
      "votes": null
    },
    {
      "id": "542138",
      "postDate": "06/03/2019 13:52:50",
      "content": "<p>Sure I could do that, but I don't want to just clone a kernel. I want to be able to make on from scratch and understand it along the way. I've still pretty new to all of this, so I want to take it as a learning experience.\nAnd I just took InceptionResNet because that was one of the ones I used in a previous competition, so I just copied the code from there.\nAnd yeah, 4 epochs are not enough indeed, but at least they can start showing a trend. For debugging quickly I thought it might be a could way to go. Might not be though.</p>",
      "rawMarkdown": "Sure I could do that, but I don't want to just clone a kernel. I want to be able to make on from scratch and understand it along the way. I've still pretty new to all of this, so I want to take it as a learning experience.\nAnd I just took InceptionResNet because that was one of the ones I used in a previous competition, so I just copied the code from there.\nAnd yeah, 4 epochs are not enough indeed, but at least they can start showing a trend. For debugging quickly I thought it might be a could way to go. Might not be though.",
      "votes": null
    },
    {
      "id": "542174",
      "postDate": "06/03/2019 14:38:01",
      "content": "<p>I see 2 different points: </p>\n\n<p>1) You are not giving enough iterations to your model to learn. You probably need more than 4 epochs especially for softmax - in my experience with this dataset at least. Increase the patience of your early stopping should improve this.</p>\n\n<p>2) Even though your validation score is low, there is an important gap (&gt; x10) between your validation score and your test score, the latter being very close to 0 anyway. It probably means that you are not submitting your results properly. I suspect that you have the same issue I went through caused by a bad order of your labels in the final dataframe you submit. </p>\n\n<p>In my case, it was caused by a mismatch between the alphabetic order and the numerical order: the numerical labels where converted to string and thus ordered  by alphabetic order (\"0\", \"1\", \"10\", \"100\", etc.). As a consequence, I was submitting the results of the 10th label for the 3nd etc. </p>\n\n<p>Look at the train_generator.class_indices to see the mapping between labels and their order and check that it's coherent. Another quick check is to look at your most frequently predicted class. It should be 813 (\"tag::men\"). Having a quick look at your submission, that does not seem to be the case here. </p>",
      "rawMarkdown": "I see 2 different points: \n\n1) You are not giving enough iterations to your model to learn. You probably need more than 4 epochs especially for softmax - in my experience with this dataset at least. Increase the patience of your early stopping should improve this.\n\n\n2) Even though your validation score is low, there is an important gap (&gt; x10) between your validation score and your test score, the latter being very close to 0 anyway. It probably means that you are not submitting your results properly. I suspect that you have the same issue I went through caused by a bad order of your labels in the final dataframe you submit. \n\nIn my case, it was caused by a mismatch between the alphabetic order and the numerical order: the numerical labels where converted to string and thus ordered  by alphabetic order (\"0\", \"1\", \"10\", \"100\", etc.). As a consequence, I was submitting the results of the 10th label for the 3nd etc. \n\nLook at the train\\_generator.class\\_indices to see the mapping between labels and their order and check that it's coherent. Another quick check is to look at your most frequently predicted class. It should be 813 (\"tag::men\"). Having a quick look at your submission, that does not seem to be the case here.",
      "votes": null
    },
    {
      "id": "542245",
      "postDate": "06/03/2019 15:56:23",
      "content": "<p>I had some similar issues and started the same way on this. This is my first image classification competition, just trying to learn how to do it all. I started by copying parts of a kernel using InceptionResNetV2. Now I have been using ResNet50 to just get started, but quickly running out of time since I only started on this 2 weeks ago and my first image learning one.</p>\n\n<p>I had some issues initially to get the labels correct, as also mentioned by <a href=\"/kiurtis\">@kiurtis</a>. I ended up one-hot encoding the target variables, and checking closely that they are actually correctly encoded (printing out specific indices in the one-hot encoded arrays to see they match the numbers from the labels dataframe). I only had a quick look at your kernel but you don't seem to be one-hot encoding it. Not sure how much difference it makes, as I said, just trying to learn and see myself. And limited time to experiment.</p>\n\n<p>Also, maybe use the inception_resnet_v2.preprocess_input() function on your images. It should give decent results anyway, but this should ensure at least the input has a similar distribution (I guess that is the correct term..). </p>",
      "rawMarkdown": "I had some similar issues and started the same way on this. This is my first image classification competition, just trying to learn how to do it all. I started by copying parts of a kernel using InceptionResNetV2. Now I have been using ResNet50 to just get started, but quickly running out of time since I only started on this 2 weeks ago and my first image learning one.\n\nI had some issues initially to get the labels correct, as also mentioned by @kiurtis. I ended up one-hot encoding the target variables, and checking closely that they are actually correctly encoded (printing out specific indices in the one-hot encoded arrays to see they match the numbers from the labels dataframe). I only had a quick look at your kernel but you don't seem to be one-hot encoding it. Not sure how much difference it makes, as I said, just trying to learn and see myself. And limited time to experiment.\n\nAlso, maybe use the inception_resnet_v2.preprocess_input() function on your images. It should give decent results anyway, but this should ensure at least the input has a similar distribution (I guess that is the correct term..).",
      "votes": null
    },
    {
      "id": "542355",
      "postDate": "06/03/2019 18:36:01",
      "content": "<p>I'm not saying copy-pasting code from kernels is good. But you are given many working examples. It's up to you to find a difference between your code and any of the working implementations. A good ML engineer must be good at coding.</p>\n\n<p>I see your point though. I made my solution from scratch.</p>\n\n<p>You must have some serious error somewhere in your pipeline, like wrong image normalization. Another thing you could try is to take the code from any image classification tutorial and make it use competition data.</p>\n\n<p>Problem is, if you change a lot of things at once and then click Run, it wouldn't work. Try doing small incremental changes while keeping an eye on validation metrics.</p>",
      "rawMarkdown": "I'm not saying copy-pasting code from kernels is good. But you are given many working examples. It's up to you to find a difference between your code and any of the working implementations. A good ML engineer must be good at coding.\n\nI see your point though. I made my solution from scratch.\n\nYou must have some serious error somewhere in your pipeline, like wrong image normalization. Another thing you could try is to take the code from any image classification tutorial and make it use competition data.\n\nProblem is, if you change a lot of things at once and then click Run, it wouldn't work. Try doing small incremental changes while keeping an eye on validation metrics.",
      "votes": null
    },
    {
      "id": "542428",
      "postDate": "06/03/2019 22:49:41",
      "content": "<p>Regarding this: \"It's also weird that your validation f2 is higher than your training, but the loss is also higher.\"\nThis is absolutely normal when augmentations are in place. Especially with mixup.</p>",
      "rawMarkdown": "Regarding this: \"It's also weird that your validation f2 is higher than your training, but the loss is also higher.\"\nThis is absolutely normal when augmentations are in place. Especially with mixup.",
      "votes": null
    },
    {
      "id": "542630",
      "postDate": "06/04/2019 02:28:35",
      "content": "<p>Well, I saw one-hot encoding was one option out of it, but I did want to try to do it without\nI saw that it could work without doing it like that, so I wanted to try.\nI think I got onboard this competition a bit too late to have time to solve any of these issues. But thanks for the ideas, I'll have a look at those!</p>",
      "rawMarkdown": "Well, I saw one-hot encoding was one option out of it, but I did want to try to do it without\nI saw that it could work without doing it like that, so I wanted to try.\nI think I got onboard this competition a bit too late to have time to solve any of these issues. But thanks for the ideas, I'll have a look at those!",
      "votes": null
    },
    {
      "id": "542636",
      "postDate": "06/04/2019 02:30:30",
      "content": "<p>Totally agree, and that's what I'm doing, tweaking one thing at a time (Kaggle allowing to run 4 kernels at once does help).\nI think my issue here is a lack of understanding at some point of the entire pipeline. I do understand most of it, but you only need one error for it not to work.</p>",
      "rawMarkdown": "Totally agree, and that's what I'm doing, tweaking one thing at a time (Kaggle allowing to run 4 kernels at once does help).\nI think my issue here is a lack of understanding at some point of the entire pipeline. I do understand most of it, but you only need one error for it not to work.",
      "votes": null
    },
    {
      "id": "542637",
      "postDate": "06/04/2019 02:30:50",
      "content": "<p>Okay, thanks! Good to know that!</p>",
      "rawMarkdown": "Okay, thanks! Good to know that!",
      "votes": null
    },
    {
      "id": "542718",
      "postDate": "06/04/2019 03:59:39",
      "content": "<p>Hi <a href=\"/maxlenormand\">@maxlenormand</a> , </p>\n\n<p>I think one issue could be  this step: datagen=ImageDataGenerator(rescale=1./255.,validation_split=0.2)</p>\n\n<p>Since we use imageNet weights we need to <em>apply same normalization to the images as ImageNet did</em>. \nIt may converge without this normalization but it will take a much longer time. </p>\n\n<p>for normalization you need to find mean value from ImageNet and subtract it from training and testing. \nI will try and see if i can fork your kernel and make this change and test my theory :-) </p>\n\n<p>Happy Debugging ! (which in a way is one of the most fun  part of ML ) </p>",
      "rawMarkdown": "Hi @maxlenormand , \n\nI think one issue could be  this step: datagen=ImageDataGenerator(rescale=1./255.,validation_split=0.2)\n\nSince we use imageNet weights we need to *apply same normalization to the images as ImageNet did*. \nIt may converge without this normalization but it will take a much longer time. \n\nfor normalization you need to find mean value from ImageNet and subtract it from training and testing. \nI will try and see if i can fork your kernel and make this change and test my theory :-) \n\nHappy Debugging ! (which in a way is one of the most fun  part of ML )",
      "votes": null
    },
    {
      "id": "542719",
      "postDate": "06/04/2019 04:00:48",
      "content": "<p>also just saw averagemn's comment. i am suggesting the same as him. \"Also, maybe use the inceptionresnetv2.preprocess_input() function on your images\"</p>",
      "rawMarkdown": "also just saw averagemn's comment. i am suggesting the same as him. \"Also, maybe use the inceptionresnetv2.preprocess_input() function on your images\"",
      "votes": null
    },
    {
      "id": "542874",
      "postDate": "06/04/2019 06:47:52",
      "content": "<p>Just would like to thanks <a href=\"/kiurtis\">@kiurtis</a> which has helped me in the background find a fix, it indeed was the predicitons that was not working properly\nI jumped up to 0.472 now thanks to that\nThanks to everyone for the help, really appreciate it! :-)</p>",
      "rawMarkdown": "Just would like to thanks @kiurtis which has helped me in the background find a fix, it indeed was the predicitons that was not working properly\nI jumped up to 0.472 now thanks to that\nThanks to everyone for the help, really appreciate it! :-)",
      "votes": null
    },
    {
      "id": "542876",
      "postDate": "06/04/2019 06:49:21",
      "content": "<p>Interesting, I didn't know about that. I'm not sure how to apply the same normalization as Imagenet, so I'd definitely be interested in seeing that, even after the competition is over!</p>",
      "rawMarkdown": "Interesting, I didn't know about that. I'm not sure how to apply the same normalization as Imagenet, so I'd definitely be interested in seeing that, even after the competition is over!",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 541766,
      "author_name": "tanlikesmath",
      "author_url": "",
      "post_date": "06/03/2019 02:09:14",
      "content": "<p>Your early-stopping stops the model very early so it only trains for 4 epochs. It's probably best to get rid of the early stopping and train as long as you can</p>",
      "votes": null,
      "replies": [
        {
          "id": 541805,
          "author_name": "maxlenormand",
          "author_url": "",
          "post_date": "06/03/2019 03:43:07",
          "content": "<p>Yep, my early stopping isn't working very well, I agree.\nHowever I did train it over 15 epoch, and the result was no better, the score was still around 0.001 ~ 0.004. So the problem doesn't (only) come from that. And still, it doesn't explain why my validation loss and F2 score are higher than my train.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 541824,
          "author_name": "tanlikesmath",
          "author_url": "",
          "post_date": "06/03/2019 04:35:21",
          "content": "<p>Have you tried increasing your learning rate? Maybe 1e-2?</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 541828,
          "author_name": "tanlikesmath",
          "author_url": "",
          "post_date": "06/03/2019 04:41:59",
          "content": "<p>It's also weird that your validation f2 is higher than your training, but the loss is also higher.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 541840,
          "author_name": "axel81",
          "author_url": "",
          "post_date": "06/03/2019 05:13:41",
          "content": "<p>Are you using pretrained imagenet weights or not?</p>\n\n<p>I also built one Siamese Net solution which was not properly learning without pretrained imagenet weights</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 541842,
          "author_name": "maxlenormand",
          "author_url": "",
          "post_date": "06/03/2019 05:16:13",
          "content": "<p>I did try at 0.001 and 0.0001, but not at 0.01. I could try it just to see, even though I don't think that's the core of the problem.\nAnd yes, the fact that the validation metrics are higher is what concerns me the most, and I can't figure what's wrong with it.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 541845,
          "author_name": "maxlenormand",
          "author_url": "",
          "post_date": "06/03/2019 05:18:05",
          "content": "<p>Yep, using imagenet weights. But maybe not properly.\nI'll have another look!</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 541846,
          "author_name": "tanlikesmath",
          "author_url": "",
          "post_date": "06/03/2019 05:18:27",
          "content": "<p>If you are not using imagenet weights, that could explain a lot of problems. Because training from scratch would take a really long time. See if there is any problems with that and let us know.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 541847,
          "author_name": "maxlenormand",
          "author_url": "",
          "post_date": "06/03/2019 05:22:47",
          "content": "<p>I know that, but I am using the imagenet weights :-)</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 541848,
          "author_name": "axel81",
          "author_url": "",
          "post_date": "06/03/2019 05:27:19",
          "content": "<p>Are you generating labels for your preds properly? there could be a bug there</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 541858,
          "author_name": "maxlenormand",
          "author_url": "",
          "post_date": "06/03/2019 06:02:49",
          "content": "<p>I think that might be where the problem is coming from yeah\nBecause I tweaked my model, and the result looks much better already. (you can see it <a href=\"https://www.kaggle.com/maxlenormand/change-model-act-softmax-incresnetv2\">in this Kernel</a> or in the image attached)</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 541868,
          "author_name": "tanlikesmath",
          "author_url": "",
          "post_date": "06/03/2019 06:16:21",
          "content": "<p>Indeed this looks better. BTW the kernel you linked is private.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 541882,
          "author_name": "maxlenormand",
          "author_url": "",
          "post_date": "06/03/2019 06:40:37",
          "content": "<p>My bad!\nAll public now!</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 542428,
          "author_name": "artyomp",
          "author_url": "",
          "post_date": "06/03/2019 22:49:41",
          "content": "<p>Regarding this: \"It's also weird that your validation f2 is higher than your training, but the loss is also higher.\"\nThis is absolutely normal when augmentations are in place. Especially with mixup.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 542637,
          "author_name": "maxlenormand",
          "author_url": "",
          "post_date": "06/04/2019 02:30:50",
          "content": "<p>Okay, thanks! Good to know that!</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 541938,
      "author_name": "artyomp",
      "author_url": "",
      "post_date": "06/03/2019 08:09:33",
      "content": "<p>Just clone a working kernel. Btw, 4 epochs are not enough for training anyway. And you don't need InceptionResNetV2 for the start, take ResNet50 and make sure your training works as expected. </p>\n\n<p>FYI, InceptionResNetV2 achieves 0.605 on validation for me.</p>",
      "votes": null,
      "replies": [
        {
          "id": 542138,
          "author_name": "maxlenormand",
          "author_url": "",
          "post_date": "06/03/2019 13:52:50",
          "content": "<p>Sure I could do that, but I don't want to just clone a kernel. I want to be able to make on from scratch and understand it along the way. I've still pretty new to all of this, so I want to take it as a learning experience.\nAnd I just took InceptionResNet because that was one of the ones I used in a previous competition, so I just copied the code from there.\nAnd yeah, 4 epochs are not enough indeed, but at least they can start showing a trend. For debugging quickly I thought it might be a could way to go. Might not be though.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 542355,
          "author_name": "artyomp",
          "author_url": "",
          "post_date": "06/03/2019 18:36:01",
          "content": "<p>I'm not saying copy-pasting code from kernels is good. But you are given many working examples. It's up to you to find a difference between your code and any of the working implementations. A good ML engineer must be good at coding.</p>\n\n<p>I see your point though. I made my solution from scratch.</p>\n\n<p>You must have some serious error somewhere in your pipeline, like wrong image normalization. Another thing you could try is to take the code from any image classification tutorial and make it use competition data.</p>\n\n<p>Problem is, if you change a lot of things at once and then click Run, it wouldn't work. Try doing small incremental changes while keeping an eye on validation metrics.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 542636,
          "author_name": "maxlenormand",
          "author_url": "",
          "post_date": "06/04/2019 02:30:30",
          "content": "<p>Totally agree, and that's what I'm doing, tweaking one thing at a time (Kaggle allowing to run 4 kernels at once does help).\nI think my issue here is a lack of understanding at some point of the entire pipeline. I do understand most of it, but you only need one error for it not to work.</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 542174,
      "author_name": "kiurtis",
      "author_url": "",
      "post_date": "06/03/2019 14:38:01",
      "content": "<p>I see 2 different points: </p>\n\n<p>1) You are not giving enough iterations to your model to learn. You probably need more than 4 epochs especially for softmax - in my experience with this dataset at least. Increase the patience of your early stopping should improve this.</p>\n\n<p>2) Even though your validation score is low, there is an important gap (&gt; x10) between your validation score and your test score, the latter being very close to 0 anyway. It probably means that you are not submitting your results properly. I suspect that you have the same issue I went through caused by a bad order of your labels in the final dataframe you submit. </p>\n\n<p>In my case, it was caused by a mismatch between the alphabetic order and the numerical order: the numerical labels where converted to string and thus ordered  by alphabetic order (\"0\", \"1\", \"10\", \"100\", etc.). As a consequence, I was submitting the results of the 10th label for the 3nd etc. </p>\n\n<p>Look at the train_generator.class_indices to see the mapping between labels and their order and check that it's coherent. Another quick check is to look at your most frequently predicted class. It should be 813 (\"tag::men\"). Having a quick look at your submission, that does not seem to be the case here. </p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 542245,
      "author_name": "donkeys",
      "author_url": "",
      "post_date": "06/03/2019 15:56:23",
      "content": "<p>I had some similar issues and started the same way on this. This is my first image classification competition, just trying to learn how to do it all. I started by copying parts of a kernel using InceptionResNetV2. Now I have been using ResNet50 to just get started, but quickly running out of time since I only started on this 2 weeks ago and my first image learning one.</p>\n\n<p>I had some issues initially to get the labels correct, as also mentioned by <a href=\"/kiurtis\">@kiurtis</a>. I ended up one-hot encoding the target variables, and checking closely that they are actually correctly encoded (printing out specific indices in the one-hot encoded arrays to see they match the numbers from the labels dataframe). I only had a quick look at your kernel but you don't seem to be one-hot encoding it. Not sure how much difference it makes, as I said, just trying to learn and see myself. And limited time to experiment.</p>\n\n<p>Also, maybe use the inception_resnet_v2.preprocess_input() function on your images. It should give decent results anyway, but this should ensure at least the input has a similar distribution (I guess that is the correct term..). </p>",
      "votes": null,
      "replies": [
        {
          "id": 542630,
          "author_name": "maxlenormand",
          "author_url": "",
          "post_date": "06/04/2019 02:28:35",
          "content": "<p>Well, I saw one-hot encoding was one option out of it, but I did want to try to do it without\nI saw that it could work without doing it like that, so I wanted to try.\nI think I got onboard this competition a bit too late to have time to solve any of these issues. But thanks for the ideas, I'll have a look at those!</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 542718,
      "author_name": "mpsampat",
      "author_url": "",
      "post_date": "06/04/2019 03:59:39",
      "content": "<p>Hi <a href=\"/maxlenormand\">@maxlenormand</a> , </p>\n\n<p>I think one issue could be  this step: datagen=ImageDataGenerator(rescale=1./255.,validation_split=0.2)</p>\n\n<p>Since we use imageNet weights we need to <em>apply same normalization to the images as ImageNet did</em>. \nIt may converge without this normalization but it will take a much longer time. </p>\n\n<p>for normalization you need to find mean value from ImageNet and subtract it from training and testing. \nI will try and see if i can fork your kernel and make this change and test my theory :-) </p>\n\n<p>Happy Debugging ! (which in a way is one of the most fun  part of ML ) </p>",
      "votes": null,
      "replies": [
        {
          "id": 542719,
          "author_name": "mpsampat",
          "author_url": "",
          "post_date": "06/04/2019 04:00:48",
          "content": "<p>also just saw averagemn's comment. i am suggesting the same as him. \"Also, maybe use the inceptionresnetv2.preprocess_input() function on your images\"</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 542876,
          "author_name": "maxlenormand",
          "author_url": "",
          "post_date": "06/04/2019 06:49:21",
          "content": "<p>Interesting, I didn't know about that. I'm not sure how to apply the same normalization as Imagenet, so I'd definitely be interested in seeing that, even after the competition is over!</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 542874,
      "author_name": "maxlenormand",
      "author_url": "",
      "post_date": "06/04/2019 06:47:52",
      "content": "<p>Just would like to thanks <a href=\"/kiurtis\">@kiurtis</a> which has helped me in the background find a fix, it indeed was the predicitons that was not working properly\nI jumped up to 0.472 now thanks to that\nThanks to everyone for the help, really appreciate it! :-)</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "541763": "Hello everyone!\n\nI'm still relatively new to Kaggle, so I'm still learning a lot. I'm getting on this competition pretty late, but I've been working on it for the past 2 weeks roughly. I've been stuck since then on a super low score, and I just can't figure out what the problem is. Here is [my Kernel ](https://www.kaggle.com/maxlenormand/act-softmax-incresnetv2) which is based upon several other kernels, but mostly [the Keras-Starter Kernel](https://www.kaggle.com/ateplyuk/keras-starter) which is basically what I was going for anyways.\nIn a nutshell, I'm using an InceptionResNetV2, with a last layer with 1103 nodes with a softmax activation.\nI think something is wrong with the way my model is learning as from what I display, the validation F2 score is already higher than the training one on the first epochs, which doesn't make much sense. The training F2 score is getting better as the epoch go on, and the training loss goes down, which seems correct. However the validation score and loss just don't seem to make sense, and I can't figure out why; hence after muliple days of searching, turning to the forum. If anybody would be willing to take a look at let me know what they think, I'd really appreciate it!\n\nI have some ideas I would have wanted to try out for this competition, but if I can't even get a simple model working, then it's not even worth trying those! My timing wasn't great on this one.\nThanks for the help!",
    "541766": "Your early-stopping stops the model very early so it only trains for 4 epochs. It's probably best to get rid of the early stopping and train as long as you can",
    "541805": "Yep, my early stopping isn't working very well, I agree.\nHowever I did train it over 15 epoch, and the result was no better, the score was still around 0.001 ~ 0.004. So the problem doesn't (only) come from that. And still, it doesn't explain why my validation loss and F2 score are higher than my train.",
    "541824": "Have you tried increasing your learning rate? Maybe 1e-2?",
    "541828": "It's also weird that your validation f2 is higher than your training, but the loss is also higher.",
    "541840": "Are you using pretrained imagenet weights or not?\n\nI also built one Siamese Net solution which was not properly learning without pretrained imagenet weights",
    "541842": "I did try at 0.001 and 0.0001, but not at 0.01. I could try it just to see, even though I don't think that's the core of the problem.\nAnd yes, the fact that the validation metrics are higher is what concerns me the most, and I can't figure what's wrong with it.",
    "541845": "Yep, using imagenet weights. But maybe not properly.\nI'll have another look!",
    "541846": "If you are not using imagenet weights, that could explain a lot of problems. Because training from scratch would take a really long time. See if there is any problems with that and let us know.",
    "541847": "I know that, but I am using the imagenet weights :-)",
    "541848": "Are you generating labels for your preds properly? there could be a bug there",
    "541858": "I think that might be where the problem is coming from yeah\nBecause I tweaked my model, and the result looks much better already. (you can see it [in this Kernel](https://www.kaggle.com/maxlenormand/change-model-act-softmax-incresnetv2) or in the image attached)",
    "541868": "Indeed this looks better. BTW the kernel you linked is private.",
    "541882": "My bad!\nAll public now!",
    "541938": "Just clone a working kernel. Btw, 4 epochs are not enough for training anyway. And you don't need InceptionResNetV2 for the start, take ResNet50 and make sure your training works as expected. \n\nFYI, InceptionResNetV2 achieves 0.605 on validation for me.",
    "542138": "Sure I could do that, but I don't want to just clone a kernel. I want to be able to make on from scratch and understand it along the way. I've still pretty new to all of this, so I want to take it as a learning experience.\nAnd I just took InceptionResNet because that was one of the ones I used in a previous competition, so I just copied the code from there.\nAnd yeah, 4 epochs are not enough indeed, but at least they can start showing a trend. For debugging quickly I thought it might be a could way to go. Might not be though.",
    "542174": "I see 2 different points: \n\n1) You are not giving enough iterations to your model to learn. You probably need more than 4 epochs especially for softmax - in my experience with this dataset at least. Increase the patience of your early stopping should improve this.\n\n\n2) Even though your validation score is low, there is an important gap (&gt; x10) between your validation score and your test score, the latter being very close to 0 anyway. It probably means that you are not submitting your results properly. I suspect that you have the same issue I went through caused by a bad order of your labels in the final dataframe you submit. \n\nIn my case, it was caused by a mismatch between the alphabetic order and the numerical order: the numerical labels where converted to string and thus ordered  by alphabetic order (\"0\", \"1\", \"10\", \"100\", etc.). As a consequence, I was submitting the results of the 10th label for the 3nd etc. \n\nLook at the train\\_generator.class\\_indices to see the mapping between labels and their order and check that it's coherent. Another quick check is to look at your most frequently predicted class. It should be 813 (\"tag::men\"). Having a quick look at your submission, that does not seem to be the case here.",
    "542245": "I had some similar issues and started the same way on this. This is my first image classification competition, just trying to learn how to do it all. I started by copying parts of a kernel using InceptionResNetV2. Now I have been using ResNet50 to just get started, but quickly running out of time since I only started on this 2 weeks ago and my first image learning one.\n\nI had some issues initially to get the labels correct, as also mentioned by @kiurtis. I ended up one-hot encoding the target variables, and checking closely that they are actually correctly encoded (printing out specific indices in the one-hot encoded arrays to see they match the numbers from the labels dataframe). I only had a quick look at your kernel but you don't seem to be one-hot encoding it. Not sure how much difference it makes, as I said, just trying to learn and see myself. And limited time to experiment.\n\nAlso, maybe use the inception_resnet_v2.preprocess_input() function on your images. It should give decent results anyway, but this should ensure at least the input has a similar distribution (I guess that is the correct term..).",
    "542355": "I'm not saying copy-pasting code from kernels is good. But you are given many working examples. It's up to you to find a difference between your code and any of the working implementations. A good ML engineer must be good at coding.\n\nI see your point though. I made my solution from scratch.\n\nYou must have some serious error somewhere in your pipeline, like wrong image normalization. Another thing you could try is to take the code from any image classification tutorial and make it use competition data.\n\nProblem is, if you change a lot of things at once and then click Run, it wouldn't work. Try doing small incremental changes while keeping an eye on validation metrics.",
    "542428": "Regarding this: \"It's also weird that your validation f2 is higher than your training, but the loss is also higher.\"\nThis is absolutely normal when augmentations are in place. Especially with mixup.",
    "542630": "Well, I saw one-hot encoding was one option out of it, but I did want to try to do it without\nI saw that it could work without doing it like that, so I wanted to try.\nI think I got onboard this competition a bit too late to have time to solve any of these issues. But thanks for the ideas, I'll have a look at those!",
    "542636": "Totally agree, and that's what I'm doing, tweaking one thing at a time (Kaggle allowing to run 4 kernels at once does help).\nI think my issue here is a lack of understanding at some point of the entire pipeline. I do understand most of it, but you only need one error for it not to work.",
    "542637": "Okay, thanks! Good to know that!",
    "542718": "Hi @maxlenormand , \n\nI think one issue could be  this step: datagen=ImageDataGenerator(rescale=1./255.,validation_split=0.2)\n\nSince we use imageNet weights we need to *apply same normalization to the images as ImageNet did*. \nIt may converge without this normalization but it will take a much longer time. \n\nfor normalization you need to find mean value from ImageNet and subtract it from training and testing. \nI will try and see if i can fork your kernel and make this change and test my theory :-) \n\nHappy Debugging ! (which in a way is one of the most fun  part of ML )",
    "542719": "also just saw averagemn's comment. i am suggesting the same as him. \"Also, maybe use the inceptionresnetv2.preprocess_input() function on your images\"",
    "542874": "Just would like to thanks @kiurtis which has helped me in the background find a fix, it indeed was the predicitons that was not working properly\nI jumped up to 0.472 now thanks to that\nThanks to everyone for the help, really appreciate it! :-)",
    "542876": "Interesting, I didn't know about that. I'm not sure how to apply the same normalization as Imagenet, so I'd definitely be interested in seeing that, even after the competition is over!"
  },
  "source": "meta"
}