pipを使用し機械学習ライブラリ「Pytorch」をインストール(Windows10)

スポンサーリンク

コンピュータービジョンや自然言語処理などのアプリケーションに使用されるTorchライブラリに基づくオープンソースの機械学習ライブラリ「Pytorch」をインストールすることについて解説しています。

■Python

今回のPythonのバージョンは、「3.9.13」を使用しています。(Windows10)(pythonランチャーでの確認)

■pipを使用しPytorchをインストールする

Pytorchをインストールするためには、いくつか方法がありますが、今回はpipを使用しインストールを行います。まずWindowsのコマンドプロンプトを起動します。

pip3 install torch==1.8.1+cpu torchvision==0.9.1+cpu torchaudio===0.8.1 -f https://download.pytorch.org/whl/torch_stable.html

起動後、上記のコマンドを入力し、Enterキーを押します。システムの仕様に従って、Pytorchをインストールします。(PyTorch ビルド、オペレーティング システム、パッケージ、言語、および CUDA を選択する必要がある。)

Defaulting to user installation because normal site-packages is not writeable
Looking in links: https://download.pytorch.org/whl/torch_stable.html
Collecting torch==1.8.1+cpu
  Downloading https://download.pytorch.org/whl/cpu/torch-1.8.1%2Bcpu-cp39-cp39-win_amd64.whl (190.4 MB)
     ---------------------------------------- 190.4/190.4 MB 2.8 MB/s eta 0:00:00
Collecting torchvision==0.9.1+cpu
  Downloading https://download.pytorch.org/whl/cpu/torchvision-0.9.1%2Bcpu-cp39-cp39-win_amd64.whl (845 kB)
     ---------------------------------------- 845.4/845.4 KB 1.1 MB/s eta 0:00:00
Collecting torchaudio===0.8.1
  Downloading torchaudio-0.8.1-cp39-none-win_amd64.whl (109 kB)
     ---------------------------------------- 109.3/109.3 KB 707.6 kB/s eta 0:00:00
Collecting typing-extensions
  Using cached typing_extensions-4.3.0-py3-none-any.whl (25 kB)
Collecting numpy
  Downloading numpy-1.23.2-cp39-cp39-win_amd64.whl (14.7 MB)
     ---------------------------------------- 14.7/14.7 MB 2.2 MB/s eta 0:00:00
Collecting pillow>=4.1.1
  Downloading Pillow-9.2.0-cp39-cp39-win_amd64.whl (3.3 MB)
     ---------------------------------------- 3.3/3.3 MB 3.2 MB/s eta 0:00:00
Installing collected packages: typing-extensions, pillow, numpy, torch, torchvision, torchaudio
  WARNING: The script f2py.exe is installed in 'C:\Users\user_\AppData\Roaming\Python\Python39\Scripts' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  WARNING: The scripts convert-caffe2-to-onnx.exe and convert-onnx-to-caffe2.exe are installed in 'C:\Users\user_\AppData\Roaming\Python\Python39\Scripts' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed numpy-1.23.2 pillow-9.2.0 torch-1.8.1+cpu torchaudio-0.8.1 torchvision-0.9.1+cpu typing-extensions-4.3.0
WARNING: You are using pip version 22.0.4; however, version 22.2.2 is available.
You should consider upgrading via the 'C:\Program Files\Python39\python.exe -m pip install --upgrade pip' command.

Enterキーを押すと、インストールが開始され、「Successfully installed」と出力されます。これが出力されれば正常にインストールが完了となります。今回は「WARNING:(警告)」が出力していますが、あくまで警告であり、エラーではないので、一旦無視します。

>pip3 show torch

完了後、実際にインストールが完了しているのかを確認するために、上記のコマンドを入力し、Enterキーを押します。

Enterキーを押すと、バージョンなどの情報が出力されます。出力されれば、インストールの確認は完了です。なお、今回はtorchのバージョン「1.8.1+cpu」をインストールしました。

コメント

タイトルとURLをコピーしました