29
Neuronale Netze mit PyTorch ALEXANDER CS HENDORF

ALEXANDER CS HENDORF€¦ · CEBIT Developer World, BI Forum, IT-Tage FFM, PyDataLondon, Berlin, PyParis,… here! [email protected] @hendorf. Neuronal Networks withPyTorch Topics

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: ALEXANDER CS HENDORF€¦ · CEBIT Developer World, BI Forum, IT-Tage FFM, PyDataLondon, Berlin, PyParis,… here! ah@koenigsweg.com @hendorf. Neuronal Networks withPyTorch Topics

Neuronale Netze mit PyTorchALEXANDER CS HENDORF

Page 2: ALEXANDER CS HENDORF€¦ · CEBIT Developer World, BI Forum, IT-Tage FFM, PyDataLondon, Berlin, PyParis,… here! ah@koenigsweg.com @hendorf. Neuronal Networks withPyTorch Topics

Alexander C. S. Hendorf

-Partner & Principal Consultant Information Technology

Consulting on AI & Data Science

-Python Software Foundation Fellow, Python Softwareverband chair,

Program Chair of EuroSciPy, PyConDE & PyData Berlin, MongoDB Master,

Emeritus EuroPython

-Speaker Europe & USA MongoDB World New York / San José, PyCon Italy,

CEBIT Developer World, BI Forum, IT-Tage FFM, PyData London, Berlin, PyParis,…

here!

[email protected]

@hendorf

Page 3: ALEXANDER CS HENDORF€¦ · CEBIT Developer World, BI Forum, IT-Tage FFM, PyDataLondon, Berlin, PyParis,… here! ah@koenigsweg.com @hendorf. Neuronal Networks withPyTorch Topics
Page 4: ALEXANDER CS HENDORF€¦ · CEBIT Developer World, BI Forum, IT-Tage FFM, PyDataLondon, Berlin, PyParis,… here! ah@koenigsweg.com @hendorf. Neuronal Networks withPyTorch Topics

Neuronal Networks with PyTorch

Topics today

- Background of PyTorch

- Tensors

- Computational graphs

- Building an neural net in PyTorch

- Debugging

- Serialization

Page 5: ALEXANDER CS HENDORF€¦ · CEBIT Developer World, BI Forum, IT-Tage FFM, PyDataLondon, Berlin, PyParis,… here! ah@koenigsweg.com @hendorf. Neuronal Networks withPyTorch Topics

Origins of PyTorch

Page 6: ALEXANDER CS HENDORF€¦ · CEBIT Developer World, BI Forum, IT-Tage FFM, PyDataLondon, Berlin, PyParis,… here! ah@koenigsweg.com @hendorf. Neuronal Networks withPyTorch Topics

Background of PyTorch

- 2017

- Open Source

- Facebook AI & huge community

- Build on Torch, made it popular with Python

Page 7: ALEXANDER CS HENDORF€¦ · CEBIT Developer World, BI Forum, IT-Tage FFM, PyDataLondon, Berlin, PyParis,… here! ah@koenigsweg.com @hendorf. Neuronal Networks withPyTorch Topics

Strongsuits

Page 8: ALEXANDER CS HENDORF€¦ · CEBIT Developer World, BI Forum, IT-Tage FFM, PyDataLondon, Berlin, PyParis,… here! ah@koenigsweg.com @hendorf. Neuronal Networks withPyTorch Topics

Strongsuits of PyTorch

- Easy to learn

- Intuitive

- Integrated with NumPy and SciKit-Learn

- Easy to debug

- Dynamic graphs

- Well documented

- Keeping release schedule

Page 9: ALEXANDER CS HENDORF€¦ · CEBIT Developer World, BI Forum, IT-Tage FFM, PyDataLondon, Berlin, PyParis,… here! ah@koenigsweg.com @hendorf. Neuronal Networks withPyTorch Topics

Let’s go

Page 10: ALEXANDER CS HENDORF€¦ · CEBIT Developer World, BI Forum, IT-Tage FFM, PyDataLondon, Berlin, PyParis,… here! ah@koenigsweg.com @hendorf. Neuronal Networks withPyTorch Topics

https://pytorch.org/

Page 11: ALEXANDER CS HENDORF€¦ · CEBIT Developer World, BI Forum, IT-Tage FFM, PyDataLondon, Berlin, PyParis,… here! ah@koenigsweg.com @hendorf. Neuronal Networks withPyTorch Topics

Tensor Basics

Page 12: ALEXANDER CS HENDORF€¦ · CEBIT Developer World, BI Forum, IT-Tage FFM, PyDataLondon, Berlin, PyParis,… here! ah@koenigsweg.com @hendorf. Neuronal Networks withPyTorch Topics
Page 13: ALEXANDER CS HENDORF€¦ · CEBIT Developer World, BI Forum, IT-Tage FFM, PyDataLondon, Berlin, PyParis,… here! ah@koenigsweg.com @hendorf. Neuronal Networks withPyTorch Topics

Computational Graphs

Page 14: ALEXANDER CS HENDORF€¦ · CEBIT Developer World, BI Forum, IT-Tage FFM, PyDataLondon, Berlin, PyParis,… here! ah@koenigsweg.com @hendorf. Neuronal Networks withPyTorch Topics

h-ps://colah.github.io/

Page 15: ALEXANDER CS HENDORF€¦ · CEBIT Developer World, BI Forum, IT-Tage FFM, PyDataLondon, Berlin, PyParis,… here! ah@koenigsweg.com @hendorf. Neuronal Networks withPyTorch Topics

https://colah.github.io/https://pytorch.org

