Advertisement
snip3r77

fastai wget unzip

Mar 17th, 2020
215
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. inspired from
  2. https://colab.research.google.com/github/corykendrick/fastai_in_colab/blob/master/Using_Google_Colab_for_Fastai.ipynb#scrollTo=8w2pvt26J6al
  3.  
  4. !curl -s https://course.fast.ai/setup/colab | bash
  5. %reload_ext autoreload
  6. %autoreload 2
  7.  
  8. from google.colab import drive
  9. drive.mount('/content/gdrive', force_remount=True)
  10. root_dir = "/content/gdrive/My Drive/"
  11. base_dir = root_dir + 'fastai-v3/'
  12.  
  13. %matplotlib inline
  14.  
  15. !pwd
  16.  
  17. path = Path(base_dir + 'data/planet')
  18. path
  19.  
  20. # Make sure the data is where you think it is:
  21. !ls '/content/gdrive/My Drive/fastai-v3/data/planet'
  22.  
  23. #get the train tar here
  24. #https://forums.fast.ai/t/lesson-2-amazon-dataset-no-tar-or-zip-file/63926/4
  25. #get the labelling csv from kaggle
  26. #upload both to '/content/gdrive/My Drive/fastai-v3/data/planet'
  27. #intended directory structure as reference https://i.imgur.com/dfQFUsZ.png
  28.  
  29. # In order to unzip the 7z files, need to install p7zip
  30. # This was helpful: http://forums.fast.ai/t/unzipping-tar-7z-files-in-google-collab-notebook/14857/4
  31. !apt-get install p7zip-full
  32. !apt install unzip
  33.  
  34. # unzip a file named 'train_v2.csv.zip'
  35. # no need extension to include the .zip extension
  36. # -d is the name of the directory to extract to
  37. !unzip "/content/gdrive/My Drive/fastai-v3/data/planet/train_v2.csv" -d "/content/gdrive/My Drive/fastai-v3/data/planet"
  38.  
  39. # Unzip the .tar files to 'somewhere'
  40. !tar -xvf /content/gdrive/My\ Drive/fastai-v3/data/planet/train-jpg.tar
  41.  
  42. # Move the unzipped folders('somewhere') back into data/planet/
  43. #
  44. !mv train-jpg /content/gdrive/My\ Drive/fastai-v3/data/planet/
  45.  
  46. #la di da
  47. df = pd.read_csv(path/'train_v2.csv')
  48. df.head()
Advertisement
RAW Paste Data Copied
Advertisement