{
  "id": 135829,
  "title": "Fastai batch predictions from image array",
  "url": "/competitions/bengaliai-cv19/discussion/135829",
  "author_name": "",
  "post_date": "2020-03-16T08:33:05.500295400Z",
  "votes": null,
  "comment_count": 1,
  "views": 0,
  "content": "<p>Hello friends, I am new to Kaggle and the Fastai library. I think I have a good model but my submissions are timing out since I'm iterating over the dataframe rows</p>\n\n<p>This works fine for single predictions, where img is np array obtained from the dataset, but this is excruciatingly slow\n<code>learn = load_learner(PATH)</code>\n<code>img = Image(pil2tensor(img,  dtype=np.float32).div_(255))</code>\n<code>preds = learn.predict(img)</code></p>\n\n<p>I've also referred to lafoss's extremely helpful kernel and tried to convert the images to tensors. I somehow got the batch prediction working but the predicted probabilities are way off. I'm not familiar enough with PyTorch to debug it right now.</p>\n\n<p>I'd be greatfull for any pointers as I really want to make this my first submission. Thank you!</p>",
  "messages": [
    {
      "id": "775052",
      "postDate": "03/16/2020 08:33:05",
      "content": "<p>Hello friends, I am new to Kaggle and the Fastai library. I think I have a good model but my submissions are timing out since I'm iterating over the dataframe rows</p>\n\n<p>This works fine for single predictions, where img is np array obtained from the dataset, but this is excruciatingly slow\n<code>learn = load_learner(PATH)</code>\n<code>img = Image(pil2tensor(img,  dtype=np.float32).div_(255))</code>\n<code>preds = learn.predict(img)</code></p>\n\n<p>I've also referred to lafoss's extremely helpful kernel and tried to convert the images to tensors. I somehow got the batch prediction working but the predicted probabilities are way off. I'm not familiar enough with PyTorch to debug it right now.</p>\n\n<p>I'd be greatfull for any pointers as I really want to make this my first submission. Thank you!</p>",
      "rawMarkdown": "Hello friends, I am new to Kaggle and the Fastai library. I think I have a good model but my submissions are timing out since I'm iterating over the dataframe rows\n\nThis works fine for single predictions, where img is np array obtained from the dataset, but this is excruciatingly slow\n`learn = load_learner(PATH)`\n`img = Image(pil2tensor(img,  dtype=np.float32).div_(255))`\n`preds = learn.predict(img)`\n\nI've also referred to lafoss's extremely helpful kernel and tried to convert the images to tensors. I somehow got the batch prediction working but the predicted probabilities are way off. I'm not familiar enough with PyTorch to debug it right now.\n\nI'd be greatfull for any pointers as I really want to make this my first submission. Thank you!",
      "votes": null
    },
    {
      "id": "775468",
      "postDate": "03/16/2020 17:56:27",
      "content": "<p>Figured it out, <code>gc.collect()</code> sitting right in the loop was slowing it down. Prediction is fast enough even without batches so bombs away! Hope it executes on time. </p>",
      "rawMarkdown": "Figured it out, `gc.collect()` sitting right in the loop was slowing it down. Prediction is fast enough even without batches so bombs away! Hope it executes on time.",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 775468,
      "author_name": "sbpdev",
      "author_url": "",
      "post_date": "03/16/2020 17:56:27",
      "content": "<p>Figured it out, <code>gc.collect()</code> sitting right in the loop was slowing it down. Prediction is fast enough even without batches so bombs away! Hope it executes on time. </p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "775052": "Hello friends, I am new to Kaggle and the Fastai library. I think I have a good model but my submissions are timing out since I'm iterating over the dataframe rows\n\nThis works fine for single predictions, where img is np array obtained from the dataset, but this is excruciatingly slow\n`learn = load_learner(PATH)`\n`img = Image(pil2tensor(img,  dtype=np.float32).div_(255))`\n`preds = learn.predict(img)`\n\nI've also referred to lafoss's extremely helpful kernel and tried to convert the images to tensors. I somehow got the batch prediction working but the predicted probabilities are way off. I'm not familiar enough with PyTorch to debug it right now.\n\nI'd be greatfull for any pointers as I really want to make this my first submission. Thank you!",
    "775468": "Figured it out, `gc.collect()` sitting right in the loop was slowing it down. Prediction is fast enough even without batches so bombs away! Hope it executes on time."
  },
  "source": "meta"
}