Shortcuts

Convolutional Architectures

This package lists contributed convolutional architectures.


GPT-2

class pl_bolts.models.vision.image_gpt.gpt2.GPT2(embed_dim, heads, layers, num_positions, vocab_size, num_classes)[source]

Bases: pytorch_lightning.LightningModule

GPT-2 from language Models are Unsupervised Multitask Learners

Paper by: Alec Radford, Jeffrey Wu, Rewon Child, David Luan, Dario Amodei, Ilya Sutskever

Implementation contributed by:

Example:

from pl_bolts.models import GPT2

seq_len = 17
batch_size = 32
vocab_size = 16
x = torch.randint(0, vocab_size, (seq_len, batch_size))
model = GPT2(embed_dim=32, heads=2, layers=2, num_positions=seq_len, vocab_size=vocab_size, num_classes=4)
results = model(x)
forward(x, classify=False)[source]

Expect input as shape [sequence len, batch] If classify, return classification logits


Image GPT

class pl_bolts.models.vision.image_gpt.igpt_module.ImageGPT(datamodule=None, embed_dim=16, heads=2, layers=2, pixels=28, vocab_size=16, num_classes=10, classify=False, batch_size=64, learning_rate=0.01, steps=25000, data_dir='.', num_workers=8, **kwargs)[source]

Bases: pytorch_lightning.LightningModule

Paper: Generative Pretraining from Pixels [original paper code].

Paper by: Mark Che, Alec Radford, Rewon Child, Jeff Wu, Heewoo Jun, Prafulla Dhariwal, David Luan, Ilya Sutskever

Implementation contributed by:

Original repo with results and more implementation details:

Example Results (Photo credits: Teddy Koker):

credit-Teddy-Koker credit-Teddy-Koker

Default arguments:

Argument Defaults

Argument

Default

iGPT-S (Chen et al.)

–embed_dim

16

512

–heads

2

8

–layers

8

24

–pixels

28

32

–vocab_size

16

512

–num_classes

10

10

–batch_size

64

128

–learning_rate

0.01

0.01

–steps

25000

1000000

Example:

import pytorch_lightning as pl
from pl_bolts.models.vision import ImageGPT

dm = MNISTDataModule('.')
model = ImageGPT(dm)

pl.Trainer(gpu=4).fit(model)

As script:

cd pl_bolts/models/vision/image_gpt
python igpt_module.py --learning_rate 1e-2 --batch_size 32 --gpus 4
Parameters
  • datamodule (Optional[LightningDataModule]) – LightningDataModule

  • embed_dim (int) – the embedding dim

  • heads (int) – number of attention heads

  • layers (int) – number of layers

  • pixels (int) – number of input pixels

  • vocab_size (int) – vocab size

  • num_classes (int) – number of classes in the input

  • classify (bool) – true if should classify

  • batch_size (int) – the batch size

  • learning_rate (float) – learning rate

  • steps (int) – number of steps for cosine annealing

  • data_dir (str) – where to store data

  • num_workers (int) – num_data workers


Pixel CNN

class pl_bolts.models.vision.pixel_cnn.PixelCNN(input_channels, hidden_channels=256, num_blocks=5)[source]

Bases: torch.nn.Module

Implementation of Pixel CNN.

Paper authors: Aaron van den Oord, Nal Kalchbrenner, Oriol Vinyals, Lasse Espeholt, Alex Graves, Koray Kavukcuoglu

Implemented by:

  • William Falcon

Example:

>>> from pl_bolts.models.vision import PixelCNN
>>> import torch
...
>>> model = PixelCNN(input_channels=3)
>>> x = torch.rand(5, 3, 64, 64)
>>> out = model(x)
...
>>> out.shape
torch.Size([5, 3, 64, 64])
Read the Docs v: 0.2.2
Versions
latest
stable
0.2.2
0.2.1
0.2.0
0.1.1
0.1.0
Downloads
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.