{
  "id": 218936,
  "title": "Please help Submission csv not found error?",
  "url": "/competitions/cassava-leaf-disease-classification/discussion/218936",
  "author_name": "",
  "post_date": "2021-02-12T18:20:07.820051500Z",
  "votes": null,
  "comment_count": 6,
  "views": 0,
  "content": "<p>if <strong>name</strong> == '<strong>main</strong>':</p>\n<pre><code>seed_everything(CFG['seed'])\n\nfolds = StratifiedKFold(n_splits=CFG['fold_num']).split(np.arange(train.shape[0]), train.label.values)\n\nfor fold, (trn_idx, val_idx) in enumerate(folds):\n\n    if fold &gt; 0:\n        break \n\n    print('Inference fold {} started'.format(fold))\n\n    valid_ = train.loc[val_idx,:].reset_index(drop=True)\n    valid_ds = CassavaDataset(valid_, '../input/cassava-leaf-disease-classification/train_images/', transforms=get_inference_transforms(), output_label=False)\n\n    test = pd.DataFrame()\n    test['image_id'] = list(os.listdir('../input/cassava-leaf-disease-classification/test_images/'))\n    test_ds = CassavaDataset(test, '../input/cassava-leaf-disease-classification/test_images/', transforms=get_inference_transforms(), output_label=False)\n\n    val_loader = torch.utils.data.DataLoader(\n        valid_ds, \n        batch_size=CFG['valid_bs'],\n        num_workers=CFG['num_workers'],\n        shuffle=False,\n        pin_memory=False,\n    )\n\n    tst_loader = torch.utils.data.DataLoader(\n        test_ds, \n        batch_size=CFG['valid_bs'],\n        num_workers=CFG['num_workers'],\n        shuffle=False,\n        pin_memory=False,\n    )\n\n    device = torch.device(CFG['device'])\n    model = CassvaImgClassifier(CFG['model_arch'], train.label.nunique()).to(device)\n\n    val_preds = []\n    tst_preds = []\n\n    #for epoch in range(CFG['epochs']-3):\n    for i, epoch in enumerate(CFG['used_epochs']):    \n        model.load_state_dict(torch.load('../input/project-cassava-leaf-disease/{}_fold_{}_{}'.format(CFG['model_arch'], fold, epoch)))\n\n        with torch.no_grad():\n            for _ in range(CFG['tta']):\n                val_preds += [CFG['weights'][i]/sum(CFG['weights'])/CFG['tta']*inference_one_epoch(model, val_loader, device)]\n                tst_preds += [CFG['weights'][i]/sum(CFG['weights'])/CFG['tta']*inference_one_epoch(model, tst_loader, device)]\n\n    val_preds = np.mean(val_preds, axis=0) \n    tst_preds = np.mean(tst_preds, axis=0) \n\n    print('fold {} validation loss = {:.5f}'.format(fold, log_loss(valid_.label.values, val_preds)))\n    print('fold {} validation accuracy = {:.5f}'.format(fold, (valid_.label.values==np.argmax(val_preds, axis=1)).mean()))\n\n    del model\n    torch.cuda.empty_cache()\n    test['label'] = np.argmax(tst_preds, axis=1)\n    test.head()\n    test.to_csv('submission.csv', index=False)\n    print(test)\n</code></pre>",
  "messages": [
    {
      "id": "1198114",
      "postDate": "02/12/2021 18:20:07",
      "content": "<p>if <strong>name</strong> == '<strong>main</strong>':</p>\n<pre><code>seed_everything(CFG['seed'])\n\nfolds = StratifiedKFold(n_splits=CFG['fold_num']).split(np.arange(train.shape[0]), train.label.values)\n\nfor fold, (trn_idx, val_idx) in enumerate(folds):\n\n    if fold &gt; 0:\n        break \n\n    print('Inference fold {} started'.format(fold))\n\n    valid_ = train.loc[val_idx,:].reset_index(drop=True)\n    valid_ds = CassavaDataset(valid_, '../input/cassava-leaf-disease-classification/train_images/', transforms=get_inference_transforms(), output_label=False)\n\n    test = pd.DataFrame()\n    test['image_id'] = list(os.listdir('../input/cassava-leaf-disease-classification/test_images/'))\n    test_ds = CassavaDataset(test, '../input/cassava-leaf-disease-classification/test_images/', transforms=get_inference_transforms(), output_label=False)\n\n    val_loader = torch.utils.data.DataLoader(\n        valid_ds, \n        batch_size=CFG['valid_bs'],\n        num_workers=CFG['num_workers'],\n        shuffle=False,\n        pin_memory=False,\n    )\n\n    tst_loader = torch.utils.data.DataLoader(\n        test_ds, \n        batch_size=CFG['valid_bs'],\n        num_workers=CFG['num_workers'],\n        shuffle=False,\n        pin_memory=False,\n    )\n\n    device = torch.device(CFG['device'])\n    model = CassvaImgClassifier(CFG['model_arch'], train.label.nunique()).to(device)\n\n    val_preds = []\n    tst_preds = []\n\n    #for epoch in range(CFG['epochs']-3):\n    for i, epoch in enumerate(CFG['used_epochs']):    \n        model.load_state_dict(torch.load('../input/project-cassava-leaf-disease/{}_fold_{}_{}'.format(CFG['model_arch'], fold, epoch)))\n\n        with torch.no_grad():\n            for _ in range(CFG['tta']):\n                val_preds += [CFG['weights'][i]/sum(CFG['weights'])/CFG['tta']*inference_one_epoch(model, val_loader, device)]\n                tst_preds += [CFG['weights'][i]/sum(CFG['weights'])/CFG['tta']*inference_one_epoch(model, tst_loader, device)]\n\n    val_preds = np.mean(val_preds, axis=0) \n    tst_preds = np.mean(tst_preds, axis=0) \n\n    print('fold {} validation loss = {:.5f}'.format(fold, log_loss(valid_.label.values, val_preds)))\n    print('fold {} validation accuracy = {:.5f}'.format(fold, (valid_.label.values==np.argmax(val_preds, axis=1)).mean()))\n\n    del model\n    torch.cuda.empty_cache()\n    test['label'] = np.argmax(tst_preds, axis=1)\n    test.head()\n    test.to_csv('submission.csv', index=False)\n    print(test)\n</code></pre>",
      "rawMarkdown": "if __name__ == '__main__':\n \n\n    seed_everything(CFG['seed'])\n    \n    folds = StratifiedKFold(n_splits=CFG['fold_num']).split(np.arange(train.shape[0]), train.label.values)\n    \n    for fold, (trn_idx, val_idx) in enumerate(folds):\n        \n        if fold > 0:\n            break \n\n        print('Inference fold {} started'.format(fold))\n\n        valid_ = train.loc[val_idx,:].reset_index(drop=True)\n        valid_ds = CassavaDataset(valid_, '../input/cassava-leaf-disease-classification/train_images/', transforms=get_inference_transforms(), output_label=False)\n        \n        test = pd.DataFrame()\n        test['image_id'] = list(os.listdir('../input/cassava-leaf-disease-classification/test_images/'))\n        test_ds = CassavaDataset(test, '../input/cassava-leaf-disease-classification/test_images/', transforms=get_inference_transforms(), output_label=False)\n        \n        val_loader = torch.utils.data.DataLoader(\n            valid_ds, \n            batch_size=CFG['valid_bs'],\n            num_workers=CFG['num_workers'],\n            shuffle=False,\n            pin_memory=False,\n        )\n        \n        tst_loader = torch.utils.data.DataLoader(\n            test_ds, \n            batch_size=CFG['valid_bs'],\n            num_workers=CFG['num_workers'],\n            shuffle=False,\n            pin_memory=False,\n        )\n\n        device = torch.device(CFG['device'])\n        model = CassvaImgClassifier(CFG['model_arch'], train.label.nunique()).to(device)\n        \n        val_preds = []\n        tst_preds = []\n        \n        #for epoch in range(CFG['epochs']-3):\n        for i, epoch in enumerate(CFG['used_epochs']):    \n            model.load_state_dict(torch.load('../input/project-cassava-leaf-disease/{}_fold_{}_{}'.format(CFG['model_arch'], fold, epoch)))\n            \n            with torch.no_grad():\n                for _ in range(CFG['tta']):\n                    val_preds += [CFG['weights'][i]/sum(CFG['weights'])/CFG['tta']*inference_one_epoch(model, val_loader, device)]\n                    tst_preds += [CFG['weights'][i]/sum(CFG['weights'])/CFG['tta']*inference_one_epoch(model, tst_loader, device)]\n\n        val_preds = np.mean(val_preds, axis=0) \n        tst_preds = np.mean(tst_preds, axis=0) \n        \n        print('fold {} validation loss = {:.5f}'.format(fold, log_loss(valid_.label.values, val_preds)))\n        print('fold {} validation accuracy = {:.5f}'.format(fold, (valid_.label.values==np.argmax(val_preds, axis=1)).mean()))\n        \n        del model\n        torch.cuda.empty_cache()\n        test['label'] = np.argmax(tst_preds, axis=1)\n        test.head()\n        test.to_csv('submission.csv', index=False)\n        print(test)",
      "votes": null
    },
    {
      "id": "1198162",
      "postDate": "02/12/2021 19:10:21",
      "content": "<p>This might help: <a href=\"https://www.kaggle.com/c/cassava-leaf-disease-classification/discussion/215962\" target=\"_blank\">https://www.kaggle.com/c/cassava-leaf-disease-classification/discussion/215962</a></p>",
      "rawMarkdown": "This might help: https://www.kaggle.com/c/cassava-leaf-disease-classification/discussion/215962",
      "votes": null
    },
    {
      "id": "1198266",
      "postDate": "02/12/2021 20:59:32",
      "content": "<p>Thanks for your reply but can you have a look at my code and try to figure out what should I do any suggestions will be helpful.</p>",
      "rawMarkdown": "Thanks for your reply but can you have a look at my code and try to figure out what should I do any suggestions will be helpful.",
      "votes": null
    },
    {
      "id": "1198270",
      "postDate": "02/12/2021 21:04:02",
      "content": "<p>Hard to debug without knowing  what inference_one_epoch is. If you look at the recommendation in the post, you can try scoring the train dataset using your logic and see if you get a submission.csv. More than likely, there is an error in the code and it doesnt produce that file. </p>",
      "rawMarkdown": "Hard to debug without knowing  what inference_one_epoch is. If you look at the recommendation in the post, you can try scoring the train dataset using your logic and see if you get a submission.csv. More than likely, there is an error in the code and it doesnt produce that file.",
      "votes": null
    },
    {
      "id": "1198769",
      "postDate": "02/13/2021 09:34:33",
      "content": "<p>def inference_one_epoch(model, data_loader, device):<br>\n    model.eval()</p>\n<pre><code>image_preds_all = []\n\npbar = tqdm(enumerate(data_loader), total=len(data_loader))\nfor step, (imgs) in pbar:\n    imgs = imgs.to(device).float()\n\n    image_preds = model(imgs)   #output = model(input)\n    image_preds_all += [torch.softmax(image_preds, 1).detach().cpu().numpy()]\n\n\nimage_preds_all = np.concatenate(image_preds_all, axis=0)\nreturn image_preds_all\n</code></pre>\n<p>this is inference_one_epoch</p>",
      "rawMarkdown": "def inference_one_epoch(model, data_loader, device):\n    model.eval()\n\n    image_preds_all = []\n    \n    pbar = tqdm(enumerate(data_loader), total=len(data_loader))\n    for step, (imgs) in pbar:\n        imgs = imgs.to(device).float()\n        \n        image_preds = model(imgs)   #output = model(input)\n        image_preds_all += [torch.softmax(image_preds, 1).detach().cpu().numpy()]\n        \n    \n    image_preds_all = np.concatenate(image_preds_all, axis=0)\n    return image_preds_all\nthis is inference_one_epoch",
      "votes": null
    },
    {
      "id": "1199363",
      "postDate": "02/13/2021 19:09:20",
      "content": "<p>did you try the recommendation? </p>",
      "rawMarkdown": "did you try the recommendation?",
      "votes": null
    },
    {
      "id": "1200330",
      "postDate": "02/14/2021 15:28:06",
      "content": "<p>Yes I changed the test path with train path and it produces a 21000 pedictions.</p>",
      "rawMarkdown": "Yes I changed the test path with train path and it produces a 21000 pedictions.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1198162,
      "author_name": "trushk",
      "author_url": "",
      "post_date": "02/12/2021 19:10:21",
      "content": "<p>This might help: <a href=\"https://www.kaggle.com/c/cassava-leaf-disease-classification/discussion/215962\" target=\"_blank\">https://www.kaggle.com/c/cassava-leaf-disease-classification/discussion/215962</a></p>",
      "votes": null,
      "replies": [
        {
          "id": 1198266,
          "author_name": "riyajm",
          "author_url": "",
          "post_date": "02/12/2021 20:59:32",
          "content": "<p>Thanks for your reply but can you have a look at my code and try to figure out what should I do any suggestions will be helpful.</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1198270,
          "author_name": "trushk",
          "author_url": "",
          "post_date": "02/12/2021 21:04:02",
          "content": "<p>Hard to debug without knowing  what inference_one_epoch is. If you look at the recommendation in the post, you can try scoring the train dataset using your logic and see if you get a submission.csv. More than likely, there is an error in the code and it doesnt produce that file. </p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1198769,
          "author_name": "riyajm",
          "author_url": "",
          "post_date": "02/13/2021 09:34:33",
          "content": "<p>def inference_one_epoch(model, data_loader, device):<br>\n    model.eval()</p>\n<pre><code>image_preds_all = []\n\npbar = tqdm(enumerate(data_loader), total=len(data_loader))\nfor step, (imgs) in pbar:\n    imgs = imgs.to(device).float()\n\n    image_preds = model(imgs)   #output = model(input)\n    image_preds_all += [torch.softmax(image_preds, 1).detach().cpu().numpy()]\n\n\nimage_preds_all = np.concatenate(image_preds_all, axis=0)\nreturn image_preds_all\n</code></pre>\n<p>this is inference_one_epoch</p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1199363,
          "author_name": "trushk",
          "author_url": "",
          "post_date": "02/13/2021 19:09:20",
          "content": "<p>did you try the recommendation? </p>",
          "votes": null,
          "replies": []
        },
        {
          "id": 1200330,
          "author_name": "riyajm",
          "author_url": "",
          "post_date": "02/14/2021 15:28:06",
          "content": "<p>Yes I changed the test path with train path and it produces a 21000 pedictions.</p>",
          "votes": null,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "1198114": "if __name__ == '__main__':\n \n\n    seed_everything(CFG['seed'])\n    \n    folds = StratifiedKFold(n_splits=CFG['fold_num']).split(np.arange(train.shape[0]), train.label.values)\n    \n    for fold, (trn_idx, val_idx) in enumerate(folds):\n        \n        if fold > 0:\n            break \n\n        print('Inference fold {} started'.format(fold))\n\n        valid_ = train.loc[val_idx,:].reset_index(drop=True)\n        valid_ds = CassavaDataset(valid_, '../input/cassava-leaf-disease-classification/train_images/', transforms=get_inference_transforms(), output_label=False)\n        \n        test = pd.DataFrame()\n        test['image_id'] = list(os.listdir('../input/cassava-leaf-disease-classification/test_images/'))\n        test_ds = CassavaDataset(test, '../input/cassava-leaf-disease-classification/test_images/', transforms=get_inference_transforms(), output_label=False)\n        \n        val_loader = torch.utils.data.DataLoader(\n            valid_ds, \n            batch_size=CFG['valid_bs'],\n            num_workers=CFG['num_workers'],\n            shuffle=False,\n            pin_memory=False,\n        )\n        \n        tst_loader = torch.utils.data.DataLoader(\n            test_ds, \n            batch_size=CFG['valid_bs'],\n            num_workers=CFG['num_workers'],\n            shuffle=False,\n            pin_memory=False,\n        )\n\n        device = torch.device(CFG['device'])\n        model = CassvaImgClassifier(CFG['model_arch'], train.label.nunique()).to(device)\n        \n        val_preds = []\n        tst_preds = []\n        \n        #for epoch in range(CFG['epochs']-3):\n        for i, epoch in enumerate(CFG['used_epochs']):    \n            model.load_state_dict(torch.load('../input/project-cassava-leaf-disease/{}_fold_{}_{}'.format(CFG['model_arch'], fold, epoch)))\n            \n            with torch.no_grad():\n                for _ in range(CFG['tta']):\n                    val_preds += [CFG['weights'][i]/sum(CFG['weights'])/CFG['tta']*inference_one_epoch(model, val_loader, device)]\n                    tst_preds += [CFG['weights'][i]/sum(CFG['weights'])/CFG['tta']*inference_one_epoch(model, tst_loader, device)]\n\n        val_preds = np.mean(val_preds, axis=0) \n        tst_preds = np.mean(tst_preds, axis=0) \n        \n        print('fold {} validation loss = {:.5f}'.format(fold, log_loss(valid_.label.values, val_preds)))\n        print('fold {} validation accuracy = {:.5f}'.format(fold, (valid_.label.values==np.argmax(val_preds, axis=1)).mean()))\n        \n        del model\n        torch.cuda.empty_cache()\n        test['label'] = np.argmax(tst_preds, axis=1)\n        test.head()\n        test.to_csv('submission.csv', index=False)\n        print(test)",
    "1198162": "This might help: https://www.kaggle.com/c/cassava-leaf-disease-classification/discussion/215962",
    "1198266": "Thanks for your reply but can you have a look at my code and try to figure out what should I do any suggestions will be helpful.",
    "1198270": "Hard to debug without knowing  what inference_one_epoch is. If you look at the recommendation in the post, you can try scoring the train dataset using your logic and see if you get a submission.csv. More than likely, there is an error in the code and it doesnt produce that file.",
    "1198769": "def inference_one_epoch(model, data_loader, device):\n    model.eval()\n\n    image_preds_all = []\n    \n    pbar = tqdm(enumerate(data_loader), total=len(data_loader))\n    for step, (imgs) in pbar:\n        imgs = imgs.to(device).float()\n        \n        image_preds = model(imgs)   #output = model(input)\n        image_preds_all += [torch.softmax(image_preds, 1).detach().cpu().numpy()]\n        \n    \n    image_preds_all = np.concatenate(image_preds_all, axis=0)\n    return image_preds_all\nthis is inference_one_epoch",
    "1199363": "did you try the recommendation?",
    "1200330": "Yes I changed the test path with train path and it produces a 21000 pedictions."
  },
  "source": "meta"
}