{
  "id": 245274,
  "title": "Saving jpeg images",
  "url": "/competitions/siim-covid19-detection/discussion/245274",
  "author_name": "",
  "post_date": "2021-06-10T10:55:13.802131900Z",
  "votes": 4,
  "comment_count": 2,
  "views": 0,
  "content": "<p>Hi All,<br>\nI would converted the dicom files to jpeg and saved it in /kaggle/working/study/train folder.</p>\n<p>However, when I restart the notebook, everything get deleted.<br>\nIs there is away I can save them permanently the images in a directory?</p>\n<p>Thanks a lot!!</p>",
  "messages": [
    {
      "id": "1343655",
      "postDate": "06/10/2021 10:55:13",
      "content": "<p>Hi All,<br>\nI would converted the dicom files to jpeg and saved it in /kaggle/working/study/train folder.</p>\n<p>However, when I restart the notebook, everything get deleted.<br>\nIs there is away I can save them permanently the images in a directory?</p>\n<p>Thanks a lot!!</p>",
      "rawMarkdown": "Hi All,\nI would converted the dicom files to jpeg and saved it in /kaggle/working/study/train folder.\n\nHowever, when I restart the notebook, everything get deleted.\nIs there is away I can save them permanently the images in a directory?\n\nThanks a lot!!",
      "votes": null
    },
    {
      "id": "1343876",
      "postDate": "06/10/2021 13:45:40",
      "content": "<p>I also faced this problem as a beginner. One way to solve it is to do the dicom to jpg conversion in a separate notebook and save the converted images in that notebook's output. You can then access those converted images from any other notebook.</p>\n<p>These are the steps:</p>\n<p>1- Create a notebook. Let’s call it jpg-Converter. In this notebook you should write the code that does the dicom to jpg conversion.</p>\n<p>2- Create a folder to store your images:</p>\n<pre><code>import os\nimages_dir = 'images_dir'\nos.mkdir(images_dir)\n</code></pre>\n<p>3- Write your code to convert your images. Store the converted images in  images_dir.</p>\n<p>4- Compress images_dir. Don’t forget the dot at the end. The images are being saved in a compressed folder called images.tar.gz.</p>\n<p><code>!tar -zcf images.tar.gz -C \"images_dir/\" .</code></p>\n<p>5- Delete images_dir. Kaggle only allows a max of 500 files to be in a notebook output. If you don’t delete images_dir your notebook commit will fail and you won’t know why.</p>\n<pre><code>import shutil\n\nif os.path.isdir('images_dir') == True:\n    shutil.rmtree('images_dir')\n</code></pre>\n<p>6- Commit the jpg-Converter notebook.</p>\n<p>7- Add jp-converter notebook to the notebook where you will be training your model. This can be done by clicking the&nbsp;<strong>+ Add Data</strong>&nbsp;link located in the top right corner, and then searching for jpg-Converter.</p>\n<p>8-  Set the path to images.tar.gz and extract the images.</p>\n<pre><code>import tarfile\n\n# Create a folder to store the extracted files\nif os.path.isdir('images_dir') == False:\n    images_dir = 'images_dir'\n    os.mkdir(images_dir)\n\npath = '../input/jpg-Converter/images.tar.gz'\ntf = tarfile.open(path)\n\n# 'images_dir' is the folder where the extracted files will be stored.\ntf.extractall('images_dir') \n</code></pre>\n<p>9- Your jpg images are now in a folder called images_dir. You can use them to train your model.</p>",
      "rawMarkdown": "I also faced this problem as a beginner. One way to solve it is to do the dicom to jpg conversion in a separate notebook and save the converted images in that notebook's output. You can then access those converted images from any other notebook.\n\nThese are the steps:\n\n1- Create a notebook. Let’s call it jpg-Converter. In this notebook you should write the code that does the dicom to jpg conversion.\n\n2- Create a folder to store your images:\n\n```\nimport os\nimages_dir = 'images_dir'\nos.mkdir(images_dir)\n```\n\n3- Write your code to convert your images. Store the converted images in  images_dir.\n\n4- Compress images_dir. Don’t forget the dot at the end. The images are being saved in a compressed folder called images.tar.gz.\n\n`!tar -zcf images.tar.gz -C \"images_dir/\" .`\n\n5- Delete images_dir. Kaggle only allows a max of 500 files to be in a notebook output. If you don’t delete images_dir your notebook commit will fail and you won’t know why.\n\n```\nimport shutil\n\nif os.path.isdir('images_dir') == True:\n    shutil.rmtree('images_dir')\n```\n\n6- Commit the jpg-Converter notebook.\n\n7- Add jp-converter notebook to the notebook where you will be training your model. This can be done by clicking the **+ Add Data** link located in the top right corner, and then searching for jpg-Converter.\n\n8-  Set the path to images.tar.gz and extract the images.\n\n```\nimport tarfile\n\n# Create a folder to store the extracted files\nif os.path.isdir('images_dir') == False:\n    images_dir = 'images_dir'\n    os.mkdir(images_dir)\n\npath = '../input/jpg-Converter/images.tar.gz'\ntf = tarfile.open(path)\n\n# 'images_dir' is the folder where the extracted files will be stored.\ntf.extractall('images_dir') \n```\n\n9- Your jpg images are now in a folder called images_dir. You can use them to train your model.",
      "votes": null
    },
    {
      "id": "1344618",
      "postDate": "06/11/2021 03:58:28",
      "content": "<p>Hi,<br>\nThanks a lot for the reply. Will try!</p>",
      "rawMarkdown": "Hi,\nThanks a lot for the reply. Will try!",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 1343876,
      "author_name": "vbookshelf",
      "author_url": "",
      "post_date": "06/10/2021 13:45:40",
      "content": "<p>I also faced this problem as a beginner. One way to solve it is to do the dicom to jpg conversion in a separate notebook and save the converted images in that notebook's output. You can then access those converted images from any other notebook.</p>\n<p>These are the steps:</p>\n<p>1- Create a notebook. Let’s call it jpg-Converter. In this notebook you should write the code that does the dicom to jpg conversion.</p>\n<p>2- Create a folder to store your images:</p>\n<pre><code>import os\nimages_dir = 'images_dir'\nos.mkdir(images_dir)\n</code></pre>\n<p>3- Write your code to convert your images. Store the converted images in  images_dir.</p>\n<p>4- Compress images_dir. Don’t forget the dot at the end. The images are being saved in a compressed folder called images.tar.gz.</p>\n<p><code>!tar -zcf images.tar.gz -C \"images_dir/\" .</code></p>\n<p>5- Delete images_dir. Kaggle only allows a max of 500 files to be in a notebook output. If you don’t delete images_dir your notebook commit will fail and you won’t know why.</p>\n<pre><code>import shutil\n\nif os.path.isdir('images_dir') == True:\n    shutil.rmtree('images_dir')\n</code></pre>\n<p>6- Commit the jpg-Converter notebook.</p>\n<p>7- Add jp-converter notebook to the notebook where you will be training your model. This can be done by clicking the&nbsp;<strong>+ Add Data</strong>&nbsp;link located in the top right corner, and then searching for jpg-Converter.</p>\n<p>8-  Set the path to images.tar.gz and extract the images.</p>\n<pre><code>import tarfile\n\n# Create a folder to store the extracted files\nif os.path.isdir('images_dir') == False:\n    images_dir = 'images_dir'\n    os.mkdir(images_dir)\n\npath = '../input/jpg-Converter/images.tar.gz'\ntf = tarfile.open(path)\n\n# 'images_dir' is the folder where the extracted files will be stored.\ntf.extractall('images_dir') \n</code></pre>\n<p>9- Your jpg images are now in a folder called images_dir. You can use them to train your model.</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 1344618,
      "author_name": "radike",
      "author_url": "",
      "post_date": "06/11/2021 03:58:28",
      "content": "<p>Hi,<br>\nThanks a lot for the reply. Will try!</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "1343655": "Hi All,\nI would converted the dicom files to jpeg and saved it in /kaggle/working/study/train folder.\n\nHowever, when I restart the notebook, everything get deleted.\nIs there is away I can save them permanently the images in a directory?\n\nThanks a lot!!",
    "1343876": "I also faced this problem as a beginner. One way to solve it is to do the dicom to jpg conversion in a separate notebook and save the converted images in that notebook's output. You can then access those converted images from any other notebook.\n\nThese are the steps:\n\n1- Create a notebook. Let’s call it jpg-Converter. In this notebook you should write the code that does the dicom to jpg conversion.\n\n2- Create a folder to store your images:\n\n```\nimport os\nimages_dir = 'images_dir'\nos.mkdir(images_dir)\n```\n\n3- Write your code to convert your images. Store the converted images in  images_dir.\n\n4- Compress images_dir. Don’t forget the dot at the end. The images are being saved in a compressed folder called images.tar.gz.\n\n`!tar -zcf images.tar.gz -C \"images_dir/\" .`\n\n5- Delete images_dir. Kaggle only allows a max of 500 files to be in a notebook output. If you don’t delete images_dir your notebook commit will fail and you won’t know why.\n\n```\nimport shutil\n\nif os.path.isdir('images_dir') == True:\n    shutil.rmtree('images_dir')\n```\n\n6- Commit the jpg-Converter notebook.\n\n7- Add jp-converter notebook to the notebook where you will be training your model. This can be done by clicking the **+ Add Data** link located in the top right corner, and then searching for jpg-Converter.\n\n8-  Set the path to images.tar.gz and extract the images.\n\n```\nimport tarfile\n\n# Create a folder to store the extracted files\nif os.path.isdir('images_dir') == False:\n    images_dir = 'images_dir'\n    os.mkdir(images_dir)\n\npath = '../input/jpg-Converter/images.tar.gz'\ntf = tarfile.open(path)\n\n# 'images_dir' is the folder where the extracted files will be stored.\ntf.extractall('images_dir') \n```\n\n9- Your jpg images are now in a folder called images_dir. You can use them to train your model.",
    "1344618": "Hi,\nThanks a lot for the reply. Will try!"
  },
  "source": "meta"
}