{
  "id": 72812,
  "title": "Pytorch Baseline 0.461",
  "url": "/competitions/human-protein-atlas-image-classification/discussion/72812",
  "author_name": "",
  "post_date": "2018-11-27T10:58:00.513053600Z",
  "votes": 56,
  "comment_count": 25,
  "views": 0,
  "content": "<p>Link:<a href=\"https://github.com/spytensor/kaggle_human_protein_baseline\">https://github.com/spytensor/kaggle_human_protein_baseline</a></p>",
  "messages": [
    {
      "id": "428480",
      "postDate": "11/27/2018 10:58:00",
      "content": "<p>Link:<a href=\"https://github.com/spytensor/kaggle_human_protein_baseline\">https://github.com/spytensor/kaggle_human_protein_baseline</a></p>",
      "rawMarkdown": "Link:https://github.com/spytensor/kaggle_human_protein_baseline",
      "votes": null
    },
    {
      "id": "430213",
      "postDate": "11/30/2018 03:10:32",
      "content": "<p>Hi spytensor, thank you very much for your baseline. I run the code by myself and get 0.460.\nI've got a question, which i cannot figure out:\nDuring training, f1 macro for training set and val set is about 0.26 or so. But f1 macro for test set is 0.460.\nwhy is that? </p>",
      "rawMarkdown": "Hi spytensor, thank you very much for your baseline. I run the code by myself and get 0.460.\nI've got a question, which i cannot figure out:\nDuring training, f1 macro for training set and val set is about 0.26 or so. But f1 macro for test set is 0.460.\nwhy is that?",
      "votes": null
    },
    {
      "id": "430356",
      "postDate": "11/30/2018 08:59:41",
      "content": "<p>I also found that question, I get 0.41 on val set,0.56 on train set and 0.461 on test set. One reason may be  the f1-score method I used in my code.You can write yourself and if solved ,please tell me.</p>",
      "rawMarkdown": "I also found that question, I get 0.41 on val set,0.56 on train set and 0.461 on test set. One reason may be  the f1-score method I used in my code.You can write yourself and if solved ,please tell me.",
      "votes": null
    },
    {
      "id": "434873",
      "postDate": "12/07/2018 04:53:25",
      "content": "<p>Thanks to your share, i am a noob in image classification.</p>\n\n<p>Your opensource is quite helpful  to me, thank you!</p>",
      "rawMarkdown": "Thanks to your share, i am a noob in image classification.\n\nYour opensource is quite helpful  to me, thank you!",
      "votes": null
    },
    {
      "id": "436348",
      "postDate": "12/10/2018 06:40:39",
      "content": "<p>Hello ,where is the pretrained models,thanks!</p>",
      "rawMarkdown": "Hello ,where is the pretrained models,thanks!",
      "votes": null
    },
    {
      "id": "436407",
      "postDate": "12/10/2018 08:41:07",
      "content": "<p>Run the model ,and it will be downloaded automatically to path \"~/user/.torch/models/\".Or you can download yourself after you googled .</p>",
      "rawMarkdown": "Run the model ,and it will be downloaded automatically to path \"~/user/.torch/models/\".Or you can download yourself after you googled .",
      "votes": null
    },
    {
      "id": "436408",
      "postDate": "12/10/2018 08:41:35",
      "content": "<p>Enjoy the competition.</p>",
      "rawMarkdown": "Enjoy the competition.",
      "votes": null
    },
    {
      "id": "436642",
      "postDate": "12/10/2018 17:32:25",
      "content": "<p>I guess you need to calculate f1score for entire validation data not batch. Averaging each batch f1score gives you wrong score.</p>",
      "rawMarkdown": "I guess you need to calculate f1score for entire validation data not batch. Averaging each batch f1score gives you wrong score.",
      "votes": null
    },
    {
      "id": "436849",
      "postDate": "12/11/2018 02:54:07",
      "content": "<p>I‘ve realized that,thanks!\nThere is “from pretrainedmodels.models import bninception” in your model.py file, so the pretrainedmodels.models is need.</p>",
      "rawMarkdown": "I‘ve realized that,thanks!\nThere is “from pretrainedmodels.models import bninception” in your model.py file, so the pretrainedmodels.models is need.",
      "votes": null
    },
    {
      "id": "437538",
      "postDate": "12/12/2018 05:22:22",
      "content": "<p>The author caculated loss each batch, which i thinks is okay, but i don't think it is suitable for f1 score. While val, he caculated f1-score each batch, and use the average of them to replace the real f1-score,\nwhich i think is not right.</p>\n\n<p>Here is my code: while val, get all the preditection and real_label and then caculate the f1-score.</p>\n\n<p>```</p>\n\n<h1>2. evaluate fuunction</h1>\n\n<p>def evaluate(val_loader,model,criterion,epoch,train_loss,best_results,start):\n    # only meter loss and f1 score\n    losses = AverageMeter()\n    f1 = AverageMeter()\n    # switch mode for evaluation\n    model.cuda()\n    model.eval()\n    with torch.no_grad():\n        for i, (images,target) in enumerate(val_loader):\n            # 1、获取新的一个batch的结果\n            images_var = images.cuda(non_blocking=True)\n            target = torch.from_numpy(np.array(target)).float().cuda(non_blocking=True)\n            #image_var = Variable(images).cuda()\n            #target = Variable(torch.from_numpy(np.array(target)).long()).cuda()\n            output = model(images_var)</p>\n\n<pre><code>        # 2、把每一个batch的结果合并\n        if i==0:\n            total_output = output\n            total_target = target\n        else:\n            total_output = torch.cat([total_output, output],0)\n            total_target = torch.cat([total_target, target],0)\n\n    # 3、计算整个验证集上的得分\n    loss = criterion(total_output, total_target)\n    losses.update(loss.item(),images_var.size(0))\n    f1_batch = f1_score(total_target, total_output.sigmoid().cpu().data.numpy() &gt; 0.15,average='macro')\n    f1.update(f1_batch,images_var.size(0))\n    print('\\r',end='',flush=True)\n    message = '%s   %5.1f %6.1f         |         %0.3f  %0.3f           |         %0.3f  %0.4f         |         %s  %s    | %s' % (\\\n                \"val\", i/len(val_loader) + epoch, epoch,                    \n                train_loss[0], train_loss[1], \n                losses.avg, f1.avg,\n                str(best_results[0])[:8],str(best_results[1])[:8],\n                time_to_str((timer() - start),'min'))\n\n    print(message, end='',flush=True)\n    log.write(\"\\n\")\n    #log.write(message)\n    #log.write(\"\\n\")\n\nreturn [losses.avg,f1.avg]\n</code></pre>\n\n<p>```</p>",
      "rawMarkdown": "The author caculated loss each batch, which i thinks is okay, but i don't think it is suitable for f1 score. While val, he caculated f1-score each batch, and use the average of them to replace the real f1-score,\nwhich i think is not right.\n\nHere is my code: while val, get all the preditection and real_label and then caculate the f1-score.\n\n```\n# 2. evaluate fuunction\ndef evaluate(val_loader,model,criterion,epoch,train_loss,best_results,start):\n    # only meter loss and f1 score\n    losses = AverageMeter()\n    f1 = AverageMeter()\n    # switch mode for evaluation\n    model.cuda()\n    model.eval()\n    with torch.no_grad():\n        for i, (images,target) in enumerate(val_loader):\n            # 1、获取新的一个batch的结果\n            images_var = images.cuda(non_blocking=True)\n            target = torch.from_numpy(np.array(target)).float().cuda(non_blocking=True)\n            #image_var = Variable(images).cuda()\n            #target = Variable(torch.from_numpy(np.array(target)).long()).cuda()\n            output = model(images_var)\n            \n            # 2、把每一个batch的结果合并\n            if i==0:\n                total_output = output\n                total_target = target\n            else:\n                total_output = torch.cat([total_output, output],0)\n                total_target = torch.cat([total_target, target],0)\n\n        # 3、计算整个验证集上的得分\n        loss = criterion(total_output, total_target)\n        losses.update(loss.item(),images_var.size(0))\n        f1_batch = f1_score(total_target, total_output.sigmoid().cpu().data.numpy() &gt; 0.15,average='macro')\n        f1.update(f1_batch,images_var.size(0))\n        print('\\r',end='',flush=True)\n        message = '%s   %5.1f %6.1f         |         %0.3f  %0.3f           |         %0.3f  %0.4f         |         %s  %s    | %s' % (\\\n                    \"val\", i/len(val_loader) + epoch, epoch,                    \n                    train_loss[0], train_loss[1], \n                    losses.avg, f1.avg,\n                    str(best_results[0])[:8],str(best_results[1])[:8],\n                    time_to_str((timer() - start),'min'))\n\n        print(message, end='',flush=True)\n        log.write(\"\\n\")\n        #log.write(message)\n        #log.write(\"\\n\")\n        \n    return [losses.avg,f1.avg]\n```",
      "votes": null
    },
    {
      "id": "439884",
      "postDate": "12/16/2018 15:22:57",
      "content": "<p>Thanks for sharing a really good BSL.</p>",
      "rawMarkdown": "Thanks for sharing a really good BSL.",
      "votes": null
    },
    {
      "id": "440196",
      "postDate": "12/17/2018 07:42:31",
      "content": "<p>I am wondering  why SGD optimizer is used in your code. As far as I know, Adam performs better as it combines RMSprop  and Momentum.\nI tried Adam but turned to get a terrible 0.33LB.\nCan anyone tell me the reason.</p>",
      "rawMarkdown": "I am wondering  why SGD optimizer is used in your code. As far as I know, Adam performs better as it combines RMSprop  and Momentum.\nI tried Adam but turned to get a terrible 0.33LB.\nCan anyone tell me the reason.",
      "votes": null
    },
    {
      "id": "442363",
      "postDate": "12/19/2018 21:29:21",
      "content": "<p>Hi EeAary,\nDid you also modify the learning rate that is set to 0.03. Such a learning rate is usable for the SGD optimizer...but for Adam you'd better start with the default of 0.001 or other minor variation on it.\nSee if that works for you.</p>",
      "rawMarkdown": "Hi EeAary,\nDid you also modify the learning rate that is set to 0.03. Such a learning rate is usable for the SGD optimizer...but for Adam you'd better start with the default of 0.001 or other minor variation on it.\nSee if that works for you.",
      "votes": null
    },
    {
      "id": "442447",
      "postDate": "12/20/2018 01:18:08",
      "content": "<p>Thanks for ur sharing</p>",
      "rawMarkdown": "Thanks for ur sharing",
      "votes": null
    },
    {
      "id": "442521",
      "postDate": "12/20/2018 04:01:27",
      "content": "<p>Definely I have modified the learning rate to 0.001 using Adam, and I set a StepLR with gamma 0.1 every 5 epoch. Anyway I failed to reach the loss as low as SGD did.\nI've obtain a better score but still interested in this problem. Maybe it just likes playing Hearthstone, I don't know what cards I'm going to get.</p>",
      "rawMarkdown": "Definely I have modified the learning rate to 0.001 using Adam, and I set a StepLR with gamma 0.1 every 5 epoch. Anyway I failed to reach the loss as low as SGD did.\nI've obtain a better score but still interested in this problem. Maybe it just likes playing Hearthstone, I don't know what cards I'm going to get.",
      "votes": null
    },
    {
      "id": "442685",
      "postDate": "12/20/2018 10:29:57",
      "content": "<p>Give it a try with a stepsize of 8 or 10 epochs. Very likely it is to early to lower the learningrate. Alternativly ... Increase gamma to say something like 0.5. That should likely increase your results. Good luck.</p>",
      "rawMarkdown": "Give it a try with a stepsize of 8 or 10 epochs. Very likely it is to early to lower the learningrate. Alternativly ... Increase gamma to say something like 0.5. That should likely increase your results. Good luck.",
      "votes": null
    },
    {
      "id": "443660",
      "postDate": "12/22/2018 04:01:11",
      "content": "<p>Thanks so much, it works!</p>",
      "rawMarkdown": "Thanks so much, it works!",
      "votes": null
    },
    {
      "id": "447148",
      "postDate": "12/29/2018 08:15:20",
      "content": "<p>Hi @Spytensor, i have some difficulty understanding your code. If you can help me, it would be great. Thanks in advance.\nIn your HumanDataset class:</p>\n\n<pre><code>y = str(self.images_df.iloc[index].Id.absolute()) # what is this absolute() function? \n</code></pre>",
      "rawMarkdown": "Hi @Spytensor, i have some difficulty understanding your code. If you can help me, it would be great. Thanks in advance.\nIn your HumanDataset class:\n\n    y = str(self.images_df.iloc[index].Id.absolute()) # what is this absolute() function?",
      "votes": null
    },
    {
      "id": "447422",
      "postDate": "12/29/2018 19:39:01",
      "content": "<p>@Spytensor could you please explain how can i feed 512X512 images to resnext architecture. Please.</p>",
      "rawMarkdown": "Spytensor could you please explain how can i feed 512X512 images to resnext architecture. Please.",
      "votes": null
    },
    {
      "id": "447550",
      "postDate": "12/30/2018 03:49:58",
      "content": "<p>Change the model's avgpool to adaptiveavgpool like this:\n<code>python\nmodel = resnext 50()\nmodel.avg_pool = nn.AdaptiveAvgPool2d(1)\n</code></p>",
      "rawMarkdown": "Change the model's avgpool to adaptiveavgpool like this:\n```python\nmodel = resnext 50()\nmodel.avg_pool = nn.AdaptiveAvgPool2d(1)\n```",
      "votes": null
    },
    {
      "id": "447892",
      "postDate": "12/30/2018 19:27:18",
      "content": "<p>Thanks</p>",
      "rawMarkdown": "Thanks",
      "votes": null
    },
    {
      "id": "447966",
      "postDate": "12/30/2018 23:48:12",
      "content": "<p>The elements in Id column are objects from pathlib, the method gets you the absolute path to the image file. </p>",
      "rawMarkdown": "The elements in Id column are objects from pathlib, the method gets you the absolute path to the image file.",
      "votes": null
    },
    {
      "id": "448781",
      "postDate": "01/02/2019 04:42:51",
      "content": "<p><a href=\"/pascal1129\">@pascal1129</a>\nThanks for sharing,does the train code need to be changed?I changed it in your way, but I got it wrong.\nIf you don’t change how to judge the gap between train and val.</p>",
      "rawMarkdown": "pascal1129\nThanks for sharing,does the train code need to be changed?I changed it in your way, but I got it wrong.\nIf you don’t change how to judge the gap between train and val.",
      "votes": null
    },
    {
      "id": "448921",
      "postDate": "01/02/2019 11:06:58",
      "content": "<p>Indeed, I changed lots, but the details are difficult to explain here.</p>",
      "rawMarkdown": "Indeed, I changed lots, but the details are difficult to explain here.",
      "votes": null
    },
    {
      "id": "448944",
      "postDate": "01/02/2019 12:00:28",
      "content": "<p>ok,thanks</p>",
      "rawMarkdown": "ok,thanks",
      "votes": null
    },
    {
      "id": "1496033",
      "postDate": "08/30/2021 03:26:22",
      "content": "<p>Thanks for sharing. This has really made me learn a lot. I also found that change to (better) model or let the image size larger could get better results.</p>",
      "rawMarkdown": "Thanks for sharing. This has really made me learn a lot. I also found that change to (better) model or let the image size larger could get better results.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1496033,
      "author_name": "nanamiyvonne",
      "author_url": "",
      "post_date": "08/30/2021 03:26:22",
      "content": "<p>Thanks for sharing. This has really made me learn a lot. I also found that change to (better) model or let the image size larger could get better results.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 430213,
      "author_name": "irvingzhang0512",
      "author_url": "",
      "post_date": "11/30/2018 03:10:32",
      "content": "<p>Hi spytensor, thank you very much for your baseline. I run the code by myself and get 0.460.\nI've got a question, which i cannot figure out:\nDuring training, f1 macro for training set and val set is about 0.26 or so. But f1 macro for test set is 0.460.\nwhy is that? </p>",
      "votes": null,
      "replies": [
        {
          "id": 437538,
          "author_name": "pascal1129",
          "author_url": "",
          "post_date": "12/12/2018 05:22:22",
          "content": "<p>The author caculated loss each batch, which i thinks is okay, but i don't think it is suitable for f1 score. While val, he caculated f1-score each batch, and use the average of them to replace the real f1-score,\nwhich i think is not right.</p>\n\n<p>Here is my code: while val, get all the preditection and real_label and then caculate the f1-score.</p>\n\n<p>```</p>\n\n<h1>2. evaluate fuunction</h1>\n\n<p>def evaluate(val_loader,model,criterion,epoch,train_loss,best_results,start):\n    # only meter loss and f1 score\n    losses = AverageMeter()\n    f1 = AverageMeter()\n    # switch mode for evaluation\n    model.cuda()\n    model.eval()\n    with torch.no_grad():\n        for i, (images,target) in enumerate(val_loader):\n            # 1、获取新的一个batch的结果\n            images_var = images.cuda(non_blocking=True)\n            target = torch.from_numpy(np.array(target)).float().cuda(non_blocking=True)\n            #image_var = Variable(images).cuda()\n            #target = Variable(torch.from_numpy(np.array(target)).long()).cuda()\n            output = model(images_var)</p>\n\n<pre><code>        # 2、把每一个batch的结果合并\n        if i==0:\n            total_output = output\n            total_target = target\n        else:\n            total_output = torch.cat([total_output, output],0)\n            total_target = torch.cat([total_target, target],0)\n\n    # 3、计算整个验证集上的得分\n    loss = criterion(total_output, total_target)\n    losses.update(loss.item(),images_var.size(0))\n    f1_batch = f1_score(total_target, total_output.sigmoid().cpu().data.numpy() &gt; 0.15,average='macro')\n    f1.update(f1_batch,images_var.size(0))\n    print('\\r',end='',flush=True)\n    message = '%s   %5.1f %6.1f         |         %0.3f  %0.3f           |         %0.3f  %0.4f         |         %s  %s    | %s' % (\\\n                \"val\", i/len(val_loader) + epoch, epoch,                    \n                train_loss[0], train_loss[1], \n                losses.avg, f1.avg,\n                str(best_results[0])[:8],str(best_results[1])[:8],\n                time_to_str((timer() - start),'min'))\n\n    print(message, end='',flush=True)\n    log.write(\"\\n\")\n    #log.write(message)\n    #log.write(\"\\n\")\n\nreturn [losses.avg,f1.avg]\n</code></pre>\n\n<p>```</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 448781,
          "author_name": "wwchaoo",
          "author_url": "",
          "post_date": "01/02/2019 04:42:51",
          "content": "<p><a href=\"/pascal1129\">@pascal1129</a>\nThanks for sharing,does the train code need to be changed?I changed it in your way, but I got it wrong.\nIf you don’t change how to judge the gap between train and val.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 448921,
          "author_name": "pascal1129",
          "author_url": "",
          "post_date": "01/02/2019 11:06:58",
          "content": "<p>Indeed, I changed lots, but the details are difficult to explain here.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 448944,
          "author_name": "wwchaoo",
          "author_url": "",
          "post_date": "01/02/2019 12:00:28",
          "content": "<p>ok,thanks</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 430356,
      "author_name": "spytensor",
      "author_url": "",
      "post_date": "11/30/2018 08:59:41",
      "content": "<p>I also found that question, I get 0.41 on val set,0.56 on train set and 0.461 on test set. One reason may be  the f1-score method I used in my code.You can write yourself and if solved ,please tell me.</p>",
      "votes": null,
      "replies": [
        {
          "id": 436642,
          "author_name": "appian",
          "author_url": "",
          "post_date": "12/10/2018 17:32:25",
          "content": "<p>I guess you need to calculate f1score for entire validation data not batch. Averaging each batch f1score gives you wrong score.</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 434873,
      "author_name": "pascal1129",
      "author_url": "",
      "post_date": "12/07/2018 04:53:25",
      "content": "<p>Thanks to your share, i am a noob in image classification.</p>\n\n<p>Your opensource is quite helpful  to me, thank you!</p>",
      "votes": null,
      "replies": [
        {
          "id": 436408,
          "author_name": "spytensor",
          "author_url": "",
          "post_date": "12/10/2018 08:41:35",
          "content": "<p>Enjoy the competition.</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 436348,
      "author_name": "ispectre",
      "author_url": "",
      "post_date": "12/10/2018 06:40:39",
      "content": "<p>Hello ,where is the pretrained models,thanks!</p>",
      "votes": null,
      "replies": [
        {
          "id": 436407,
          "author_name": "spytensor",
          "author_url": "",
          "post_date": "12/10/2018 08:41:07",
          "content": "<p>Run the model ,and it will be downloaded automatically to path \"~/user/.torch/models/\".Or you can download yourself after you googled .</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 436849,
          "author_name": "ispectre",
          "author_url": "",
          "post_date": "12/11/2018 02:54:07",
          "content": "<p>I‘ve realized that,thanks!\nThere is “from pretrainedmodels.models import bninception” in your model.py file, so the pretrainedmodels.models is need.</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 439884,
      "author_name": "kentchun33333",
      "author_url": "",
      "post_date": "12/16/2018 15:22:57",
      "content": "<p>Thanks for sharing a really good BSL.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 440196,
      "author_name": "eeaary",
      "author_url": "",
      "post_date": "12/17/2018 07:42:31",
      "content": "<p>I am wondering  why SGD optimizer is used in your code. As far as I know, Adam performs better as it combines RMSprop  and Momentum.\nI tried Adam but turned to get a terrible 0.33LB.\nCan anyone tell me the reason.</p>",
      "votes": null,
      "replies": [
        {
          "id": 442363,
          "author_name": "rsmits",
          "author_url": "",
          "post_date": "12/19/2018 21:29:21",
          "content": "<p>Hi EeAary,\nDid you also modify the learning rate that is set to 0.03. Such a learning rate is usable for the SGD optimizer...but for Adam you'd better start with the default of 0.001 or other minor variation on it.\nSee if that works for you.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 442521,
          "author_name": "eeaary",
          "author_url": "",
          "post_date": "12/20/2018 04:01:27",
          "content": "<p>Definely I have modified the learning rate to 0.001 using Adam, and I set a StepLR with gamma 0.1 every 5 epoch. Anyway I failed to reach the loss as low as SGD did.\nI've obtain a better score but still interested in this problem. Maybe it just likes playing Hearthstone, I don't know what cards I'm going to get.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 442685,
          "author_name": "rsmits",
          "author_url": "",
          "post_date": "12/20/2018 10:29:57",
          "content": "<p>Give it a try with a stepsize of 8 or 10 epochs. Very likely it is to early to lower the learningrate. Alternativly ... Increase gamma to say something like 0.5. That should likely increase your results. Good luck.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 443660,
          "author_name": "eeaary",
          "author_url": "",
          "post_date": "12/22/2018 04:01:11",
          "content": "<p>Thanks so much, it works!</p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 442447,
      "author_name": "desperadod",
      "author_url": "",
      "post_date": "12/20/2018 01:18:08",
      "content": "<p>Thanks for ur sharing</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 447148,
      "author_name": "adilurrahim",
      "author_url": "",
      "post_date": "12/29/2018 08:15:20",
      "content": "<p>Hi @Spytensor, i have some difficulty understanding your code. If you can help me, it would be great. Thanks in advance.\nIn your HumanDataset class:</p>\n\n<pre><code>y = str(self.images_df.iloc[index].Id.absolute()) # what is this absolute() function? \n</code></pre>",
      "votes": null,
      "replies": [
        {
          "id": 447966,
          "author_name": "ryanzhang",
          "author_url": "",
          "post_date": "12/30/2018 23:48:12",
          "content": "<p>The elements in Id column are objects from pathlib, the method gets you the absolute path to the image file. </p>",
          "votes": null,
          "replies": []
        }
      ]
    },
    {
      "id": 447422,
      "author_name": "adilurrahim",
      "author_url": "",
      "post_date": "12/29/2018 19:39:01",
      "content": "<p>@Spytensor could you please explain how can i feed 512X512 images to resnext architecture. Please.</p>",
      "votes": null,
      "replies": [
        {
          "id": 447550,
          "author_name": "spytensor",
          "author_url": "",
          "post_date": "12/30/2018 03:49:58",
          "content": "<p>Change the model's avgpool to adaptiveavgpool like this:\n<code>python\nmodel = resnext 50()\nmodel.avg_pool = nn.AdaptiveAvgPool2d(1)\n</code></p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 447892,
          "author_name": "adilurrahim",
          "author_url": "",
          "post_date": "12/30/2018 19:27:18",
          "content": "<p>Thanks</p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "428480": "Link:https://github.com/spytensor/kaggle_human_protein_baseline",
    "430213": "Hi spytensor, thank you very much for your baseline. I run the code by myself and get 0.460.\nI've got a question, which i cannot figure out:\nDuring training, f1 macro for training set and val set is about 0.26 or so. But f1 macro for test set is 0.460.\nwhy is that?",
    "430356": "I also found that question, I get 0.41 on val set,0.56 on train set and 0.461 on test set. One reason may be  the f1-score method I used in my code.You can write yourself and if solved ,please tell me.",
    "434873": "Thanks to your share, i am a noob in image classification.\n\nYour opensource is quite helpful  to me, thank you!",
    "436348": "Hello ,where is the pretrained models,thanks!",
    "436407": "Run the model ,and it will be downloaded automatically to path \"~/user/.torch/models/\".Or you can download yourself after you googled .",
    "436408": "Enjoy the competition.",
    "436642": "I guess you need to calculate f1score for entire validation data not batch. Averaging each batch f1score gives you wrong score.",
    "436849": "I‘ve realized that,thanks!\nThere is “from pretrainedmodels.models import bninception” in your model.py file, so the pretrainedmodels.models is need.",
    "437538": "The author caculated loss each batch, which i thinks is okay, but i don't think it is suitable for f1 score. While val, he caculated f1-score each batch, and use the average of them to replace the real f1-score,\nwhich i think is not right.\n\nHere is my code: while val, get all the preditection and real_label and then caculate the f1-score.\n\n```\n# 2. evaluate fuunction\ndef evaluate(val_loader,model,criterion,epoch,train_loss,best_results,start):\n    # only meter loss and f1 score\n    losses = AverageMeter()\n    f1 = AverageMeter()\n    # switch mode for evaluation\n    model.cuda()\n    model.eval()\n    with torch.no_grad():\n        for i, (images,target) in enumerate(val_loader):\n            # 1、获取新的一个batch的结果\n            images_var = images.cuda(non_blocking=True)\n            target = torch.from_numpy(np.array(target)).float().cuda(non_blocking=True)\n            #image_var = Variable(images).cuda()\n            #target = Variable(torch.from_numpy(np.array(target)).long()).cuda()\n            output = model(images_var)\n            \n            # 2、把每一个batch的结果合并\n            if i==0:\n                total_output = output\n                total_target = target\n            else:\n                total_output = torch.cat([total_output, output],0)\n                total_target = torch.cat([total_target, target],0)\n\n        # 3、计算整个验证集上的得分\n        loss = criterion(total_output, total_target)\n        losses.update(loss.item(),images_var.size(0))\n        f1_batch = f1_score(total_target, total_output.sigmoid().cpu().data.numpy() &gt; 0.15,average='macro')\n        f1.update(f1_batch,images_var.size(0))\n        print('\\r',end='',flush=True)\n        message = '%s   %5.1f %6.1f         |         %0.3f  %0.3f           |         %0.3f  %0.4f         |         %s  %s    | %s' % (\\\n                    \"val\", i/len(val_loader) + epoch, epoch,                    \n                    train_loss[0], train_loss[1], \n                    losses.avg, f1.avg,\n                    str(best_results[0])[:8],str(best_results[1])[:8],\n                    time_to_str((timer() - start),'min'))\n\n        print(message, end='',flush=True)\n        log.write(\"\\n\")\n        #log.write(message)\n        #log.write(\"\\n\")\n        \n    return [losses.avg,f1.avg]\n```",
    "439884": "Thanks for sharing a really good BSL.",
    "440196": "I am wondering  why SGD optimizer is used in your code. As far as I know, Adam performs better as it combines RMSprop  and Momentum.\nI tried Adam but turned to get a terrible 0.33LB.\nCan anyone tell me the reason.",
    "442363": "Hi EeAary,\nDid you also modify the learning rate that is set to 0.03. Such a learning rate is usable for the SGD optimizer...but for Adam you'd better start with the default of 0.001 or other minor variation on it.\nSee if that works for you.",
    "442447": "Thanks for ur sharing",
    "442521": "Definely I have modified the learning rate to 0.001 using Adam, and I set a StepLR with gamma 0.1 every 5 epoch. Anyway I failed to reach the loss as low as SGD did.\nI've obtain a better score but still interested in this problem. Maybe it just likes playing Hearthstone, I don't know what cards I'm going to get.",
    "442685": "Give it a try with a stepsize of 8 or 10 epochs. Very likely it is to early to lower the learningrate. Alternativly ... Increase gamma to say something like 0.5. That should likely increase your results. Good luck.",
    "443660": "Thanks so much, it works!",
    "447148": "Hi @Spytensor, i have some difficulty understanding your code. If you can help me, it would be great. Thanks in advance.\nIn your HumanDataset class:\n\n    y = str(self.images_df.iloc[index].Id.absolute()) # what is this absolute() function?",
    "447422": "Spytensor could you please explain how can i feed 512X512 images to resnext architecture. Please.",
    "447550": "Change the model's avgpool to adaptiveavgpool like this:\n```python\nmodel = resnext 50()\nmodel.avg_pool = nn.AdaptiveAvgPool2d(1)\n```",
    "447892": "Thanks",
    "447966": "The elements in Id column are objects from pathlib, the method gets you the absolute path to the image file.",
    "448781": "pascal1129\nThanks for sharing,does the train code need to be changed?I changed it in your way, but I got it wrong.\nIf you don’t change how to judge the gap between train and val.",
    "448921": "Indeed, I changed lots, but the details are difficult to explain here.",
    "448944": "ok,thanks",
    "1496033": "Thanks for sharing. This has really made me learn a lot. I also found that change to (better) model or let the image size larger could get better results."
  },
  "source": "meta"
}