偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

GitHub 7.5k star量,各種視覺Transformer的PyTorch實現(xiàn)合集整理好了

人工智能 新聞
該項目名為「vit-pytorch」,它是一個 Vision Transformer 實現(xiàn),展示了一種在 PyTorch 中僅使用單個 transformer 編碼器來實現(xiàn)視覺分類 SOTA 結(jié)果的簡單方法。

近一兩年,Transformer 跨界 CV 任務不再是什么新鮮事了。

自 2020 年 10 月谷歌提出 Vision Transformer (ViT) 以來,各式各樣視覺 Transformer 開始在圖像合成、點云處理、視覺 - 語言建模等領(lǐng)域大顯身手。

之后,在 PyTorch 中實現(xiàn) Vision Transformer 成為了研究熱點。GitHub 中也出現(xiàn)了很多優(yōu)秀的項目,今天要介紹的就是其中之一。

該項目名為「vit-pytorch」,它是一個 Vision Transformer 實現(xiàn),展示了一種在 PyTorch 中僅使用單個 transformer 編碼器來實現(xiàn)視覺分類 SOTA 結(jié)果的簡單方法。

項目當前的 star 量已經(jīng)達到了 7.5k,創(chuàng)建者為 Phil Wang,ta 在 GitHub 上有 147 個資源庫。

圖片

項目地址:https://github.com/lucidrains/vit-pytorch

項目作者還提供了一段動圖展示:

圖片

項目介紹

首先來看 Vision Transformer-PyTorch 的安裝、使用、參數(shù)、蒸餾等步驟。

第一步是安裝:

$ pip install vit-pytorch

第二步是使用:

import torch
from vit_pytorch import ViT

v = ViT(
    image_size = 256,
    patch_size = 32,
    num_classes = 1000,
    dim = 1024,
    depth = 6,
    heads = 16,
    mlp_dim = 2048,
    dropout = 0.1,
    emb_dropout = 0.1
)

img = torch.randn(1, 3, 256, 256)

preds = v(img) # (1, 1000)

第三步是所需參數(shù),包括如下:

  • image_size:圖像大小
  • patch_size:patch 數(shù)量
  • num_classes:分類類別的數(shù)量
  • dim:線性變換 nn.Linear(..., dim) 后輸出張量的最后維
  • depth:Transformer 塊的數(shù)量
  • heads:多頭注意力層中頭的數(shù)量
  • mlp_dim:MLP(前饋)層的維數(shù)
  • channels:圖像通道的數(shù)量
  • dropout:Dropout rate
  • emb_dropout:嵌入 dropout rate
  • ……

最后是蒸餾,采用的流程出自 Facebook AI 和索邦大學的論文《Training data-efficient image transformers & distillation through attention》。

圖片

論文地址:https://arxiv.org/pdf/2012.12877.pdf

從 ResNet50(或任何教師網(wǎng)絡)蒸餾到 vision transformer 的代碼如下:

import torchfrom torchvision.models import resnet50from vit_pytorch.distill import DistillableViT, DistillWrapperteacher = resnet50(pretrained = True)
v = DistillableViT(
    image_size = 256,
    patch_size = 32,
    num_classes = 1000,
    dim = 1024,
    depth = 6,
    heads = 8,
    mlp_dim = 2048,
    dropout = 0.1,
    emb_dropout = 0.1
)
distiller = DistillWrapper(
    student = v,
    teacher = teacher,
    temperature = 3,           # temperature of distillationalpha = 0.5,               # trade between main loss and distillation losshard = False               # whether to use soft or hard distillation
)
img = torch.randn(2, 3, 256, 256)labels = torch.randint(0, 1000, (2,))
loss = distiller(img, labels)loss.backward()
# after lots of training above ...pred = v(img) # (2, 1000)

除了 Vision Transformer 之外,該項目還提供了 Deep ViT、CaiT、Token-to-Token ViT、PiT 等其他 ViT 變體模型的 PyTorch 實現(xiàn)。

圖片

對 ViT 模型 PyTorch 實現(xiàn)感興趣的讀者可以參閱原項目。

責任編輯:張燕妮 來源: 計算機視覺研究院
相關(guān)推薦

2019-01-16 10:55:08

Python 開發(fā)編程語言

2019-02-19 10:23:53

GitHub 技術(shù)性能

2021-11-04 09:08:39

項目JS 解構(gòu)知識

2023-01-05 17:55:39

分布式架構(gòu)

2021-02-23 15:54:23

編程技能開發(fā)

2018-08-03 10:49:00

2023-12-06 09:37:55

模型視覺

2021-11-02 08:14:36

個人信息保護法信息安全個人信息

2020-08-21 13:55:56

微軟開源PyTorch

2022-04-28 13:17:10

低代碼開發(fā)工具

2020-11-02 14:49:46

GitHub Java圖片

2021-09-09 07:21:25

項目GithubRedux-Thunk

2020-10-28 09:50:05

GitHubPython項目

2025-01-22 13:15:10

2023-07-03 09:55:01

2023-12-08 08:01:29

分布式IM即時通訊系統(tǒng)架構(gòu)設計

2025-04-23 09:21:10

2020-02-27 09:46:19

GitHub代碼開發(fā)者

2024-12-16 08:06:42

2022-04-11 09:20:00

模型訓練
點贊
收藏

51CTO技術(shù)棧公眾號