Recommended
PDF
PDF
Google Developer Day 2010 Japan: プログラミング言語 Go (鵜飼 文敏)
KEY
PDF
PDF
2018年01月27日 TensorFlowの計算グラフの理解
PDF
TensorFlow Operation 作ってみた
PDF
KEY
Hello World Python featuring GAE
PDF
PDF
PWNの超入門 大和セキュリティ神戸 2018-03-25
PDF
PDF
Metaprogramming in JuliaLang
PPTX
How to use Moresampler? (Japanese)
PPTX
PDF
PDF
PPTX
PPTX
PPTX
LUT-Network ~Edge環境でリアルタイムAIの可能性を探る~
PDF
PDF
PDF
PDF
PDF
ぼくのかんがえたさいきょうのついったーくらいあんと
PPTX
デザイナーのためのPHP講座 for WordPress (初級)
PDF
Dentoo lt 4 - octave の旋律 -
PDF
PDF
PDF
TensorFlow White Paperを読む
PDF
[第2版]Python機械学習プログラミング 第14章
More Related Content
PDF
PDF
Google Developer Day 2010 Japan: プログラミング言語 Go (鵜飼 文敏)
KEY
PDF
PDF
2018年01月27日 TensorFlowの計算グラフの理解
PDF
TensorFlow Operation 作ってみた
PDF
KEY
Hello World Python featuring GAE
What's hot
PDF
PDF
PWNの超入門 大和セキュリティ神戸 2018-03-25
PDF
PDF
Metaprogramming in JuliaLang
PPTX
How to use Moresampler? (Japanese)
PPTX
PDF
PDF
PPTX
PPTX
PPTX
LUT-Network ~Edge環境でリアルタイムAIの可能性を探る~
PDF
PDF
PDF
PDF
PDF
ぼくのかんがえたさいきょうのついったーくらいあんと
PPTX
デザイナーのためのPHP講座 for WordPress (初級)
PDF
Dentoo lt 4 - octave の旋律 -
PDF
Similar to Pytorch 01
PDF
PDF
TensorFlow White Paperを読む
PDF
[第2版]Python機械学習プログラミング 第14章
PDF
[第2版]Python機械学習プログラミング 第13章
PDF
Pythonによる機械学習入門〜基礎からDeep Learningまで〜
PPTX
PDF
Deep Learning Implementations: pylearn2 and torch7 (JNNS 2015)
KEY
PyOpenCLによるGPGPU入門 Tokyo.SciPy#4 編
KEY
PPTX
Tensor コアを使った PyTorch の高速化
PPTX
みんなが知らない pytorch-pfn-extras
PPTX
PDF
PDF
[DLHacks LT] PytorchのDataLoader -torchtextのソースコードを読んでみた-
PPTX
PPTX
PDF
TensorFlow 3分紹介 with 速攻 windows 環境構築
PDF
Anaconda & NumbaPro 使ってみた
PPTX
PPTX
Kaggle参加報告: Quora Insincere Questions Classification
Recently uploaded
PDF
krsk_aws_re-growth_aws_devops_agent_20251211
PDF
音楽アーティスト探索体験に特化した音楽ディスカバリーWebサービス「DigLoop」|Created byヨハク技研
PDF
ソフトウェアエンジニアがクルマのコアを創る!? モビリティの価値を最大化するソフトウェア開発の最前線【DENSO Tech Night 第一夜】
PPTX
君をむしばむこの力で_最終発表-1-Monthon2025最終発表用資料-.pptx
PDF
2025/12/12 AutoDevNinjaピッチ資料 - 大人な男のAuto Dev環境
PDF
ソフトとハードの二刀流で実現する先進安全・自動運転のアルゴリズム開発【DENSO Tech Night 第二夜】 ー高精度な画像解析 / AI推論モデル ...
Pytorch 01 1. 2. 3. 4. 5. torch empty
x2 = torch.empty(5, 3)
print(x2)
=> tensor([[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.],
[0., 0., 0.]])
1. 未初期化の配列を作成する
2. 割り当てられたメモリにあった値が初期値
6. torch random
x3 = torch.rand(5, 3)
print(x3)
=> tensor([[0.8747, 0.1603, 0.2513],
[0.6047, 0.7739, 0.9702],
[0.1574, 0.1463, 0.1762],
[0.8923, 0.5875, 0.5725],
[0.3153, 0.1467, 0.9051]])
1. 乱数の配列も可能
7. torch size
x4 = torch.empty(3, 2)
print( x4.size() )
=> torch.Size([3, 2])
1. 配列のサイズを取得(np.shape的な)
8. torch operations
x = torch.tensor([1,2,3])
y = torch.tensor([10,20,30])
print(x + y)
=> tensor([11, 22, 33])
配列同士の加算
print(torch.add(x, y))
=> tensor([11, 22, 33])
上記と動作は同じ
9. torch operations
x = torch.tensor([1,2,3])
y = torch.tensor([10,20,30])
y.add_(x)
print(y)
=> tensor([11, 22, 33])
破壊的メソッド(本例ではyの値を変更する)
メソッド名末尾がアンダーバーの場合は破壊的
10. torch index
x = torch.tensor([[1,2,3], [4,5,6]])
print(x[:,1])
print(x[:, :2])
=> tensor([2, 5])
=> tensor([[1, 2],
[4, 5]])
numpyライクなインデックス操作
11. torch view
x = torch.tensor([[1,2,3,4], [5,6,7,8]])
print(x.view(8))
print(x.view(-1, 2))
=> tensor([1, 2, 3, 4, 5, 6, 7, 8])
=> tensor([[1, 2],
[3, 4],
[5, 6],
[7, 8]])
viewで行列をresize, reshapeする
12. torch item
x = torch.tensor([[1,2,3,4], [5,6,7,8]])
print( x[0, 0].item() )
print( type(x[0, 0].item()) )
=> 1
=> <class ‘int’>
1つの値が欲しい場合はitemで取得
取得した値はpython number型
13. torch numpy bridge
x1 = torch.tensor([1,2,3,4])
x2 = x1.numpy()
x3 = torch.from_numpy(x2)
print(x)
print(_x)
print(__x)
=> tensor([1, 2, 3, 4])
=> [1 2 3 4]
=> tensor([1, 2, 3, 4])
tensorとnumpyは相互に変換が可能
14. torch cuda
device = "cuda:1" if torch.cuda.is_available() else "cpu"
x = torch.tensor([1,2,3]).to(device)
y = torch.tensor([10,20,30]).to(device)
z = x + y
print(z)
print(z.to("cpu"))
=> tensor([11, 22, 33], device='cuda:1')
=> tensor([11, 22, 33])
tensorをgpuに転送
deviceを定義することでコードが簡潔になる
15. torch cuda
device = "cuda:1" if torch.cuda.is_available() else "cpu"
x = torch.tensor([1,2,3]).to(device)
y = torch.tensor([10,20,30])
z = x + y
=> RuntimeError: expected device cuda:1 and dtype Long but got
device cpu and dtype Long
cpu + gpuの演算はエラーとなるので注意
x.to(gpu) + y.to(gpu)もしくはx.to(cpu) + y.to(cpu)
16.