PyTorch- A Deep Learning Journey!

in OCD4 years ago

20200524_150439.jpg

Hello! I am a diet/fitness freak and a coder who’s currently enrolled in Deep Learning with PyTorch: ‘Zero to GAN’s’. This is a free online certification course that provides an introduction to deep learning using the PyTorch framework. The course instructor, Mr. Aakash N S, is the co-founder and CEO of Jovian.ml. Students from over 100 countries are currently enrolled in the course. This course is conducted in collaboration with freeCodeCamp.org.

Last Saturday, 23rd May 2020 was the first lecture where Aakash introduced us to PyTorch Tensors, Linear Regression and Gradient Descent. I will be documenting my assignments to share my experiences and knowledge. Please feel free to give me your feedback or ask me any questions.

Let’s get to business! In the first assignment we were asked to illustrate five interesting built-in functions of PyTorch in a Jupyter notebook and share them using Jovian.ml. So here are five functions which I found interesting.

The first function that I found interesting was torch.div(input, other, out=None) because it can be useful in making price predictions for different markets such as cryptocurrency, stocks, precious metals and so on. This function helps divide each element of a tensor (input) by a scalar and returns a new tensor.

Example 1 - working

x = torch.tensor([[7.1, 4], [1, 5]])
x

image.png

Example 2 - working

print(x)
y = torch.div(x, 2.7)
y

image.png

Example 3 - breaking (to illustrate when it breaks)

print(x)
z = torch.div(x, 2.7, out=[7.2])
z

image.png

Torch.remainder(input, other, out=None) is another interesting function which can help in managing personal finances. This can be used by individuals and companies to understand the percentage difference in spending and buying, calculating compounding interest and so on.

Example 1 - working

print(x)
b= torch.remainder(x, 3.4, out=None)
b

image.png

Example 2 - working

print(x)
c= torch.remainder(x, 2)
c

image.png

Example 3 - breaking (to illustrate when it breaks)

print(x)

d = torch.tensor([[2,5,9],[2, 1.2]])

f = torch.remainder(d, 1, out=None)
f

image.png

The torch.trunc(input, out=None) function can be helpful when we want our predictions to be whole numbers and the decimal values are irrelevant. It helps while analysing prices in areas such as real estate, gold etc.

Example 1 - working

print(x)

g = torch.trunc(x)
g

image.png

Example 2 - working

h = torch.randn(6)
print(h)

i = torch.trunc(h)
i

image.png

Example 3 - breaking (to illustrate when it breaks)

print(h)

j= torch.trunc([h])
j

image.png

The fourth function, torch.var_mean(input, unbiased=True) I think can be used in efficiently managing the working capital of businesses because it returns the variance and mean of all elements in the 'input' (tensor).

Example 1 - working

print(x)

k = torch.var_mean(x, unbiased=True)
k

image.png

Example 2 - working

print(x)

l = torch.var_mean(x, unbiased=False)
l

image.png

Example 3 - breaking (to illustrate when it breaks)

print(x)

m = torch.var_mean(x, unbiased=bool)
m

image.png

Lastly, the torch.flatten(input, start_dim=0, end_dim=-1) function which I think is useful while modifying images.

Example 1 - working

print(x)

n = torch.flatten(x)
n

image.png

Example 2 - working

o = torch.randn(4,5)
print(o)

q = torch.flatten(o)
q

image.png

Example 3 - breaking (to illustrate when it breaks)

print(x)

r = torch.flatten(x, start_dim=1.2)
r

image.png

PyTorch built-in functions are efficient in performing simple or complex calculations with a few lines of code! To view my Jupyter notebook click here. Can you tell me some other interesting built-in functions?

Credits
The material in this series is heavily inspired by the following resources:
PyTorch Tutorial for Deep Learning Researchers by Yunjey Choi:
FastAI development notebooks by Jeremy Howard:

Sort:  

Congratulations @cryptopossible! You received a personal badge!

Happy Hive Birthday! You are on the Hive blockchain for 1 year!

You can view your badges on your board And compare to others on the Ranking

Do not miss the last post from @hivebuzz:

Introducing HiveBuzz Shop - Offer gifts with your favorite badges
Support the HiveBuzz project. Vote for our proposal!