您的位置 > 首页 > 商业智能 > A Beginner-Friendly Guide to PyTorch and How it Works from Scratch

A Beginner-Friendly Guide to PyTorch and How it Works from Scratch

来源:分析大师 | 2019-09-17 | 发布:ope电竞之家

Every once in a while, there comes a library or framework that reshapes and reimagines how we look at the field of deep learning. The remarkable progress a single framework can bring about never ceases to amaze me.I can safely say PyTorch is on that list of deep learning libraries. It has helped accelerate the research that goes into deep learning models by making them computationally faster and less expensive (a data scientist’s dream!).I’ve personally found PyTorch really useful for my work. I delve heavily into the arts of computer vision and find myself leaning on PyTorch’s flexibility and efficiency quite often.So in this article, I will guide you on how PyTorch works, and how you can get started with it today itself. We’ll cover everything there is to cover about this game-changing deep learning library and also take up a really cool case study to see PyTorch in action.PyTorch is a Python-based library that provides maximum flexibility and speed.I’ve found PyTorch to be as simple as working with NumPy – and trust me, that is not an exaggeration.You will figure this out really soon as we move forward in this article. But before we dive into the nuances of PyTorch, lets look at some of the key features of this library which make it unique and easy to use.PyTorch TorchScript helps to create serializable and optimizable models. Once we train these models in Python, they can be run independently from Python as well. This helps when we’re in the model deployment stage of a data science project.So, you can train a model in PyTorch using Python and then export the model via TorchScript to a production environment where Python is not available. We will discuss model deployment in more detail in the later articles of this series.PyTorch also supports distributed training which enables researchers as well as practitioners to parallelize their computations. Distributed training makes it possible to use multiple GPUs to process larger batches of input data. This, in turn, reduces the computation time.PyTorch has a very good interaction with Python. In fact, coding in PyTorch is quite similar to Python. So if you are comfortable with Python, you are going to love working with PyTorch.PyTorch has a unique way of building neural networks. It creates dynamic computation graphs meaning that the graph will be created on the fly:And this is just skimming the surface of why PyTorch has become such a beloved framework in the data science community.Right – now it’s time to get started with understanding the basics of PyTorch. So make sure you install PyTorch on your machine before proceeding. The latest version of PyTorch (PyTorch 1.2) was released on August 08, 2019 and you can see the installation steps for it using this link.Remember how I said PyTorch is quite similar to Numpy earlier? Let’s build on that statement now. I will demonstrate basic PyTorch operations and show you how similar they are to NumPy.In the NumPy library, we have multi-dimensional arrays whereas in PyTorch, we have tensors. So, lets first understand what tensors are.Tensors are multidimensional arrays. And PyTorch tensors are similar to NumPy’s n-dimensional arrays. We can use these tensors on a GPU as well (this is not the case with NumPy arrays). This is a major advantage of using tensors.PyTorch supports multiple types of tensors, including:Now, lets look at the basics of PyTorch along with how it compares against NumPy. We’ll start by importing both the NumPy and the Torch libraries:Now, lets see how we can assign a variable in NumPy as well as PyTorch:Lets quickly look at the type of both these variables:Type here confirms that the first variable (a) here is a NumPy array whereas the second variable (b) is a torch tensor.Next, we will see how to perform mathematical operations on these tensors and how it is similar to NumPy’s mathematical operations.Do you remember how to perform mathematical operations on NumPy arrays? If not, let me quickly recap that for you.We will initialize two arrays and then perform mathematical operations like addition, subtraction, multiplication, and division, on them:
本文已经过优化显示,查看原文请点击以下链接:
查看原文:https://www.analyticsvidhya.com/blog/2019/09/introduction-to-pytorch-from-scratch/

看图学经济more

  • 【ope电竞之家】 P2P网贷行业流量之伤与评级之伤 08-10
  • 【ope电竞之家】 财富管理论:从理财师到智能投顾 08-10
  • 【ope电竞之家】 轮回的学生贷江湖,你可懂?(下) 04-05
  • 【ope电竞之家】 互联网票据理财之二:风险辨识不容易 03-30
  • 【ope电竞之家】 互联网票据理财之一:业务运作模式详解! 03-29
  • 京ICP备11001960号  京ICP证090565号 京公网安备1101084107号 论坛法律顾问:王进律师知识产权保护声明免责及隐私声明   主办单位:人大经济论坛 版权所有
    联系QQ:2881989700  邮箱:service@pinggu.org
    合作咨询电话:(010)62719935 广告合作电话:13661292478(刘老师)

    投诉电话:(010)68466864 不良信息处理电话:(010)68466864