Colab运行GitHub代码

前提:代理选“德国”,稳定一点 ~

1. 将Colab与Good Drive关联起来

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

2.定位到Drive的根目录,并查看根目录下的文件

import os
os.chdir("/content/drive/My Drive")
!ls

3.下载GitHub的代码到Drive

!git clone https://github.com/wadayama/TISTA.git
!ls

4. 切换到刚才下载项目的文件夹下

cd TISTA/

5.查看文件夹下所有文件

!ls

6.修改TensorFlow版本为1.X,Colab默认使用TensorFlow 2.X

%tensorflow_version 1.1
import tensorflow
print(tensorflow.__version__)

7. 运行python程序

!python main.py

7.1 运行Python程序,并在notebook上显示plt图片

#!python main.py  #下面的运行方式
% run main.py
%matplotlib inline

如何查看GPU?

! /opt/bin/nvidia-smi

在本地如何TensorFlow2.0下运行TensorFlow1.X版本的代码

import tensorflow as tf
#-----修改为↓↓↓↓↓↓↓↓↓
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()

参考:

https://blog.csdn.net/tan123456987321/article/details/104777049

colab+git clone+Google drive提速: https://blog.csdn.net/qq_42698608/article/details/104793387

原文地址:https://www.cnblogs.com/HuangYJ/p/13362945.html