admin管理员组文章数量:1402433
Why is my train_ch3
function with #@save
not accessible in other notebooks when using d2l
?
I am following the d2l
(Dive into Deep Learning) framework and trying to save the train_ch3
function using the #@save
annotation so that it can be accessed from other notebooks. However, even after adding the #@save
annotation and ensuring I have imported the d2l
package correctly, the function is not available when I try to call it from another notebook using from d2l import train_ch3
.
Other functions with the #@save
annotation work fine, but this specific function does not seem to be recognized. Below is the code for my train_ch3
function:
def train_ch3(net, train_iter, test_iter, loss, num_epochs, updater): #@save
"""Train a model (defined in Chapter 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)
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 how I try to import and use the function in another notebook:
from d2l import train_ch3
But this results in the following error:
ImportError: cannot import name 'train_ch3' from 'd2l' (unknown location)
What I've checked so far:
- Other functions with
#@save
work: Functions liketrain_epoch_ch3
andevaluate_accuracy
are accessible after adding#@save
. d2l
installation: I confirmed thatd2l
is installed and up-to-date (pip install --upgrade d2l
).- Notebook execution: I ensured that the cell defining
train_ch3
has been executed before trying to use it in another notebook.
My question:
Why does the train_ch3
function fail to be recognized for import despite using the #@save
annotation? Is there something specific about #@save
usage or the d2l
package that I might be missing?
本文标签: pythond2l save is not working in jupyter notebookStack Overflow
版权声明:本文标题:python - d2l #@save is not working in jupyter notebook - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744314053a2600173.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论