xiaoxiaokeke 2020-05-17
1.记得选择使用GPU
# 授权绑定Google Drive
!apt-get install -y -qq software-properties-common python-software-properties module-init-tools
!add-apt-repository -y ppa:alessandro-strada/ppa 2>&1 > /dev/null
!apt-get update -qq 2>&1 > /dev/null
!apt-get -y install -qq google-drive-ocamlfuse fuse
from google.colab import auth
auth.authenticate_user()
from oauth2client.client import GoogleCredentials
creds = GoogleCredentials.get_application_default()
import getpass
!google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret} < /dev/null 2>&1 | grep URL
vcode = getpass.getpass()
!echo {vcode} | google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret}2.安装必要的库(还不确定必须需要)
# 安装最新版本Keras # https://keras.io/ !pip install keras # 指定版本安装 !pip install keras==2.1.5 # 安装 OpenCV # https://opencv.org/ !apt-get -qq install -y libsm6 libxext6 && pip install -q -U opencv-python # 安装 Pytorch # http://pytorch.org/ !pip install -q http://download.pytorch.org/whl/cu75/torch-0.2.0.post3-cp27-cp27mu-manylinux1_x86_64.whl torchvision # 安装 XGBoost # https://github.com/dmlc/xgboost !pip install -q xgboost # 安装 7Zip !apt-get -qq install -y libarchive-dev && pip install -q -U libarchive # 安装 GraphViz 和 PyDot !apt-get -qq install -y graphviz && pip install -q pydot !pip install jieba !pip install h5py
3.进入文件并查看
# 挂载Google driver,指定Google Drive云端硬盘的根目录,名为drive
!mkdir -p drive
!google-drive-ocamlfuse drive
# 指定当前的工作目录
# 此处为google drive中的文件路径,drive为之前指定的工作根目录,要加上
import os
os.chdir("drive/BreastCancer_FinalVersion")
!ls
4. 运行
!python trainAlexnet.py使用TensorFlow的实现,tf.keras。这个适用于TF 2。
例如你需要使用tf.keras,必须确保使用正确的导入:
from tensorflow import keras
而不是直接使用:import keras
同样,在要使用keras下的其他模块时:
from tensorflow.keras import layers
而不是使用 from keras import layers
https://www.jianshu.com/p/c09ef6597b8b