Commit
·
387aa7a
1
Parent(s):
8ff4a33
updated license
Browse files- README.md +12 -1
- _utils.py +29 -0
- attention.py +29 -0
- modeling_vqvae.py +29 -30
README.md
CHANGED
|
@@ -1,3 +1,14 @@
|
|
| 1 |
---
|
| 2 |
-
license:
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
license: mit
|
| 3 |
---
|
| 4 |
+
|
| 5 |
+
# VQVAE
|
| 6 |
+
|
| 7 |
+
This repository is a clone of the [VideoGPT](https://github.com/wilson1yan/VideoGPT/tree/master) in order to convert the VQ-VAE model to the Hugging Face format for easier model loading.
|
| 8 |
+
|
| 9 |
+
Paper: [VideoGPT: Video Generation using VQ-VAE and Transformers](https://arxiv.org/abs/2104.10157)
|
| 10 |
+
|
| 11 |
+
## License
|
| 12 |
+
|
| 13 |
+
We follow the MIT license distributed by the [VideoGPT](https://github.com/wilson1yan/VideoGPT/tree/master) project.
|
| 14 |
+
|
_utils.py
CHANGED
|
@@ -1,3 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
# Shifts src_tf dim to dest dim
|
| 2 |
# i.e. shift_dim(x, 1, -1) would be (b, c, t, h, w) -> (b, t, h, w, c)
|
| 3 |
def shift_dim(x, src_dim=-1, dest_dim=-1, make_contiguous=True):
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
MIT License
|
| 3 |
+
|
| 4 |
+
Copyright (c) 2021 Wilson Yan
|
| 5 |
+
|
| 6 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 7 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 8 |
+
in the Software without restriction, including without limitation the rights
|
| 9 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 10 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 11 |
+
furnished to do so, subject to the following conditions:
|
| 12 |
+
|
| 13 |
+
The above copyright notice and this permission notice shall be included in all
|
| 14 |
+
copies or substantial portions of the Software.
|
| 15 |
+
|
| 16 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 17 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 18 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 19 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 20 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 21 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 22 |
+
SOFTWARE.
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
This file is copied from https://github.com/wilson1yan/VideoGPT/blob/master/videogpt/utils.py
|
| 26 |
+
We adapted it to Hugging Face AutoModel for easier model loading.
|
| 27 |
+
"""
|
| 28 |
+
|
| 29 |
+
|
| 30 |
# Shifts src_tf dim to dest dim
|
| 31 |
# i.e. shift_dim(x, 1, -1) would be (b, c, t, h, w) -> (b, t, h, w, c)
|
| 32 |
def shift_dim(x, src_dim=-1, dest_dim=-1, make_contiguous=True):
|
attention.py
CHANGED
|
@@ -1,3 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import numpy as np
|
| 2 |
|
| 3 |
import torch
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
MIT License
|
| 3 |
+
|
| 4 |
+
Copyright (c) 2021 Wilson Yan
|
| 5 |
+
|
| 6 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 7 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 8 |
+
in the Software without restriction, including without limitation the rights
|
| 9 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 10 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 11 |
+
furnished to do so, subject to the following conditions:
|
| 12 |
+
|
| 13 |
+
The above copyright notice and this permission notice shall be included in all
|
| 14 |
+
copies or substantial portions of the Software.
|
| 15 |
+
|
| 16 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 17 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 18 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 19 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 20 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 21 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 22 |
+
SOFTWARE.
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
This file is copied from https://github.com/wilson1yan/VideoGPT/blob/master/videogpt/attention.py
|
| 26 |
+
We adapted it to Hugging Face AutoModel for easier model loading.
|
| 27 |
+
"""
|
| 28 |
+
|
| 29 |
+
|
| 30 |
import numpy as np
|
| 31 |
|
| 32 |
import torch
|
modeling_vqvae.py
CHANGED
|
@@ -1,3 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
import math
|
| 3 |
import numpy as np
|
|
@@ -6,43 +35,13 @@ import torch
|
|
| 6 |
import torch.nn as nn
|
| 7 |
import torch.nn.functional as F
|
| 8 |
import torch.distributed as dist
|
| 9 |
-
import gdown
|
| 10 |
|
| 11 |
from .attention import MultiHeadAttention
|
| 12 |
from ._utils import shift_dim
|
| 13 |
from transformers import PreTrainedModel
|
| 14 |
-
from typing import Tuple
|
| 15 |
from .configuration_vqvae import VQVAEConfig
|
| 16 |
|
| 17 |
|
| 18 |
-
_VQVAE = {
|
| 19 |
-
'bair_stride4x2x2': '1iIAYJ2Qqrx5Q94s5eIXQYJgAydzvT_8L', # trained on 16 frames of 64 x 64 images
|
| 20 |
-
'ucf101_stride4x4x4': '1uuB_8WzHP_bbBmfuaIV7PK_Itl3DyHY5', # trained on 16 frames of 128 x 128 images
|
| 21 |
-
'kinetics_stride4x4x4': '1DOvOZnFAIQmux6hG7pN_HkyJZy3lXbCB', # trained on 16 frames of 128 x 128 images
|
| 22 |
-
'kinetics_stride2x4x4': '1jvtjjtrtE4cy6pl7DK_zWFEPY3RZt2pB' # trained on 16 frames of 128 x 128 images
|
| 23 |
-
}
|
| 24 |
-
|
| 25 |
-
def download(id, fname, root=None):
|
| 26 |
-
"""
|
| 27 |
-
Download the VQVAE weights from Google Drive.
|
| 28 |
-
|
| 29 |
-
Args:
|
| 30 |
-
id (str): the ID of the file to download
|
| 31 |
-
fname (str): the name of the file to save
|
| 32 |
-
root (str): the directory to save the file to
|
| 33 |
-
"""
|
| 34 |
-
if root is None:
|
| 35 |
-
root = os.path.expanduser('~/.cache/sora')
|
| 36 |
-
os.makedirs(root, exist_ok=True)
|
| 37 |
-
destination = os.path.join(root, fname)
|
| 38 |
-
|
| 39 |
-
if os.path.exists(destination):
|
| 40 |
-
return destination
|
| 41 |
-
|
| 42 |
-
gdown.download(id=id, output=destination, quiet=False)
|
| 43 |
-
return destination
|
| 44 |
-
|
| 45 |
-
|
| 46 |
class VQVAE(PreTrainedModel):
|
| 47 |
config_class = VQVAEConfig
|
| 48 |
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
MIT License
|
| 3 |
+
|
| 4 |
+
Copyright (c) 2021 Wilson Yan
|
| 5 |
+
|
| 6 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 7 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 8 |
+
in the Software without restriction, including without limitation the rights
|
| 9 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 10 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 11 |
+
furnished to do so, subject to the following conditions:
|
| 12 |
+
|
| 13 |
+
The above copyright notice and this permission notice shall be included in all
|
| 14 |
+
copies or substantial portions of the Software.
|
| 15 |
+
|
| 16 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 17 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 18 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 19 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 20 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 21 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 22 |
+
SOFTWARE.
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
This file is copied from https://github.com/wilson1yan/VideoGPT/blob/master/videogpt/vqvae.py
|
| 26 |
+
We adapted it to Hugging Face AutoModel for easier model loading.
|
| 27 |
+
"""
|
| 28 |
+
|
| 29 |
+
|
| 30 |
import os
|
| 31 |
import math
|
| 32 |
import numpy as np
|
|
|
|
| 35 |
import torch.nn as nn
|
| 36 |
import torch.nn.functional as F
|
| 37 |
import torch.distributed as dist
|
|
|
|
| 38 |
|
| 39 |
from .attention import MultiHeadAttention
|
| 40 |
from ._utils import shift_dim
|
| 41 |
from transformers import PreTrainedModel
|
|
|
|
| 42 |
from .configuration_vqvae import VQVAEConfig
|
| 43 |
|
| 44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
class VQVAE(PreTrainedModel):
|
| 46 |
config_class = VQVAEConfig
|
| 47 |
|