当前位置:网站首页>Google lab usage notes

Google lab usage notes

2022-07-28 14:55:00 javafalcon

google Provided colab Provides GPU、TPU Operating environment , You can save a lot of money , In use, according to your own situation , I took a few notes for review from time to time .

1. The problem of path . For a question , Just write a ipynb The file shows that it is not conducive to the reusability of the code , I am used to writing some reusable code py file , And then in ipynb Used in documents import The command reference . stay colab In order to identify the path of the file , Follow these steps .

step1. Mount Directory . We copy the following code to a cell in , And run this cell

from google.colab import drive

drive.mount('/content/drive')

step 2. Change the directory to the folder you want to use

import os

os.chdir('drive/MyDrive/Colab/workfiles')

notes : here workfiles Your working directory , Take yours. ipynb Document and py Put the file in a directory and you can use it . File references between different directories , It hasn't been used yet , It will be supplemented later .

2. colab The problem of disconnection .colab It's easy to use , But if we run a program and then do something else , Not clicking on the page for a long time will cause colab disconnect , So our code interrupts execution , To keep the page connected , Follow these steps .

step 1. Click on Google browser “ Developer tools ”

 step 2. Click in the developer tool “Concole”

 step 3. Copy and paste the following code at the red horizontal line in the above figure :

function ClickConnect(){
  colab.config
  console.log("Connnect Clicked - Start"); 
  document.querySelector("#top-toolbar > colab-connect-button").shadowRoot.querySelector("#connect").click();
  console.log("Connnect Clicked - End");
};
setInterval(ClickConnect, 60000)

After copy and paste , You can enter. . In this way, you can make the web page every 60 One click per second . But in my own experiment, I found that such frequent clicks will lead to interruption , I usually set it to 10 One click per minute , Put the last line of 60000 Change it to 600000.

Statement :

This blog is just my own study notes , Not the original . All the methods are from others' blogs. Thank you here .

Note No 2 The dots come from CSDN Blogger 「 Today is another day of hope 」 The original article of ,
Link to the original text :https://blog.csdn.net/liupeng19970119/article/details/105625334

原网站

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