《动手学深度学习》(tensorflow版)中“d2lzh_tensorflow2“包的安装

前言

在参考李沐老师《动手学深度学习》tensorflow版本实现多层感知机时,需要安装"d2lzh_tensorflow2"包,笔者尝试直接pip install d2lzh,却出现了以下错误:

AttributeError: ‘tensorflow.python.framework.ops.EagerTensor’ object has no attribute ‘sum’

初步判断是d2lzh包的版本问题。

解决方式

  1. 到github项目中下载d2lzh_tensorflow2文件。
    地址:https://github.com/TrickyGo/Dive-into-DL-TensorFlow2.0/tree/master/code
    在这里插入图片描述
  2. d2lzh_tensorflow2文件夹拷贝到自己的项目目录中。
    在这里插入图片描述
    运行报错:

ModuleNotFoundError: No module named ‘tqdm’

  1. 在终端中执行 pip install tqdm,重新运行。
    输出正常。

epoch 1, loss 0.8183, train acc 0.694, test acc 0.816
epoch 2, loss 0.4892, train acc 0.818, test acc 0.834
epoch 3, loss 0.4206, train acc 0.843, test acc 0.851
epoch 4, loss 0.3869, train acc 0.856, test acc 0.859
epoch 5, loss 0.3636, train acc 0.865, test acc 0.864