当前位置:网站首页>Introduction to pytorch ecology
Introduction to pytorch ecology
2022-07-24 03:28:00 【Orange @ orange】
PyTorch The power of is not limited to its own ease of use , What's more, the open source community revolves around PyTorch A series of toolkits ( It's usually Python package) And procedure , These kits are a great convenience PyTorch Use in specific areas . For example, for image processing, we usually use torchvision, For video processing, I will use torchvideo, For text processing, we will use torchtext wait . Together, these excellent toolkits make up PyTorch The ecology of . Use... In a specific field PyTorch Toolkit in Ecology , It can greatly reduce the entry threshold , It is convenient for novices to quickly master the coding in specific fields .
( One )torchvision
torchvision yes PyTorch A library for image processing in , It mainly deals with models and data sets in the direction of computer vision .
- torchvision.datasets: Used to load some built-in data sets and some commonly used functions .
- torchvision.models: Used to load PyTorch Built in model , And the pre training parameters of these models can be downloaded together .
- torchvision.transforms: For image transformation , Enhance the data . for example : Random scaling (transforms.Resize)、 Random position clipping (transforms.RandomCrop)、 Random rotation (transforms.RandomRotation()) etc. .
- torchvision.utils: Provides some visual methods , You can splice several pictures together 、 Visualize the effect of detection and segmentation .
import torchvision
from torchvision import datasets, transforms
# Load the built-in model Resnet18
model=torchvision.models.resnet18(pretrained=True)
# Load the built-in dataset MINIST
train_ds=datasets.MNIST('data', train=True, transform=ToTensor(), download=True)
test_ds=datasets.MNIST('data', train=False, transform=ToTensor(), download=True)
# use transforms Enhance data
transform_train=transforms.Compose([transforms.Resize(224), # Random scaling
transforms.RandomCrop(192), # Random position clipping
transforms.RandomHorizontalFlip(), # Random horizontal flip
transforms.RandomRotation(0.2), # Random rotation
transforms.ColorJitter(brightness=0.5,), # Adjust the brightness of the picture
transforms.ColorJitter(contrast=0.5,), # Image data enhancement
transforms.ToTensor(),# Convert the image into tensor; Change the picture format ; Normalize the pixel value range to (0,1)
transforms.Normalize(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]),# Data normalization
( Two )torchcideo
TorchVideo It is a deep learning library focusing on video understanding .torchVideo It provides the reusable software needed to accelerate the research of video understanding 、 Modular and efficient components .TorchVideo It's using PyTorch Developed , Support different in-depth learning video components , Such as video model 、 Video dataset and video specific conversion .
PytorchVideo It provides a modular and efficient method to accelerate the research of video understanding API. It also supports different deep learning video components , Such as video model 、 Video dataset and video specific conversion , most important of all ,PytorchVideo Also provided model zoo, So that people can use various advanced pre training video models and their evaluation benchmarks .
( 3、 ... and )torchtext
torchtext yes PyTorch Officially used for natural language processing (NLP) The toolkit .
torchtext It is convenient to preprocess the text , For example, truncation and lengthening 、 Construct thesaurus, etc .torchtext It mainly includes the following main components :1. Data processing tools (torchtext.data.functional、torchtext.data.utils)、2. load NLP Built in datasets (torchtext.data.datasets)、3. Building a vocabulary (torchtext.vocab) etc. .
import torch
import torchtext
# Load text built-in dataset
train_iter, test_iter=torchtext.datasets.IMDB()
#torchtext Built in word segmentation tool
from torchtext.data.utils import get_tokenizer
tokenizer=get_tokenizer('basic_english') #basic_english: Will turn letters into lowercase and divide by spaces , Can split punctuation marks .
#torchtext Built in tool for creating thesaurus
from torchtext.vocab import build_vocab_from_iterator
def yield_tokens(data): # When creating a thesaurus, you need to pass in a generator , So first define a generator function
for (_,text) in data:
yield tokenizer(text)
vocab=build_vocab_from_iterator(yield_tokens(train_data),
specials=['<pad>', '<unk>'],
min_freq=3)
vocab.set_default_index(vocab['<unk>'])notes :torchtext When installing, its version needs to be the same as that installed by yourself PyTorch The version corresponds to , Otherwise, it will not work properly . You can refer to the following website (https://pypi.org/project/torchtext/).
边栏推荐
- 08 reptile project
- The error of van swipe in the rotation chart: cannot read a properties of null (reading width)
- Do you know how to do interface testing well?
- Tetris, 1
- Advantages, disadvantages and summary of sequence list and linked list
- Regular expression \b \b understand word boundary matching in simple terms
- FTP服务与配置
- Secondary development of ArcGIS JS API -- loading national sky map
- IDEA Clone的项目报Cannot resolve symbol ‘Override‘
- Preliminary exploration of Flink principle and flow batch integration API (II) V2
猜你喜欢

Rpc-bdy (5) - automatic service logoff, load balancing

JIRA automation experience sharing for 2 years

实现两个页面之前的通信(使用localStorage)

C自定义类型详解

What is the experience of writing concurrent tool classes (semaphore, cyclicbarrier, countdownlatch) by yourself in line 30?

Leetcode-382. random nodes of linked list

IDEA Clone的项目报Cannot resolve symbol ‘Override‘

Do you know how to do interface testing well?

Expressions régulières \ \ B \ \ b compréhension de l'appariement des limites des mots

Babylon.js cool canvas background animation JS special effects
随机推荐
Skywalking distributed system application performance monitoring tool - upper
Keras deep learning practice (15) -- realize Yolo target detection from scratch
uva1467
Using global data to realize data sharing in wechat applet
Okaleido tiger NFT is about to log in to the binance NFT platform. Are you looking forward to it?
Qt自定义类使用自定义含参信号与槽
IDEA Clone的项目报Cannot resolve symbol ‘Override‘
What is the experience of writing concurrent tool classes (semaphore, cyclicbarrier, countdownlatch) by yourself in line 30?
QT custom class uses custom parametric signals and slots
Binary tree traversal
1. Learn to understand web pages
Preliminary exploration of Flink principle and flow batch integration API (II) V2
Hospital PACS source code PACS ultrasonic Department source code DICOM image workstation source code [source code free sharing]
leetcode hot 100(刷題篇8)(232/88/451/offer10/offer22/344/)
openEuler 资源利用率提升之道 01:概论
Istio architecture extension mechanism
MySQL sub database and sub table and its smooth expansion scheme
Idea failed to load resource: the server responded with a status of 404 (not found)
Appendtofile append failed
移动通信的新定义:R&SCMX500 将提高5G设备的IP数据吞吐量