文章目录
mac上安装pytorch
建立python虚拟环境
(base) :~ XXX$ conda create -n my_pytorch python=3.9
输入y+Enter
Proceed ([y]/n)? y
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
# $ conda activate my_pytorch
#
# To deactivate an active environment, use
#
# $ conda deactivate
等待出现这些提示,说明已经创建成功
激活python虚拟环境
(base) :~ XXX$ conda activate my_pytorch
若出现()里面是创建的虚拟环境的名称,则表明已经切换到该虚拟环境下。如下图所示
(my_pytorch):~ XXX$
利用pip安装pytorch
(my_pytorch):~ XXX$ pip3 install torch
报错
pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.
出现该错误的原因是当前网速不够,因此选择使用清华镜像进行安装
(my_pytorch):~ XXX$ python3 -m pip install torch torchvision -i https://pypi.tuna.tsinghua.edu.cn/simple
Successfully installed numpy-1.22.1 pillow-9.0.0 torch-1.10.1 torchvision-0.11.2 typing-extensions-4.0.1
成功安装
搭建自定义网络
搭建自定义网络层
- design y = w × x 2 + b y = w\times\sqrt{x^2+b} y=w×x2+b