当前位置:网站首页>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 .
边栏推荐
- 嵌套事务 UnexpectedRollbackException 分析与事务传播策略
- PyTorch进阶训练技巧
- Mirror Grid
- Analysis of TCP packet capturing using Wireshark
- Figure neural network for recommending system problems (imp-gcn, lr-gcn)
- logstash
- R语言ggpubr包ggarrange函数将多幅图像组合起来、annotate_figure函数为组合图像添加注释、注解、标注信息、fig.lab参数添加图像标签、fig.lab.face参数指定样式
- Implement anti-theft chain through referer request header
- Intelligent information retrieval (overview of intelligent information retrieval)
- Eureka注册中心开启密码认证-记录
猜你喜欢

Can't delete the blank page in word? How to operate?

Meta learning (meta learning and small sample learning)

scrapy 爬虫框架简介

Word中的空白页,怎么也删不掉?如何操作?

Intelligent information retrieval (overview of intelligent information retrieval)

NLP的基本概念1

Feign使用

【GCN-RS】Are Graph Augmentations Necessary? Simple Graph Contrastive Learning for RS (SIGIR‘22)

【CTR】《Towards Universal Sequence Representation Learning for Recommender Systems》 (KDD‘22)

Pycharm connects to the remote server SSH -u reports an error: no such file or directory
随机推荐
scrapy 设置随机的user_agent
Transformer variants (routing transformer, linformer, big bird)
【九】坐标格网添加以及调整
【AI4Code】《CodeBERT: A Pre-Trained Model for Programming and Natural Languages》 EMNLP 2020
Power Bi -- these skills make the report more "compelling"“
Multi label image classification
Analysis of TCP packet capturing using Wireshark
R语言组间均值是否相同的成对比较:使用pairwise.t.test函数执行多个分组数据均值的两两成对假设检验
mysql的表分区
Intelligent information retrieval (overview of intelligent information retrieval)
嵌套事务 UnexpectedRollbackException 分析与事务传播策略
Scott+Scott律所计划对Yuga Labs提起集体诉讼,或将确认NFT是否属于证券产品
Resttemplate and ribbon are easy to use
scrapy 爬虫框架简介
使用TensorBoard可视化训练过程
微软Azure和易观分析联合发布《企业级云原生平台驱动数字化转型》报告
Ansible
Unexpected rollback exception analysis and transaction propagation strategy for nested transactions
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
PyTorch进阶训练技巧