Skip to content

Instantly share code, notes, and snippets.

View dvgodoy's full-sized avatar

Daniel Voigt Godoy dvgodoy

View GitHub Profile
square = exponentiation_builder(2)
cube = exponentiation_builder(3)
fourth_power = exponentiation_builder(4)
# and so on and so forth...
def exponentiation_builder(exponent):
def skeleton_exponentiation(x):
return x ** exponent
return skeleton_exponentiation
def skeleton_exponentiation(x):
return x ** exponent
def generic_exponentiation(x, exponent):
return x ** exponent
def square(x):
return x ** 2
def cube(x):
return x ** 3
def fourth_power(x):
return x ** 4
# and so on and so forth...
decoder_cnn = nn.Sequential(
# z_size -> (n_filters*2)*7*7
nn.Linear(z_size, (n_filters*2)*int(img_size/4)**2),
# (n_filters*2)*7*7 -> (n_filters*2)@7x7
nn.Unflatten(1, (n_filters*2, int(img_size/4), int(img_size/4))),
# (n_filters*2)@7x7 -> (n_filters*2)@7x7
nn.ConvTranspose2d(n_filters*2, n_filters*2, kernel_size=3, stride=1, padding=1, output_padding=0),
nn.LeakyReLU(),
set_seed(13)
z_size = 1
n_filters = 32
in_channels = 1
img_size = 28
input_shape = (in_channels, img_size, img_size)
base_model = nn.Sequential(
# in_channels@28x28 -> n_filters@28x28
device = 'cuda' if torch.cuda.is_available() else 'cpu'
model_vae_cnn = AutoEncoder(encoder_var_cnn, decoder_cnn)
model_vae_cnn.to(device)
loss_fn = nn.MSELoss(reduction='none')
optim = torch.optim.Adam(model_vae_cnn.parameters(), 0.0003)
num_epochs = 30
train_losses = []
device = 'cuda' if torch.cuda.is_available() else 'cpu'
model_vae.to(device)
loss_fn = nn.MSELoss(reduction='none')
optim = torch.optim.Adam(model_vae.parameters(), 0.0003)
num_epochs = 30
train_losses = []
reconstruction_loss_factor = 1
@dvgodoy
dvgodoy / vae.py
Last active April 30, 2022 09:47
set_seed(13)
z_size = 1
input_shape = (1, 28, 28)
base_model = nn.Sequential(
# (C, H, W) -> C*H*W
nn.Flatten(),
# C*H*W -> 2048
nn.Linear(np.prod(input_shape), 2048),