Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors in train_ch3 in tensorflow version softmax-regression-scratch.ipynb #2577

Open
Neverforgetme opened this issue Dec 24, 2023 · 1 comment

Comments

@Neverforgetme
Copy link

Here is the function that causes an error when I use train_ch3(net, train_iter, test_iter, cross_entropy, num_epochs, updater)

in the softmax-regression-scratch.ipynb

def train_ch3(net, train_iter, test_iter, loss, num_epochs, updater):
"""动画+训练模型(定义见第3章)"""
animator = Animator(xlabel='epoch', xlim=[1, num_epochs], ylim=[0.3, 0.9],
legend=['train loss', 'train acc', 'test acc'])
for epoch in range(num_epochs):
train_metrics = train_epoch_ch3(net, train_iter, loss, updater)
##NameError: name 'train_epoch_ch3' is not defined
test_acc = evaluate_accuracy(net, test_iter)
animator.add(epoch + 1, train_metrics + (test_acc,))
train_loss, train_acc = train_metrics
assert train_loss < 0.5, train_loss
assert train_acc <= 1 and train_acc > 0.7, train_acc
assert test_acc <= 1 and test_acc > 0.7, test_acc

Here is the bug details



NameError Traceback (most recent call last)
in <cell line: 2>()
1 num_epochs = 10
----> 2 train_ch3(net, train_iter, test_iter, cross_entropy, num_epochs, updater)

in train_ch3(net, train_iter, test_iter, loss, num_epochs, updater)
4 legend=['train loss', 'train acc', 'test acc'])
5 for epoch in range(num_epochs):
----> 6 train_metrics = train_epoch_ch3(net, train_iter, loss, updater)
7 test_acc = evaluate_accuracy(net, test_iter)
8 animator.add(epoch + 1, train_metrics + (test_acc,))

NameError: name 'train_epoch_ch3' is not defined


@Neverforgetme
Copy link
Author

Here is another bug in the last cell of softmax-regression-concise.ipynb
d2l.train_ch3(net, train_iter, test_iter, loss, num_epochs, trainer)

Here is the bug detail


AssertionError Traceback (most recent call last)
in <cell line: 2>()
1 num_epochs = 2
----> 2 d2l.train_ch3(net, train_iter, test_iter, loss, num_epochs, trainer)

/usr/local/lib/python3.10/dist-packages/d2l/tensorflow.py in train_ch3(net, train_iter, test_iter, loss, num_epochs, updater)
318 animator.add(epoch + 1, train_metrics + (test_acc,))
319 train_loss, train_acc = train_metrics
--> 320 assert train_loss < 0.5, train_loss
321 assert train_acc <= 1 and train_acc > 0.7, train_acc
322 assert test_acc <= 1 and test_acc > 0.7, test_acc

AssertionError: 0.5710129758199056

ImportError Traceback (most recent call last)
/usr/local/lib/python3.10/dist-packages/IPython/core/formatters.py in call(self, obj)
339 pass
340 else:
--> 341 return printer(obj)
342 # Finally look for special method names
343 method = get_real_method(obj, self.print_method)

12 frames
/usr/local/lib/python3.10/dist-packages/matplotlib/backends/backend_svg.py in
16 import matplotlib as mpl
17 from matplotlib import _api, cbook, font_manager as fm
---> 18 from matplotlib.backend_bases import (
19 _Backend, _check_savefig_extra_args, FigureCanvasBase, FigureManagerBase,
20 RendererBase)

ImportError: cannot import name '_check_savefig_extra_args' from 'matplotlib.backend_bases' (/usr/local/lib/python3.10/dist-packages/matplotlib/backend_bases.py)


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant