当前位置:网站首页>Google colab loads Google drive (Google drive is used in Google colab)

Google colab loads Google drive (Google drive is used in Google colab)

2022-07-07 10:07:00 iioSnail

Why are you in Google Colab Use in Google Drive

Generally, there are several reasons :

  1. Upload slow : Upload local files to Google Colab Medium too slow , If session Out of date , You may have to upload it again and again . But if you send the file to Google Drive On , So you can start directly from Google Drive Take it up , Just upload it once .
  2. Data loss :Google Colab Sessions tend to expire , Resulting in the loss of model and training data , Therefore, data and models can be saved to Google Drive in , So you won't be afraid to lose , And it is very convenient for follow-up training .
  3. Some public datasets are Google Drive link , You can easily load them .

load Google Drive

As we enter Colab After the page , Click on the file , Then click load Google Colab:

 Insert picture description here

After that, a piece of code may be generated ( It may not generate , Directly load successfully ):

from google.colab import drive
drive.mount('/content/drive')

Then run the code ( A box will pop up for confirmation for the first time ), Then you will find that there is one more file list drive Folder , Here's you Google Drive File contents of :

 Insert picture description here

Then your operations on this folder will be synchronized to your Google Drive in .


from Google Drive Download files from

Loaded Google Drive after , Just use the files inside , for example :

!unzip drive/MyDrive/Datasets/wider_yolo.zip

I decompress my Google Drive in Datasets/wider_yolo.zip file .

 Insert picture description here


Write file to Google Drive

Loaded Google Drive after , Just write the file to drive/MyDrive Under the following directory . for example :

with open('drive/MyDrive/test.txt', mode='w') as f:
	f.write("Deep Learning")

After executing the above order ,MyDrive Generated in directory test.txt file .

 Insert picture description here

Go now Google Drive You can also see the file in .

 Insert picture description here

Google Colab download Google Drive Shared files

for example , There is such a shared file link :

https://drive.google.com/file/d/1xmkOQ1p6R2T44yZw55wNivPATAieyja9/view?usp=sharing

Then take out. /d/ and /view/ Between the documents id:1xmkOQ1p6R2T44yZw55wNivPATAieyja9

Then execute the following command :

!gdown --id '1xmkOQ1p6R2T44yZw55wNivPATAieyja9' --output test.txt
原网站

版权声明
本文为[iioSnail]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207070719013131.html