"/home" directory removed in my Google Colab - google-colaboratory

I ran a python script in my notebook which accessed and wrote to "/home" directory in colab. On program exit, the home directory vanished. How do I get back my home directory? Thanks.
Raghu

Related

Google Colab: mounted Drive but unable to read files

I am doing Stanford's course CS231n on deep learning and am using Google Colab.
The initialization code and all the files are given, so all i need is just to hit "run" on the given code.
I have followed step be step the official instructions and successfully mounted Google Drive, yet i get an error when trying to read the files:
"cp: cannot stat 'cs231n/assignments/assignment1/cs231n/': No such file or directory /content".
And then some more errors.
The files are located in my drive as in the path "FOLDERNAME".
The errors i get:
How it should be:
Official instructions:
https://cs231n.github.io/assignments2020/assignment1/
How can i solve it?
Thanks!
I am having the exactly same problem as you were. And here is my solution:
delete the folder named cs231n
follow the tutorial again
3. change the path %cd drive/My\ Drive into %cd drive/MyDrive
As you can see, default setting of the folder is 'MyDrive'(without space in midddle) but not 'My Drive'(My\ Drive).
Then, everything should run as your expectation.
Cheers.
Based on the course instructions, it sounds like you need to expand the course archive in your Drive.
Quoting here:
Create a folder in your personal Google Drive and upload assignment1/
folder to the Drive folder. We recommend that you call the Google
Drive folder cs231n/assignments/ so that the final uploaded folder has
the path cs231n/assignments/assignment1/.
If you already did that, I'd check the Drive web UI to make sure that the paths line up with the course instructions, and to move the files around if there's a mismatch.

How to read images from a local drive into Google Colab

I want to run deep learning models in Google Colab that has a power GPU support. I am quite new to Colab. Originally I though I could uplod the images using os.path.join and PIL.Image.open as I did in the environment of Spyder. But the Colab gives a FileNotFoundError FileNotFoundError: [Errno 2] No such file or directory (the images indeed exist in a local directory). It seems I did not do correctly for the uploading.
You can directly upload to colab or upload images to a google drive folder. Then mount that folder in google colab to use it. On the left there is an arrow that opens a sidebar which contains searchable code snippets. Here, you can search for drive to get google drive related code snippets.
This notebook contains some examples,
https://colab.research.google.com/notebooks/snippets/drive.ipynb#scrollTo=u22w3BFiOveA
The command below list contents of folder named DeepLearning,
!ls -la "/content/gdrive/My Drive/DeepLearning"
Copy contents of drive DeepLearning folder to Virtual Machine in DeepLearning folder,
!cp /content/gdrive/My\ Drive/DeepLearning ./DeepLearning
Copy contents of Virtual Machine DeepLearning folder to google drive DeepLearning folder,
!cp ./DeepLearning /content/gdrive/My\ Drive/DeepLearning
You can run %cd DeepLearning to change directory to DeepLearning folder.
GPU support can be enabled by Runtime > Change Runtime Type > Hardware Accelerator > GPU.

How upload files to current working directory in Google Colab notebook?

I uploaded a Jupyter notebook to Google Colab. The notebook accessed a couple of images from local path /images/pic1.png How to upload data to the directory in Colab where the notebook is running? Please note that these are temporary files. So, I don't mind them being deleted on terminating the session.
I used Files upload feature but it doesn't seem to upload to Google Drive. I want to upload the folder with the same hierarchy as in the local environment without needing any change in the paths of the files in the code.
The better way I've found is mounting a folder in your Google Drive. Upload the image folder to your drive. After that, in your notebook you write:
from google.colab import drive
drive.mount('/content/drive')
After you allow the authentication, you can work using the path "/content/drive/My Drive" with the path for your image folder. Like that:
from IPython.display import Image
Image("/content/drive/My Drive/images/pic1.png")
See more in the notebook with documentation: https://colab.research.google.com/notebooks/io.ipynb

Mounting google drive on google Colab

I followed the steps given in this Medium tutorial on google colab and then tried to clone a git repository but I cannot see the repository anywhere in my drive.
The following image is the code snippet I used which is exactly the same as that from the Medium tutorial:
To mount google drive on google Colab just use these commands:
from google.colab import drive
drive.mount('/content/drive')
It would need an authentication process. Do whatever it needs (open the link and copy the key)
Now you have mounted your google drive in /content/drive/ directory in your google Colab machine.
To clone a git repository, first set your current directory as a path in /content/drive/, then just clone the git repository. Like below:
path_clone = "/content/drive/my_project"
%cd path_clone
!git clone <Git project URL address>
Now you would have the cloned Git project in my_projects folder in your Google Drive (which is also connected to your Google Colab runtime machine)
Adjust ur path where you git clone.
try adding drive folder to path
import os
os.chdir("drive")
Just do cd drive (without !) or %cd drive.
See cd vs !cd vs %cd in IPython.

How to pass dataset directory in google datalab

I have setup google datalab on my local machine then tried to read dataset using pandas by passing custom data directory but it doesn't take path correctly it adds root at the start then try to pass absolute path then it gives error file doesn't exist but file is in the directory.
Can any one help me what is the issue or anyone explain me is there any predefined rule to put the dataset
If you ran Datalab as a docker container on your local machine, it automatically maps your home directory to /content inside the container, so just make sure your Dataset is accessible from your home path.