• Google Colab 基本操作


    ## 上传

    from google.colab import files
    
    uploaded = files.upload()
    
    for fn in uploaded.keys():
      print('User uploaded file "{name}" with length {length} bytes'.format(
          name=fn, length=len(uploaded[fn])))

    ## 下载

    from google.colab import files
    
    with open('example.txt', 'w') as f:
      f.write('some content')
    
    files.download('example.txt')

    ## 获取谷歌硬盘的文件

    ## 方法1 要输入授权码 整个谷歌硬盘整体挂载

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

    ## 方法2 下载并解压,压缩文件

    从google drive 选择某个压缩文件并解压(这里file_id的获取需要右键点击上传文件,选择“获取共享链接”。将Google Drive的zip文件的共享链接复制后

    截取"open?id="后面的一串地址字符 粘贴到下面第二个代码块file_id=' xxxxxxxxxxx '的X的部分)

    !pip install PyDrive googledrivedownloader
    from google_drive_downloader import GoogleDriveDownloader
    
    GoogleDriveDownloader.download_file_from_google_drive(file_id='1I4YGP8LsZMJ6nyv0y3ncklds94XTg19z',dest_path="./tmp.zip",unzip=True)
    !rm tmp.zip !ls

    ### 写入并存储文件

    with open('/content/gdrive/My Drive/foo.txt', 'w') as f:
      f.write('Hello Google Drive!')
    !cat /content/gdrive/My Drive/foo.txt

    ### 升级安装 TensorFlow 

    # To determine which version you're using:
    !pip show tensorflow
    
    # For the current version: 
    !pip install --upgrade tensorflow
    
    # For a specific version:
    !pip install tensorflow==1.2
    
    # For the latest nightly build:
    !pip install tf-nightly

    ### 导入colab默认中没有的库 `!pip install` or `!apt-get install`

    !pip install -q xxx
    !apt-get -qq install -y xxx
  • 相关阅读:
    css样式之补充
    css样式之属性操作
    css之操作属性
    前端基础之css样式(选择器)
    mysql之视图,触发器,事务等
    pymysql模块
    MySQL之IDE工具介绍及数据备份
    mysql老是停止运行该怎么解决
    mysql之索引原理与慢查询优化
    MySQL 5.7.9版本sql_mode=only_full_group_by问题
  • 原文地址:https://www.cnblogs.com/clemente/p/10430488.html
Copyright © 2020-2023  润新知