Page 16: ALEXANDER CS HENDORF€¦ · CEBIT Developer World, BI Forum, IT-Tage FFM, PyDataLondon, Berlin, PyParis,… here! ah@koenigsweg.com @hendorf. Neuronal Networks withPyTorch Topics

Neural Network in Brief

Wi-> Wi+1Data Label’

Neural Network

LabelLoss

Optimizer

Backward

Forward

Big Data

Batch N

Batch 1

Batch 2

Batch 3

1 Epoch

Forward Process: from data to label

Backward Process: update the parameters

N=Big Data/Batch Size

Page 17: ALEXANDER CS HENDORF€¦ · CEBIT Developer World, BI Forum, IT-Tage FFM, PyDataLondon, Berlin, PyParis,… here! ah@koenigsweg.com @hendorf. Neuronal Networks withPyTorch Topics

https://colah.github.io/https://pytorch.org

Page 18: ALEXANDER CS HENDORF€¦ · CEBIT Developer World, BI Forum, IT-Tage FFM, PyDataLondon, Berlin, PyParis,… here! ah@koenigsweg.com @hendorf. Neuronal Networks withPyTorch Topics

Define modules

Build network

Page 19: ALEXANDER CS HENDORF€¦ · CEBIT Developer World, BI Forum, IT-Tage FFM, PyDataLondon, Berlin, PyParis,… here! ah@koenigsweg.com @hendorf. Neuronal Networks withPyTorch Topics

conv1

relu

pooling

Page 20: ALEXANDER CS HENDORF€¦ · CEBIT Developer World, BI Forum, IT-Tage FFM, PyDataLondon, Berlin, PyParis,… here! ah@koenigsweg.com @hendorf. Neuronal Networks withPyTorch Topics

Init Network

Parameter update

Train

Monitor Progress

Page 21: ALEXANDER CS HENDORF€¦ · CEBIT Developer World, BI Forum, IT-Tage FFM, PyDataLondon, Berlin, PyParis,… here! ah@koenigsweg.com @hendorf. Neuronal Networks withPyTorch Topics
Page 22: ALEXANDER CS HENDORF€¦ · CEBIT Developer World, BI Forum, IT-Tage FFM, PyDataLondon, Berlin, PyParis,… here! ah@koenigsweg.com @hendorf. Neuronal Networks withPyTorch Topics

Packages

- torch a Tensor library like Numpy, with strong GPU support

- torch.autograd a tape based automatic differentiation library that supports all differentiable Tensor operations in torch

- torch.nn a neural networks library deeply integrated with autograd designed for maximum flexibility

- torch.optim an optimization package to be used with torch.nn with standard optimization methods such as

SGD, RMSProp, LBFGS, Adam etc.

- torch.multiprocessing python multiprocessing, but with magical memory sharing of torch Tensors across processes.

Useful for data loading and hogwild training.

- torch.utils DataLoader, Trainer and other utility functions for convenience

Page 23: ALEXANDER CS HENDORF€¦ · CEBIT Developer World, BI Forum, IT-Tage FFM, PyDataLondon, Berlin, PyParis,… here! ah@koenigsweg.com @hendorf. Neuronal Networks withPyTorch Topics

GPU / CPU

- Well integrated with CUDA

- Control where to put the data CPU / GPU

torch.device(dev)

- Release data from GPU

torch.cuda.empty_cache()

- torch.cuda.is_available()

Page 24: ALEXANDER CS HENDORF€¦ · CEBIT Developer World, BI Forum, IT-Tage FFM, PyDataLondon, Berlin, PyParis,… here! ah@koenigsweg.com @hendorf. Neuronal Networks withPyTorch Topics

Saving Models

- Pickle

- torch.save(the_model.state_dict(), optimizer_state_dict, PATH)

- Requires the code to load😨

- ONNX

Page 25: ALEXANDER CS HENDORF€¦ · CEBIT Developer World, BI Forum, IT-Tage FFM, PyDataLondon, Berlin, PyParis,… here! ah@koenigsweg.com @hendorf. Neuronal Networks withPyTorch Topics

TensorFlow vs. PyTorch

Page 26: ALEXANDER CS HENDORF€¦ · CEBIT Developer World, BI Forum, IT-Tage FFM, PyDataLondon, Berlin, PyParis,… here! ah@koenigsweg.com @hendorf. Neuronal Networks withPyTorch Topics

Comparison with TensorFlowProperties TensorFlow PyTorch

Graph Static Dynamic (TensorFlow Fold) Dynamic

Ramp-up Time - Win

Graph Creation and Debugging - Win

Feature Coverage Win Catch up quickly

Documentation Tie Tie

Serialization Win (support other lang.) -

Deployment Win (Cloud & Mobile) -

Data Loading - Win

Device Management Win Need .cuda()

Custom Extensions - Win

Summarized from https://awni.github.io/pytorch-tensorflow/

Page 27: ALEXANDER CS HENDORF€¦ · CEBIT Developer World, BI Forum, IT-Tage FFM, PyDataLondon, Berlin, PyParis,… here! ah@koenigsweg.com @hendorf. Neuronal Networks withPyTorch Topics

Wrap Up

Page 28: ALEXANDER CS HENDORF€¦ · CEBIT Developer World, BI Forum, IT-Tage FFM, PyDataLondon, Berlin, PyParis,… here! ah@koenigsweg.com @hendorf. Neuronal Networks withPyTorch Topics

Vielen Dank für Ihre Aufmerksamkeit. Fragen & Antworten

koenigsweg.com [email protected]

@hendorf

Page 29: ALEXANDER CS HENDORF€¦ · CEBIT Developer World, BI Forum, IT-Tage FFM, PyDataLondon, Berlin, PyParis,… here! ah@koenigsweg.com @hendorf. Neuronal Networks withPyTorch Topics