google Colab跑代码挂载drive上的数据文件

    xiaoxiao2022-07-02  99

    提供Tesla K80这块高级的GPU加速功能,但是也存在一个问题。

    因为Colaboratory是完全云端的,所以,每次如果想让他访问谷歌云盘的内容,必须要先进性授权操作,直接在colab的jupyter中进行绑定授权操作。(会需要点时间)

    授权绑定代码如下:

    !apt-get install -y -qq software-properties-common python-software-properties module-init-tools !add-apt-repository -y ppa:alessandro-strada/ppa 2>&1 > /dev/null !apt-get update -qq 2>&1 > /dev/null !apt-get -y install -qq google-drive-ocamlfuse fuse from google.colab import auth auth.authenticate_user() from oauth2client.client import GoogleCredentials creds = GoogleCredentials.get_application_default() import getpass !google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret} < /dev/null 2>&1 | grep URL vcode = getpass.getpass() !echo {vcode} | google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret}

    如果上面报错,需要在前面先执行一个代码

    import os del os.environ['LC_ALL']

    余下的可以参考:

     

    谷歌云盘Colaboratory如何载入文件https://blog.csdn.net/einstellung/article/details/81006408

    注意挂载drive时,要更改自己的文件目录路径。

    os.chdir("drive/demo-python-image-classification-Google-colab-master/")

    另外完整的实际项目可以参考:

    如何免费云端运行Python深度学习框架?

    https://www.jianshu.com/p/eebf9a13c52a

     

    最新回复(0)