Link to images within google drive from a colab notebook

前端 未结 3 615
没有蜡笔的小新
没有蜡笔的小新 2020-12-19 17:20

I would like to store image files on a drive and link to them from a collaboration notebook. Is this possible? For example.

google-drive/
  notebook.ipynb
           


        
3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-19 17:55

    Use the following code:

    !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}
    

    After running above command it will ask for the key. Click on the provided link and verify it.

    Create a folder in drive using:

    !mkdir -p colabData
    !google-drive-ocamlfuse colabData
    

    After this you can use the drive as if its connected locally:

    %%bash
    echo "Hello World...!!!" > colabData/hello.txt
    ls colabData
    

提交回复
热议问题