李沐动手学深度学习(pytorch版本)"d2lzh_pytorch"包的缺少安装问题

学习深度学习时候,很多人参考的是李沐的动手学深度学习Pytorch版本(附上官方地址:https://tangshusen.me/Dive-into-DL-PyTorch/#/)。

在学习3.5.1节 “获取数据集” 时,会遇到d2lzh_pytorch包缺少的问题,经过查阅资料,下面方法可以解决这个问题。

import torch
import torchvision
import torchvision.transforms as transforms
import matplotlib.pyplot as plt
import time
import sys
sys.path.append("..") # 为了导入上层目录的d2lzh_pytorch
import d2lzh_pytorch as d2l

首先下载d2lzh_pytorch包文件(地址:链接:https://pan.baidu.com/s/1WTYOPj_M0C7kzFNSgYH5rw 提取码:z878),失效可百度自找。解压后,放到自己安装Anaconda下面的Lib文件夹中。右键属性把文件索引地址放进源码中。我的供参考:

李沐动手学深度学习(pytorch版本)

李沐动手学深度学习(pytorch版本)

但是接着出现了一个问题,提示没有 torchtext 的module。百度搜torchtext,使用pip安装,直接运行这句程序即可。

pip install https://github.com/pytorch/text/archive/master.zip

然后提示安装成功。

再次运行3.5.1节第一段代码。

待成功后运行下面代码:

mnist_train = torchvision.datasets.FashionMNIST(root='~/Datasets/FashionMNIST', train=True, download=True, transform=transforms.ToTensor())
mnist_test = torchvision.datasets.FashionMNIST(root='~/Datasets/FashionMNIST', train=False, download=True, transform=transforms.ToTensor())
print(type(mnist_train))
print(len(mnist_train), len(mnist_test))

最后提示如下成功。

0it [00:00, ?it/s]
Downloading http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/train-images-idx3-ubyte.gz to C:\Users\wang/Datasets/FashionMNIST\FashionMNIST\raw\train-images-idx3-ubyte.gz
26427392it [00:06, 3888254.22it/s]                              
Extracting C:\Users\wang/Datasets/FashionMNIST\FashionMNIST\raw\train-images-idx3-ubyte.gz to C:\Users\wang/Datasets/FashionMNIST\FashionMNIST\raw
0it [00:00, ?it/s]
Downloading http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/train-labels-idx1-ubyte.gz to C:\Users\wang/Datasets/FashionMNIST\FashionMNIST\raw\train-labels-idx1-ubyte.gz
32768it [00:00, 33876.82it/s]                           
0it [00:00, ?it/s]
Extracting C:\Users\wang/Datasets/FashionMNIST\FashionMNIST\raw\train-labels-idx1-ubyte.gz to C:\Users\wang/Datasets/FashionMNIST\FashionMNIST\raw
Downloading http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/t10k-images-idx3-ubyte.gz to C:\Users\wang/Datasets/FashionMNIST\FashionMNIST\raw\t10k-images-idx3-ubyte.gz
4423680it [00:02, 2118055.67it/s]                             
0it [00:00, ?it/s]
Extracting C:\Users\wang/Datasets/FashionMNIST\FashionMNIST\raw\t10k-images-idx3-ubyte.gz to C:\Users\wang/Datasets/FashionMNIST\FashionMNIST\raw
Downloading http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/t10k-labels-idx1-ubyte.gz to C:\Users\wang/Datasets/FashionMNIST\FashionMNIST\raw\t10k-labels-idx1-ubyte.gz
8192it [00:00, 12252.34it/s]            
Extracting C:\Users\wang/Datasets/FashionMNIST\FashionMNIST\raw\t10k-labels-idx1-ubyte.gz to C:\Users\wang/Datasets/FashionMNIST\FashionMNIST\raw
Processing...
Done!

60000 10000

 

你可能感兴趣的:(Python,Pytorch,pytorch,深度学习,神经网络)