🌎

Google Colab のいろいろ

2022/10/15に公開

はじめに

Google Colaboratory の使う際に使うものをメモ。
更新する可能性あり。

Google ドライブにマウント

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

GitHub のリポジトリをクローンする

content フォルダに格納される。

!git clone [GitHubのリポジトリのURL(https://github.com/...)]

フォルダの移動

%cd [パス]

パッケージのインストール

!pip install [パッケージ名]

Python ファイルの実行

!python [ファイル名.py]

セッション切れ防止

  • 対策1
    デベロッパーツールの Console で以下を実行
function ClickConnect(){
  console.log("3minごとに再接続");
  document.querySelector("colab-connect-button").click()
}
setInterval(ClickConnect,1000*180);
  • 対策2

https://qiita.com/enmaru/items/2770df602dd7778d4ce6

TensorBoardの表示

  • 以下のコードをセルで実行
  • /content/drive/.../logs/はログのパスを指定する。
  • クォーテーション等は必要なし
%load_ext tensorboard
%tensorboard --logdir /content/drive/.../logs/

ERROR: pip's dependency resolver does not currently take into account all the packages that are installed.

Google colab で実行した時に吐き出された。以下で解決。

!pip install h5py
!pip install typing-extensions
!pip install wheel

参考

https://github.com/apple/turicreate/issues/3383
https://flat-kids.net/2020/07/28/google-colab-セッション切れを防止する/

Discussion