ZikangZhou / vector-quantize-pytorch

Vector Quantization, in Pytorch

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Vector Quantization, in Pytorch

A vector quantization library originally transcribed from Deepmind's tensorflow implementation, made conveniently into a package. It uses exponential moving averages to update the dictionary.

VQ has been successfully used by Deepmind and OpenAI for high quality generation of images (VQ-VAE-2) and music (Jukebox).

Install

$ pip install vector-quantize-pytorch

Usage

import torch
from vector_quantize_pytorch import VectorQuantize

vq = VectorQuantize(
    dim = 256,
    n_embed = 512,     # size of the dictionary
    decay = 0.8,       # the exponential moving average decay, lower means the dictionary will change faster
    commitment = 1.    # the weight on the commitment loss
)

x = torch.randn(1, 1024, 256)
quantized, indices, commit_loss = vq(x) # (1, 1024, 256), (1, 1024), (1)

About

Vector Quantization, in Pytorch

License:MIT License


Languages

Language:Python 100.0%