-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from mk314k/development
complete attention
- Loading branch information
Showing
33 changed files
with
360 additions
and
861 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
name: Pylint | ||
|
||
on: [push] | ||
on: | ||
push: | ||
branches: [ "main" ] | ||
|
||
jobs: | ||
build: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
""" | ||
_summary_ | ||
""" | ||
import torch | ||
from matplotlib import pyplot as plt | ||
import tqdm.auto as tqdm | ||
from utils import load_data | ||
from train import train_epoch | ||
from models.r3d import R3D | ||
|
||
|
||
if __name__ == "__main__": | ||
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') | ||
|
||
|
||
TRAIN_DATA_PATH = "data/shapenetcore/train_imgs" | ||
TEST_DATA_PATH = "data/shapenetcore/test_imgs" | ||
VOXEL_SIZE = 64 | ||
pixel_shape = (192,256) | ||
|
||
train_2d, train_3d = load_data( | ||
TRAIN_DATA_PATH, | ||
voxel_size = VOXEL_SIZE, | ||
pixel_shape = pixel_shape, | ||
device = device | ||
) | ||
test_2d, test_3d = load_data( | ||
TEST_DATA_PATH, | ||
voxel_size = VOXEL_SIZE, | ||
pixel_shape = pixel_shape, | ||
device = device | ||
) | ||
|
||
|
||
model = R3D( | ||
|
||
).to(device) | ||
|
||
# Setting hyperparameters for optimizers | ||
LR = 1e-3 | ||
WD = 0.2 | ||
betas=(0.9, 0.98) | ||
# Initializing optimizers | ||
vae_optim = torch.optim.AdamW( | ||
model.vae_parameters(), | ||
lr=LR, | ||
weight_decay=WD, | ||
betas=betas | ||
) | ||
gan_optim = torch.optim.AdamW( | ||
model.gan_parameters(), | ||
lr=LR, | ||
weight_decay=WD, | ||
betas=betas | ||
) | ||
NUM_EPOCHS = 25 | ||
train_loss = [] | ||
for _ in tqdm.tqdm(NUM_EPOCHS): | ||
train_loss.append(train_epoch( | ||
train_2d, train_3d, model, vae_optim, gan_optim | ||
)) | ||
# Plotting training losses | ||
plt.figure(figsize=(16, 6)) | ||
plt.plot(range(len(train_loss)), [tloss[0] for tloss in train_loss], label='Training VAE loss') | ||
plt.plot(range(len(train_loss)), [tloss[1] for tloss in train_loss], label='Training GAN loss') | ||
plt.xlabel('Epoch') | ||
plt.ylabel('Loss') | ||
plt.title('Model Performance') | ||
plt.legend() | ||
plt.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
""" | ||
This is an optional wrapper for VAE_GAN Model | ||
""" | ||
import torch | ||
from encoder import R3DEncoder | ||
from generator import R3DGenerator | ||
from discriminator import R3Discriminator | ||
|
||
class R3D: | ||
""" | ||
The main model | ||
""" | ||
def __init__(self, # pylint: disable=too-many-arguments | ||
in_channel=1, | ||
num_patches=128, | ||
embedding_dim=64, | ||
embedding_kernel=3, | ||
attention_head=4, | ||
latent_dim=1024 | ||
): | ||
self.encoder = R3DEncoder( | ||
in_channel, num_patches, embedding_dim, embedding_kernel, attention_head, latent_dim | ||
) | ||
self.generator = R3DGenerator(latent_dim) | ||
self.discriminator = R3Discriminator() | ||
self.enc = None | ||
self.gan = None | ||
self.disc_true = None | ||
self.disc_false = None | ||
|
||
def __call__(self, x:torch.Tensor, y:torch.Tensor)->torch.Tensor: | ||
self.enc = self.encoder(x) | ||
self.gan = self.generator(self.enc) | ||
self.disc_true = self.discriminator(y.reshape(1, *y.shape)) | ||
self.disc_false = self.discriminator(self.gan) | ||
|
||
return self.gan | ||
|
||
def vae_parameters(self): | ||
""" | ||
Returns: | ||
list of parameters for encoding 2d images and generating 3d images | ||
""" | ||
return list(self.encoder.parameters()) + list(self.generator.parameters()) | ||
|
||
def gan_parameters(self): | ||
""" | ||
Returns: | ||
list of parameters for 3d image generation and discrimination | ||
""" | ||
return list(self.generator.parameters()) + list(self.discriminator.parameters()) |
Oops, something went wrong.