Overview of Pytorch

Why Pytorch: Pytorch is an easy-to-use, top machine learning framework. It is easy to use for prototyping and research and can be used in production. It is supported by Facebook and it is open-sourced. For installation you will want to visit the installation page of the official website. We recommend skipping the complex configuration and use Google Colab for your Pytorch study.Google Colab, in-browser notebook for data scientists and machine learning practitioners According to pytorch developer conferences: pytorch is used at Uber, Tesla, Microsoft, Captum, Fastai, MARS, AllenNLP, ClassyVision. Pytorch is believed to be popular among university researchers too. Many deep learning papers use either Pytorch and/or Tensorflow. In Pytorch's own words: the machine learning framework provides important components deep learning such as neural network layers, activation functions, loss functions, and optimizers. It also allows developers to write python code, use autograd, eager mode (as opposed to lazy graph compute). There are production and deployment features: torchscript, torchserve, quantization. Ever since Pytorch 1.0, the library is supposed to be research friendly, as well as production ready-ish.

Keep in mind all our content in all our sites, channels and social media are for educational, information purpose only. Our tutorials are not for commercial usage, not for production. They are not production ready code. Read our full disclaimer before using.

Check out our Medium Pytorch guide Pytorch code snippet, cheat sheet - Uniqtech Guide [medium]. This article is featured on KDnuggets.

Pytorch pro tip flash card - Uniqtech

Frequently used Pytorch libraries. Below are three modules that are often used. torch.nn for neural networks, torch.nn.functional for layers activations, and finally optim for the optimizer, source pytorch official documentation

Tensors

Tensors are essential components of Pytorch. It is the main data structure used to handle deep learning data. Don't scared by the name. A 1 dimensional tensor is a list of numbers with a lot of fancy deep learning capabilities. A 2 dimensional tensor is a matrix of numbers with fancy DL super powers. Usually tensor referrs to 3 dimensional and above. In Deep Learning, there's plenty of high dimensional data.

Initiate a Model

What is a sequential? A sequential can be seen as a container that contains a stack of deep learning layers. It's similar for Keras and Pytorch. Pytorch Official Documentation on Sequential The explanation on Pytorch doc is a bit dense. It mentions several important characteristics : ... Sequential Model flash card - Uniqtech [Public, Free] ... Now check out the sample code snippet Code snippet Pytorch Sequential

There's the a objected-oriented programming OOP way of initating a model.

Pytorch Forward Function

Another name is for the forward function is the forward pass.

Pytorch training loop

sklearn (scikitlearn) and keras just call .fit() to train. The format is model.fit(X_train, y_train). In Pytorch you will have to do a bit DIY your own custom training loop.

Pytorch classes

Pytorch ImageFolder Pytorch Dataloader

Pytorch libraries

torchvision for computer vision. torchtext . PyTorch Geometric .

torchvision, pytorch library for computer vision, includes pre-trained models and package datasets (buildin datasets)

Transfer Learning

Training large image and natural language models cost time, resources, human resources, compute power and requires collection of large training dataset. Often, we use transfer learning to resolve this costly problem. Transfer learning is when we use models trained on other related datasets, use it to make prediction on our own dataset, often with a bit of adjustment and fine tuning. It is common practice to train the final one or few layers before using. It is also common we have to change a few parameters such as out_features. For example, if a model is trained on imagenet dataset, then it can predict 1000 classes, in reality we need it to predict a smaller number of classes 10 for example. Transfer Learning using Pytorch [Medium] Uniqtech Guide

Additional Reading

Pytorch cheat sheet by Pytorch documentation

How Tesla uses Pytorch