1.开启一个新的notebook,每次开启一个新的notebook都必须先运行以下代码。
先执行以下代码授权给colab,使其可以使用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}
运行上述代码,得到如下结果
E: Package ‘python-software-properties’ has no installation candidate Selecting previously unselected package libfuse2:amd64. (Reading database … 26397 files and directories currently installed.) Preparing to unpack …/libfuse2_2.9.7-1ubuntu1_amd64.deb … Unpacking libfuse2:amd64 (2.9.7-1ubuntu1) … Selecting previously unselected package fuse. Preparing to unpack …/fuse_2.9.7-1ubuntu1_amd64.deb … Unpacking fuse (2.9.7-1ubuntu1) … Selecting previously unselected package google-drive-ocamlfuse. Preparing to unpack …/google-drive-ocamlfuse_0.7.1-0ubuntu2~ubuntu18.04.1_amd64.deb … Unpacking google-drive-ocamlfuse (0.7.1-0ubuntu2~ubuntu18.04.1) … Setting up libfuse2:amd64 (2.9.7-1ubuntu1) … Processing triggers for libc-bin (2.27-3ubuntu1) … Processing triggers for man-db (2.8.3-2ubuntu0.1) … Setting up fuse (2.9.7-1ubuntu1) … Setting up google-drive-ocamlfuse (0.7.1-0ubuntu2~ubuntu18.04.1) … Please, open the following URL in a web browser: https://accounts.google.com/o/oauth2/auth?client_id=32555940559.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&response_type=code&access_type=offline&approval_prompt=force ·········· Please, open the following URL in a web browser: https://accounts.google.com/o/oauth2/auth?client_id=32555940559.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&response_type=code&access_type=offline&approval_prompt=force Please enter the verification code: Access token retrieved correctly.
期间会有两次要求输入验证码,直接点击链接输入即可。
2. 挂载云盘
!mkdir -p drive
!google-drive-ocamlfuse drive -o nonempty
colab会使用云盘上的文件。
3. 安装mxnet和依赖组件。
!apt-get install libnvrtc9.1
!pip install mxnet-cu92
import mxnet as mx
注意版本号。之前安装libnvrtc8.0一直装不上。mxnet-cu80也不好用。
4. 导入gluonbook模块
!mkdir -p gluonbook/gluonbook
%%writefile gluonbook/__init__.py
from .utils import *
__version__ = '0.8.3'
%%writefile gluonbook/utils.py
import collections
import math
import os
import random
import sys
import tarfile
import time
import zipfile
from IPython import display
from matplotlib import pyplot as plt
import mxnet as mx
from mxnet import autograd, gluon, image, init, nd
from mxnet.contrib import text
from mxnet.gluon import data as gdata, loss as gloss, nn, utils as gutils
import numpy as np
VOC_CLASSES = ['background', 'aeroplane', 'bicycle', 'bird', 'boat',
'bottle', 'bus', 'car', 'cat', 'chair', 'cow',
'diningtable', 'dog', 'horse', 'motorbike', 'person',
'potted plant', 'sheep', 'sofa', 'train', 'tv/monitor']
......
......
......
(省略)
5.上传需要的数据集
6.开始写自己的程序进行训练