谷歌近期推出一项免费服务,总结起来主要有以下亮点:
- 完全免费的机器学习,深度学习环境
- 在线 Jupyter Notebook 交互式python运行环境
- 免安装快速切换Python2,Python3环境
- 可以免费使用GPU加速神经网络训练
- 可以使用pip自定义安装需要的第三方库与使用apt-get安装依赖
- 方便对接Tensorflow,GoogleDrive,BigQuery等谷歌服务
网址:https://colab.research.google.com
第三方库与依赖安装示例
Colab 自带了 Tensorflow、Matplotlib、Numpy、Pandas 等深度学习基础库。如果还需要其他依赖,如 Keras,可以新建代码块,输入
# 安装最新版本 Keras # https://keras.io/ !pip install keras # 指定版本安装 !pip install keras==2.0.9 # 安装 OpenCV # https://opencv.org/ !apt-get -qq install -y libsm6 libxext6 && pip install -q -U opencv-python ## 安装其它依赖与库自行参考上面示例 ## 与jupyter notebook一样 !加命令 是在命令行环境下执行这条命令
Google Drive 操作
- 授权登录
# 安装 PyDrive 操作库,该操作每个 notebook 只需要执行一次 !pip install -U -q PyDrive from pydrive.auth import GoogleAuth from pydrive.drive import GoogleDrive from google.colab import auth from oauth2client.client import GoogleCredentials # 授权登录,仅第一次的时候会鉴权 auth.authenticate_user() gauth = GoogleAuth() gauth.credentials = GoogleCredentials.get_application_default() drive = GoogleDrive(gauth)
- 遍历目录
# 列出根目录的所有文件 # "q" 查询条件教程详见:https://developers.google.com/drive/v2/web/search-parameters file_list = drive.ListFile({'q': "'root' in parents and trashed=false"}).GetList() for file1 in file_list: print('title: %s, id: %s, mimeType: %s' % (file1['title'], file1['id'], file1["mimeType"]))
- 读写等操作由于没有实测,这里就不粘过来了,更多操作可查看 http://pythonhosted.org/PyDrive/filemanagement.html
声明
本文摘自机器之心
想搞机器学习可以仔细看看上面的教程哈
本文只做免费服务推荐,具体玩法大家自己发掘吧~