{
  "id": 375035,
  "title": "Inference and submission failure",
  "url": "/competitions/rsna-breast-cancer-detection/discussion/375035",
  "author_name": "Sarmad_mueen",
  "post_date": "2022-12-30T00:52:28.914000",
  "votes": 0,
  "comment_count": 0,
  "views": 0,
  "content": "<p>Hi<br>\nI'm using the below code for inference and submission, but it fails every time I try to submit and get the score, could you please help me to find out the problem.</p>\n<pre><code>     SAVE_FOLDER = \n     test_images = glob.glob()\n     os.makedirs(SAVE_FOLDER, exist_ok=)\n       ():\n        patient = f.split()[-]\n        image = f.split()[-][:-]\n        dicom = pydicom.dcmread(f)\n        img = dicom.pixel_array\n        img = (img - img.()) / (img.() - img.())\n         dicom.PhotometricInterpretation == :\n            img =  - img\n        img = cv2.resize(img, (size, size))\n        cv2.imwrite(save_folder + , (img * ).astype(np.uint8))\n       _ = Parallel(n_jobs=)(\n           delayed(process)(uid, size=SIZE, save_folder=SAVE_FOLDER, extension=EXTENSION)\n            uid  tqdm(test_images)\n</code></pre>\n<p>To predict every image in the test folder:</p>\n<pre><code>      test_im = glob.glob()\n      preds=[]\n       img  (test_im):\n                image = tf.keras.preprocessing.image.load_img(img)\n                image=tf.expand_dims(np.array(image), )\n                pred=model.predict(np.asarray(image))\n                preds.append(pred)\n</code></pre>\n<p>Save predicts in df and submit .csv</p>\n<pre><code>pred_df = pd.DataFrame({:test_df.prediction_id, :preds})\npred_df[]=(pred_df.cancer &gt; ).astype()\npred_df.to_csv(, index=)\n</code></pre>",
  "messages": [
    {
      "id": 2080219,
      "postDate": "2022-12-30T00:52:28.913Z",
      "content": "<p>Hi<br>\nI'm using the below code for inference and submission, but it fails every time I try to submit and get the score, could you please help me to find out the problem.</p>\n<pre><code>     SAVE_FOLDER = \n     test_images = glob.glob()\n     os.makedirs(SAVE_FOLDER, exist_ok=)\n       ():\n        patient = f.split()[-]\n        image = f.split()[-][:-]\n        dicom = pydicom.dcmread(f)\n        img = dicom.pixel_array\n        img = (img - img.()) / (img.() - img.())\n         dicom.PhotometricInterpretation == :\n            img =  - img\n        img = cv2.resize(img, (size, size))\n        cv2.imwrite(save_folder + , (img * ).astype(np.uint8))\n       _ = Parallel(n_jobs=)(\n           delayed(process)(uid, size=SIZE, save_folder=SAVE_FOLDER, extension=EXTENSION)\n            uid  tqdm(test_images)\n</code></pre>\n<p>To predict every image in the test folder:</p>\n<pre><code>      test_im = glob.glob()\n      preds=[]\n       img  (test_im):\n                image = tf.keras.preprocessing.image.load_img(img)\n                image=tf.expand_dims(np.array(image), )\n                pred=model.predict(np.asarray(image))\n                preds.append(pred)\n</code></pre>\n<p>Save predicts in df and submit .csv</p>\n<pre><code>pred_df = pd.DataFrame({:test_df.prediction_id, :preds})\npred_df[]=(pred_df.cancer &gt; ).astype()\npred_df.to_csv(, index=)\n</code></pre>",
      "rawMarkdown": "\nHi\n\nI'm using the below code for inference and submission, but it fails every time I try to submit and get the score, could you please help me to find out the problem.\n\n    ```python\n      SAVE_FOLDER = \"/kaggle/tmp/output/\"\n      test_images = glob.glob(\"/kaggle/input/rsna-breast-cancer-detection/test_images/*/*.dcm\")\n      os.makedirs(SAVE_FOLDER, exist_ok=True)\n\n       def process(f, size=512, save_folder=\"\", extension=\"png\"):\n         patient = f.split('/')[-2]\n         image = f.split('/')[-1][:-4]\n\n         dicom = pydicom.dcmread(f)\n         img = dicom.pixel_array\n\n         img = (img - img.min()) / (img.max() - img.min())\n\n         if dicom.PhotometricInterpretation == \"MONOCHROME1\":\n             img = 1 - img\n\n         img = cv2.resize(img, (size, size))\n         cv2.imwrite(save_folder + f\"{patient}_{image}.{extension}\", (img * 255).astype(np.uint8))\n\n\n        _ = Parallel(n_jobs=2)(\n            delayed(process)(uid, size=SIZE, save_folder=SAVE_FOLDER, extension=EXTENSION)\n            for uid in tqdm(test_images)\n       \n```\nTo predict every image in the test folder:\n\n\n ```python\n       test_im = glob.glob(\"//kaggle/tmp/output/*.png\")\n       preds=[]\n       for img in (test_im):\n\n                 image = tf.keras.preprocessing.image.load_img(img)\n                 image=tf.expand_dims(np.array(image), 0)\n                 pred=model.predict(np.asarray(image))\n                 preds.append(pred)\n\n```\n\nSave predicts in df and submit .csv\n\n```python\npred_df = pd.DataFrame({'prediction_id':test_df.prediction_id, 'cancer':preds})\npred_df['cancer']=(pred_df.cancer > 0.5).astype(int)\npred_df.to_csv('sample_submission.csv', index=False)\n```"
    }
  ],
  "comments": [],
  "raw_markdown_by_id": {
    "2080219": "\nHi\n\nI'm using the below code for inference and submission, but it fails every time I try to submit and get the score, could you please help me to find out the problem.\n\n    ```python\n      SAVE_FOLDER = \"/kaggle/tmp/output/\"\n      test_images = glob.glob(\"/kaggle/input/rsna-breast-cancer-detection/test_images/*/*.dcm\")\n      os.makedirs(SAVE_FOLDER, exist_ok=True)\n\n       def process(f, size=512, save_folder=\"\", extension=\"png\"):\n         patient = f.split('/')[-2]\n         image = f.split('/')[-1][:-4]\n\n         dicom = pydicom.dcmread(f)\n         img = dicom.pixel_array\n\n         img = (img - img.min()) / (img.max() - img.min())\n\n         if dicom.PhotometricInterpretation == \"MONOCHROME1\":\n             img = 1 - img\n\n         img = cv2.resize(img, (size, size))\n         cv2.imwrite(save_folder + f\"{patient}_{image}.{extension}\", (img * 255).astype(np.uint8))\n\n\n        _ = Parallel(n_jobs=2)(\n            delayed(process)(uid, size=SIZE, save_folder=SAVE_FOLDER, extension=EXTENSION)\n            for uid in tqdm(test_images)\n       \n```\nTo predict every image in the test folder:\n\n\n ```python\n       test_im = glob.glob(\"//kaggle/tmp/output/*.png\")\n       preds=[]\n       for img in (test_im):\n\n                 image = tf.keras.preprocessing.image.load_img(img)\n                 image=tf.expand_dims(np.array(image), 0)\n                 pred=model.predict(np.asarray(image))\n                 preds.append(pred)\n\n```\n\nSave predicts in df and submit .csv\n\n```python\npred_df = pd.DataFrame({'prediction_id':test_df.prediction_id, 'cancer':preds})\npred_df['cancer']=(pred_df.cancer > 0.5).astype(int)\npred_df.to_csv('sample_submission.csv', index=False)\n```"
  }
}