Tutorial - Dipartimento di Informatica

Tutorial

April 27, 2020

[1]: import matplotlib.pyplot as plt import sys sys.stderr = sys.__stderr__ plt.rc('font', size=16)

1 Outline

1. Introduction 2. Sparse Data & Indexing in PyTorch 3. Framework Overview 4. Machine Learning with PyG 5. Conclusions

2 The "What"

? Python library for Geometric Deep Learning ? Written on top of PyTorch ? Provides utilities for sparse data ? CUDA/C++ routines for max performance

3 The "Why"

? A must-have if you are a (G)DL guy ? Only few more alternatives:

? Deep Graph Library (DGL, PyTorch) ? Stellar Graph, Euler (TF)

1

? Other wannabes ( 1 mat[1::2] = -mat[::2]

2 mat

RuntimeError: The expanded size of the tensor (1) must match the existing size (2) at non-singleton dimension 0. Target sizes: [1, 4]. Tensor sizes: [2, 4]

4

[11]: mat[1, :, :] = 0 mat

---------------------------------------------------------------------------

IndexError

Traceback (most recent call last)

in ----> 1 mat[1, :, :] = 0

2 mat

IndexError: too many indices for tensor of dimension 2

[13]: mat[1, ..., 2] = 5 mat

[13]: tensor([[ 42, -42, 42, -42], [ 0, 0, 5, 0], [ 42, -42, 42, -42]])

9 Masked Selection

Using a BoolTensor to select values inside another Tensor [14]: rnd = torch.rand(3, 9)

rnd

[14]: tensor([[0.0671, 0.4826, 0.5229, 0.9172, 0.0080, 0.6228, 0.3292, 0.5323, 0.4379], [0.3695, 0.1830, 0.5255, 0.0216, 0.6390, 0.5217, 0.1131, 0.4823, 0.8124], [0.9888, 0.4735, 0.1370, 0.2681, 0.6472, 0.4005, 0.3606, 0.9460, 0.6793]])

[15]: mask = rnd >= 0.5 mask

[15]: tensor([[False, False, True, True, False, True, False, True, False], [False, False, True, False, True, True, False, False, True], [ True, False, False, False, True, False, False, True, True]])

[16]: mask.type()

[16]: 'torch.BoolTensor'

5

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download