关于李沐深度学习softmax学习中代码出错的问题及解决方法

写在前面:本人使用的是VS Code编译器,解决的是在VS Code中出现的问题

创作不易,人走留赞!感谢!

问题一:C:\Users\AppData\Local\Programs\Python\Python38\lib\site-packages\torchvision\datasets\mnist.py:498: UserWarning: The given NumPy array is
not writeable, and PyTorch does not support non-writeable tensors. This means you can write to the underlying (supposedly non-writeable) NumPy array using the tensor. You may want to copy the array to protect its data or make it writeable before converting it to a tensor. This type of warning will be suppressed for the rest of this program. (Triggered internally at …\torch\csrc\utils\tensor_numpy.cpp:180.)
return torch.from_numpy(parsed.astype(m[2],copy=False)).view(*s)

问题分析:
数据集处理过程中,无法copy数据集,从而使数据集加载器失效

解决方法:
1.找到C:\Users\AppData\Local\Programs\Python\Python38\lib\site-packages\torchvision\datasets\mnist.py文件,在read_sn3_pascalvincent_tensor 函数中找到 return torch.from_numpy(parsed.astype(m[2],copy=False)).view(*s)返回值,将,copy=False进行删除保存即可

问题二:
qt.qpa.plugin: Could not find the Qt platform plugin “windows” in “”
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

问题分析:
这是环境变量问题

解决方法:
在系统环境变量中添加变量名为:QT_QPA_PLATFORM_PLUGIN_PATH
路径为C:\Users\AppData\Local\Programs\Python\Python38\Lib\site-packages\PyQt5\Qt5\plugins

问题三:
问题解决后仍然无法显示结果

问题分析:
代码有问题

解决方法:
笔者在这里检查到在Animator类中,add函数不全,如果按原视频中的方法写,不可行
笔者尝试用animator = d2l.Animator代替animator = Animator,结果显示可行,但是不会显示图片,终端显示

<Figure size 700x500 with 1 Axes>

想要显示结果图,需要在
train_ch3(net,train_iter,test_iter,loss,num_epochs,updater)
函数中添加d2l.plt.show(),将会显示最终结果。
这里无法显示动图,笔者尝试在循环中添加此函数,仍无法显示动图,并且只显示第一轮训练的结果,另外,如果显示的窗口不关掉,训练将会被中止。笔者水平有限,无法解决动图问题

参考文献:
https://blog.csdn.net/weixin_42116703/article/details/121236256
https://blog.csdn.net/bkdly9/article/details/120634060

Supongo que te gusta

Origin blog.csdn.net/KD_NO_1/article/details/122265572
Recomendado
Clasificación