Giter Site home page Giter Site logo

conformervit's Introduction

Conformer-ViT

This repository extends Vision Transformers and Conformers for Image Classification and Image2Seq tasks such as OCR and Captioning.

Usage - Image2Seq

from conformer_vit import ConformerViTForImage2Seq
import torch

model = ConformerViTForImage2Seq(
    image_size=256,
    patch_size=16,
    num_classes=150,
    dim=320,
    depth=12,
    heads=8,
    decoder_dim=640,
    output_seq_len=128,
    decoder_type="transformer",
    SOS_token=1,
    EOS_token=2,
    channels=1,
    dropout=0.1,
    emb_dropout=0.1,
    kernel_size=17,
    causal=False
)

inp = torch.randn(1, 1, 64, 256)
target_seq = torch.randint(0, 150, (1, 128))
pred = model(inp, target_seq=target_seq, teacher_forcing_ratio=0.5)
print(pred.shape) # (1, 128, 150)

Usage - Image Classification

from conformer_vit import ConformerViTForClassification
import torch

model = ConformerViTForClassification(
    image_size=256,
    patch_size=32,
    num_classes=1000,
    dim=144,
    depth=12,
    heads=16,
    dropout=0.1,
    emb_dropout=0.1
)

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

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

Acknowledgement

Code for Decoder borrowed from here

conformervit's People

Contributors

ojus1 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.