Colab+pytorch使用

一、colab相关问题

1、colab.research.google.com 

打开或新建笔记本,在“修改”->“笔记本设置”里,将“硬件加速器”设置为“GPU”

from tensorflow.python.client import device_lib
device_lib.list_local_devices()

import torch
torch.cuda.get_device_name(0)

可发现使用的是“Tesla T4”

2、使用Google drive中的数据

先将本地数据集上传到Google drive,存储在"/content/gdrive/My Drive/data"

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

然后将代码中的file_name指向Google drive中的保存位置

3、读写外部文件

参考https://blog.csdn.net/heliucs/article/details/84644372

https://colab.research.google.com/notebooks/io.ipynb#scrollTo=BaCkyg5CV5jF

(1)本地文件上传,会出现一个交互界面,选择文件上传

from google.colab import files
uploaded = files.upload()
for fn in uploaded.keys():
    print('User uploaded file "{name}" with length {length} bytes'.format(name=fn, length=len(uploaded[fn])))

(2)colab下载文件到本地(下载到默认下载位置,比如“下载”)

from google.colab import files
with open('example.txt', 'w') as f:
    f.write('some content')
files.download('example.txt')

二、pytorch相关问题

1、本地安装pytorch

conda install --use-local F:/pytorch-0.4.0-py35_cuda8.0.61_cudnn7.1.2_1.tar.bz2

2、出现"cuDNN error: CUDNN_STATUS_INTERNAL_ERROR"

解决方案:指定显卡(已测试有效),参考https://blog.csdn.net/u014176855/article/details/80994991

import os
os.environ["CUDA_VISIBLE_DEVICES"]="0"

(待续)

你可能感兴趣的:(tools,pytorch)