deviceの使い方(pytorch)



Python
Pythonとは
基本的な使い方
IDLE

Jupyter Notebook

Markdown

コマンドプロンプトで実行

仮想環境の構築

仮想環境でIDLEを実行

ライブラリのインストール
pipの使い方

numpy , matplotlib等

graphviz

pytorch

Mecab

Pythonの関数:一覧
共通関数
append , extend

class

copy

csv.reader

csv.writer

def , return

dict , defaultdict

enumerate

exit

for

if

import

in

input

lambda

len

list

min/max

OrderedDict

open/close

os

pickle

print

range

re.split

read/readline

round/floor/ceil

split

sys.argv

time

while

write

zip

・特殊メソッド
 ・__name__

 ・__iter__ , __next__

正規表現、メタ文字

データの型の種類

四則演算 (+ , - , * , /)

コメントアウト (# , ''')

numpy
append

arange

argmax/argmin

array

asfarray

astype , dtype

digitize

dot

hstack/vstack

linalg.solve

linspace

max,min

mean

meshgrid

mgrid

ndim

ndmin

pad

poly1d

polyfit

prod

random

reshape

savetxt/loadtxt

shape

std

transpose

where

zeros/zeros_like

scipy
expit

imread

interpolate

signal.square, sawtooth

matplotlib
imshow

figure

pcolormesh

plot

quiver

scatter

scikit-learn
GaussianNB

KMeans

KNeighborsClassifier

SVC

tree

chaospy

keras

chainer

chainerrl

pytorch
BCELoss , MSELoss

Embedding

device

Sequential

Dataset, Dataloader

RNN, LSTM

OpenAI gym
Blackjack-v0

CartPole-v0

tkinter
frame, grid

画像表示

画像を切り取り表示

画像を保存

目的別
ステップ関数

矩形波, 三角波

1 of K 符号化法

線形補間

配列に番号をつける

ベクトル場を描く

線形回帰, 多項式回帰


公開日:2020/6/25         

In English
<premise knowledge>
Python


■説明
pytorchで使用するGPU(cuda)を指定します。cudaとはNVIDIAが提供するGPU向けの開発環境です。

■具体例
まずは自身のPCにpytorchで使えるGPUがあるか確認します。

import torch
print(torch.cuda.is_available())

  ⇒ False # cudaの環境が入っていない場合はFalse


次に以下の様に、"cuda"か"cpu"かいずれかを使用できるデバイス名として変数に格納します。

dev = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") #(1)
print(dev)

  ⇒ device(type='cpu')


以下の様に、.toを使う事で、cudaかcpuを使った演算をすることができます。

b = torch.zeros(4)
c = b.to(dev)
print(c)

  ⇒ tensor([0., 0., 0., 0.])


以下のようなエラーメッセージが出る場合は、GPUが使えないのにGPUを使う設定になっています。上記#(1)の式が正しく設定されているか確認しましょう。

 "Torch not compiled with CUDA enabled"









サブチャンネルあります。⇒ 何かのお役に立てればと

関連記事一覧



Python
Pythonとは
基本的な使い方
IDLE

Jupyter Notebook

Markdown

コマンドプロンプトで実行

仮想環境の構築

仮想環境でIDLEを実行

ライブラリのインストール
pipの使い方

numpy , matplotlib等

graphviz

pytorch

Mecab

Pythonの関数:一覧
共通関数
append , extend

class

copy

csv.reader

csv.writer

def , return

dict , defaultdict

enumerate

exit

for

if

import

in

input

lambda

len

list

min/max

OrderedDict

open/close

os

pickle

print

range

re.split

read/readline

round/floor/ceil

split

sys.argv

time

while

write

zip

・特殊メソッド
 ・__name__

 ・__iter__ , __next__

正規表現、メタ文字

データの型の種類

四則演算 (+ , - , * , /)

コメントアウト (# , ''')

numpy
append

arange

argmax/argmin

array

asfarray

astype , dtype

digitize

dot

hstack/vstack

linalg.solve

linspace

max,min

mean

meshgrid

mgrid

ndim

ndmin

pad

poly1d

polyfit

prod

random

reshape

savetxt/loadtxt

shape

std

transpose

where

zeros/zeros_like

scipy
expit

imread

interpolate

signal.square, sawtooth

matplotlib
imshow

figure

pcolormesh

plot

quiver

scatter

scikit-learn
GaussianNB

KMeans

KNeighborsClassifier

SVC

tree

chaospy

keras

chainer

chainerrl

pytorch
BCELoss , MSELoss

Embedding

device

Sequential

Dataset, Dataloader

RNN, LSTM

OpenAI gym
Blackjack-v0

CartPole-v0

tkinter
frame, grid

画像表示

画像を切り取り表示

画像を保存

目的別
ステップ関数

矩形波, 三角波

1 of K 符号化法

線形補間

配列に番号をつける

ベクトル場を描く

線形回帰, 多項式回帰