google Colab雲GPU平臺與Keras操作記錄
阿新 • • 發佈:2019-01-01
谷歌雲盤掛載:
from google.colab import drive
drive.mount('/content/drive/')
雲盤掛載之後切換到程式碼目錄:不能用!cd命令
import os
os.chdir('/content/drive/My Drive/CoLab/PCANet-Python')
os.getcwd()
匯入第三方包:setup是包程式根目錄的檔案
!python3 setup.py install
或者在根目錄執行:
pip3 install
install Keras:
!pip install -q keras
下載dataset(.csv File):
!wget https://raw.githubusercontent.com/vincentarelbundock/Rdatasets/master/csv/datasets/Titanic.csv -P "/content/drive/My Drive/app"
讀取 .csv file 並展示 first 5 rows:
import pandas as pd
titanic = pd.read_csv(“/content/drive/My Drive/app/Titanic.csv”)
titanic.head(5)
克隆git-hub程式碼到colab:
Step 1: Find the Github Repo and Get “Git” Link(紅色方框)
2. Git Clone:程式碼將下載到colab的My Driver下
!git clone https://github.com/wxs/keras-mnist-tutorial.git
然後就可以在colab的目錄下執行程式碼了
Some Useful Tips
1. How to Install Libraries?
Keras
!pip install -q keras
import keras
PyTorch
from os import path from wheel.pep425tags import get_abbr_impl, get_impl_ver, get_abi_tag platform = '{}{}-{}'.format(get_abbr_impl(), get_impl_ver(), get_abi_tag())
accelerator = 'cu80' if path.exists('/opt/bin/nvidia-smi') else 'cpu'
!pip install -q http://download.pytorch.org/whl/{accelerator}/torch-0.3.0.post4-{platform}-linux_x86_64.whl torchvision
import torch
or try this:
!pip3 install torch torchvision
MxNet
!apt install libnvrtc8.0
!pip install mxnet-cu80
import mxnet as mx
OpenCV
!apt-get -qq install -y libsm6 libxext6 && pip install -q -U opencv-python
import cv2
XGBoost
!pip install -q xgboost==0.4a30
import xgboost
GraphViz
!apt-get -qq install -y graphviz && pip install -q pydot
import pydot
7zip Reader
!apt-get -qq install -y libarchive-dev && pip install -q -U libarchive
import libarchive
Other Libraries
!pip install
or !apt-get install
to install other libraries.
檢視tensorboard:
tensorboard可以用來檢視程式碼執行的中間變數、log及畫出相應的曲線變化圖。