Test if notebook is running on Google Colab

后端 未结 4 1281
小蘑菇
小蘑菇 2021-01-07 19:47

How can I test if my notebook is running on Google Colab?

I need this test as obtaining / unzipping my training data is different if running on my laptop or on Colab

4条回答
  •  梦谈多话
    2021-01-07 19:58

    you can check environment variable like this:

    import os
    if 'COLAB_GPU' in os.environ:
       print("I'm running on Colab")
    

    actually you can print out os.environ to check what's associated with colab and then check the key

提交回复
热议问题