当前位置:网站首页>Pytorch environment configuration and basic knowledge
Pytorch environment configuration and basic knowledge
2022-07-25 12:21:00 【Alexa2077】
One 、 Configuration environment
Prepare in advance : This article is installed by default Anaconda, The following operations are Anaconda Prompt on .
1, Creating a virtual environment :conda create -n env_name python==version
2, Activate the virtual environment :conda activate env_name
3, Look at the graphics driver : nvidia-smi
4, To PyTorch Official website installation : Suggest using CUDA edition
conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch
5, Verify successful installation :
Input python Post input :
import torch
torch.cuda.is_available()
CPU Version returns False,GPU Version returns True
6, Use PyCharm Connect to the virtual environment for use
Two 、 Basic knowledge of
1, tensor
tensor : Generalization based on vector and matrix , From scalar , vector , matrix , Expand to higher dimensions .
for instance :
0D: Scalar , Numbers
1D: vector
2D: matrix
3D: The time series , Single color picture
4D: Images
5D: video
stay PyTorch in ,torch.Tensor It is the main tool for storing and transforming data . And NumPy Quite similar . However ,Tensor Provide GPU Calculation and automatic gradient calculation, etc 更 multi-function , These make Tensor This data type is more suitable for deep learning .
2, Common operations
1, Randomly initialize the matrix :torch.rand()
2, whole 0 matrix :torch.zeros()
3, Build... Directly :torch.tensor()
4, Addition operation :torch.add(x,y)
5, Index operation ( Be similar to numpy): The indexed results share memory with the original data , To modify a , The other one will be modified . If you don't want to change it , Consider using copy() Other methods
6, Dimensional transformation :
torch.view(): Back to the new tensor With the source tensor Shared memory ( It's actually the same tensor),更 Change one of them , The other one will change .( seeing the name of a thing one thinks of its function ,view() Just change 了 Yes, this one 量 Observation angle )
torch.reshape(): You can also change the shape of the tensor , However, this function does not guarantee to return its copy value , So the official 不 Recommended .
Recommended approach : First use clone() Create a tensor copy and then use torch.view() Transform the function dimension . Use clone() Another advantage is that it will be recorded in the calculation diagram , That is, when the gradient is returned to the replica, it will also be transmitted to the source Tensor .
3, Broadcast mechanism
When two shapes 不 Identical Tensor When calculating by element , May trigger a broadcast (broadcasting) Mechanism : First copy the elements appropriately so that the two Tensor After the shape is the same, operate according to the element .
边栏推荐
- 面试官:“同学,你做过真实落地项目吗?”
- Can't delete the blank page in word? How to operate?
- 【GCN-RS】Learning Explicit User Interest Boundary for Recommendation (WWW‘22)
- scrapy爬虫爬取动态网站
- Pycharm connects to the remote server SSH -u reports an error: no such file or directory
- 【GCN-CTR】DC-GNN: Decoupled GNN for Improving and Accelerating Large-Scale E-commerce Retrieval WWW22
- 【AI4Code】CodeX:《Evaluating Large Language Models Trained on Code》(OpenAI)
- Scott+scott law firm plans to file a class action against Yuga labs, or will confirm whether NFT is a securities product
- NLP的基本概念1
- R language ggplot2 visualization: visualize the scatter diagram, add text labels to some data points in the scatter diagram, and use geom of ggrep package_ text_ The repl function avoids overlapping l
猜你喜欢

2.1.2 application of machine learning

Basic concepts of NLP 1

【6篇文章串讲ScalableGNN】围绕WWW 2022 best paper《PaSca》

Add a little surprise to life and be a prototype designer of creative life -- sharing with X contestants in the programming challenge

【AI4Code】《GraphCodeBERT: Pre-Training Code Representations With DataFlow》 ICLR 2021

Power Bi -- these skills make the report more "compelling"“

【GCN-RS】Towards Representation Alignment and Uniformity in Collaborative Filtering (KDD‘22)
![[dark horse morning post] eBay announced its shutdown after 23 years of operation; Wei Lai throws an olive branch to Volkswagen CEO; Huawei's talented youth once gave up their annual salary of 3.6 mil](/img/d7/4671b5a74317a8f87ffd36be2b34e1.jpg)
[dark horse morning post] eBay announced its shutdown after 23 years of operation; Wei Lai throws an olive branch to Volkswagen CEO; Huawei's talented youth once gave up their annual salary of 3.6 mil

搭建Vision Transformer系列实践,终于见面了,Timm库!

scrapy爬虫爬取动态网站
随机推荐
Data transmission under the same LAN based on tcp/ip
Eureka注册中心开启密码认证-记录
【AI4Code】《IntelliCode Compose: Code Generation using Transformer》 ESEC/FSE 2020
【AI4Code最终章】AlphaCode:《Competition-Level Code Generation with AlphaCode》(DeepMind)
From cloud native to intelligent, in-depth interpretation of the industry's first "best practice map of live video technology"
协程
monit安装和使用
Zuul网关使用
Fiddler抓包APP
Knowledge maps are used to recommend system problems (mvin, Ctrl, ckan, Kred, gaeat)
scrapy 设置随机的user_agent
那些离开网易的年轻人
Application of comparative learning (lcgnn, videomoco, graphcl, XMC GaN)
【微服务~Sentinel】Sentinel降级、限流、熔断
2.1.2 机器学习的应用
[untitled]
1.1.1 欢迎来到机器学习
Basic concepts of NLP 1
R language uses the ggarrange function of ggpubr package to combine multiple images, and uses the ggexport function to save the visual images in JPEG format (width parameter specifies width, height pa
[multimodal] transferrec: learning transferable recommendation from texture of modality feedback arXiv '22