1,书以及配套代码
pytorch-book:PyTorch tutorials and fun projects including neural talk, neural style, poem writing, anime generation
https://github.com/chenyuntc/pytorch-book
这是书籍《深度学习框架PyTorch:入门与实践》的对应代码,但是也可以作为一个独立的PyTorch入门指南和教程。
2,调试方法
pytorch Debug —交互式调试工具Pdb (ipdb是增强版的pdb)-1-在pytorch中使用
https://www.cnblogs.com/wanghui-garcia/p/10648849.html
3,安装步骤
安装好pytorch之后,下载pytorch-book,然后创建一个conda环境,安装requirements.txt中的软件包。
git clone https://github.com/chenyuntc/pytorch-book
cd pytorch-book/
conda create -n myStudyPytorch
conda activate myStudyPytorch
pip install -r requirements.txt
pip install ipdb
如果出现如下错误,可以尝试在pip指令后面增加’–user’。具体原因参考pip的官方说明。
Consider using the `--user` option or check the permissions
https://pip.readthedocs.io/en/stable/user_guide/
User Installs
With Python 2.6 came the “user scheme” for installation, which means that all Python distributions support an alternative install location that is specific to a user. The default location for each OS is explained in the python documentation for the site.USER_BASE variable. This mode of installation can be turned on by specifying the --user option to pip install.
Moreover, the “user scheme” can be customized by setting the PYTHONUSERBASE environment variable, which updates the value of site.USER_BASE.
To install “SomePackage” into an environment with site.USER_BASE customized to ‘/myappenv’, do the following:
export PYTHONUSERBASE=/myappenv
pip install --user SomePackage
pip install --user follows four rules:
When globally installed packages are on the python path, and they conflict with the installation requirements, they are ignored, and not uninstalled.
When globally installed packages are on the python path, and they satisfy the installation requirements, pip does nothing, and reports that requirement is satisfied (similar to how global packages can satisfy requirements when installing packages in a --system-site-packages virtualenv).
pip will not perform a --user install in a --no-site-packages virtualenv (i.e. the default kind of virtualenv), due to the user site not being on the python path. The installation would be pointless.
In a --system-site-packages virtualenv, pip will not install a package that conflicts with a package in the virtualenv site-packages. The --user installation would lack sys.path precedence and be pointless.
To make the rules clearer, here are some examples:
From within a --no-site-packages virtualenv (i.e. the default kind):
4,代码运行和调试
1、运行 jupyter notebook
jupyter notebook
2、使用:
在代码开头import ipdb,如下:
import ipdb
在需要开始调试的地方加入语句:
ipdb.set_trace()
3、常用命令:
n (下一个),next单步执行
ENTER (重复上次命令)
q (退出)
p <变量> (打印变量)