Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,9 @@ def final_test_epoch(model, dataloader,criterion):
decoder = Decoder().to(device)
disc = Discriminator().to(device)

if device != 'cpu':
encoder.load_state_dict(torch.load(MODEL_PATH + 'encoder.pth'))
decoder.load_state_dict(torch.load(MODEL_PATH + 'decoder.pth'))
disc.load_state_dict(torch.load(MODEL_PATH + 'discriminator.pth'))
else:
encoder.load_state_dict(torch.load(MODEL_PATH + 'encoder.pth', map_location = torch.device('cpu')))
decoder.load_state_dict(torch.load(MODEL_PATH + 'decoder.pth', map_location = torch.device('cpu')))
disc.load_state_dict(torch.load(MODEL_PATH + 'discriminator.pth', map_location = torch.device('cpu')))
encoder.load_state_dict(torch.load(MODEL_PATH + 'encoder.pth', map_location=device, weights_only=True))
decoder.load_state_dict(torch.load(MODEL_PATH + 'decoder.pth', map_location=device, weights_only=True))
disc.load_state_dict(torch.load(MODEL_PATH + 'discriminator.pth', map_location=device, weights_only=True))

model = {'enc':encoder,
'dec': decoder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,9 @@ def fit_model(model, checkpoint_path):
disc = Discriminator().to(device)

if LOAD_PRETRAINED_MODEL:
if device != 'cpu':
encoder.load_state_dict(torch.load(MODEL_PATH + 'encoder.pth'))
decoder.load_state_dict(torch.load(MODEL_PATH + 'decoder.pth'))
disc.load_state_dict(torch.load(MODEL_PATH + 'discriminator.pth'))

else:
encoder.load_state_dict(torch.load(MODEL_PATH + 'encoder.pth', map_location = torch.device('cpu')))
decoder.load_state_dict(torch.load(MODEL_PATH + 'decoder.pth', map_location = torch.device('cpu')))
disc.load_state_dict(torch.load(MODEL_PATH + 'discriminator.pth', map_location = torch.device('cpu')))
encoder.load_state_dict(torch.load(MODEL_PATH + 'encoder.pth', map_location=device, weights_only=True))
decoder.load_state_dict(torch.load(MODEL_PATH + 'decoder.pth', map_location=device, weights_only=True))
disc.load_state_dict(torch.load(MODEL_PATH + 'discriminator.pth', map_location=device, weights_only=True))

model = {'enc':encoder,
'dec': decoder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ def final_test_epoch(model, dataloader,criterion):
set_seed(7)

model = Autoencoder().to(device)
if device != 'cpu':
model.load_state_dict(torch.load(MODEL_PATH))
else:
model.load_state_dict(torch.load(MODEL_PATH, map_location = torch.device('cpu')))
model.load_state_dict(torch.load(MODEL_PATH, map_location=device, weights_only=True))

full_test_loader, class_map = create_full_test_dataloader(FULL_TEST_DATA_PATH, test_transforms, BATCH_SIZE)
criterion = nn.MSELoss()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,7 @@ def fit_model(model, checkpoint_path):
model = Autoencoder().to(device)

if LOAD_PRETRAINED_MODEL:
if device != 'cpu':
model.load_state_dict(torch.load(MODEL_PATH))
else:
model.load_state_dict(torch.load(MODEL_PATH, map_location = torch.device('cpu')))
model.load_state_dict(torch.load(MODEL_PATH, map_location=device, weights_only=True))

model, loss_dict = fit_model(model, checkpoint_path = MODEL_PATH)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,5 @@ def forward(self, x):
encoder = Encoder()
decoder = Decoder()
model = VAE(encoder, decoder)
if device != 'cpu':
model.load_state_dict(torch.load(MODEL_PATH))
else:
model.load_state_dict(torch.load(MODEL_PATH, map_location = torch.device('cpu')))
model.load_state_dict(torch.load(MODEL_PATH, map_location=device, weights_only=True))
print(model)
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ def final_test_epoch(model, dataloader,criterion):
encoder = Encoder().to(device)
decoder = Decoder().to(device)
model = VAE(encoder, decoder).to(device)
if device != 'cpu':
model.load_state_dict(torch.load(MODEL_PATH))
else:
model.load_state_dict(torch.load(MODEL_PATH, map_location = torch.device('cpu')))
model.load_state_dict(torch.load(MODEL_PATH, map_location=device, weights_only=True))

full_test_loader, class_map = create_full_test_dataloader(FULL_TEST_DATA_PATH, test_transforms, BATCH_SIZE)
criterion = nn.MSELoss()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def plot_ae_outputs(model, dataloader, n = 10):
def fit_model(model, checkpoint_path):

optimizer = optim.Adam(model.parameters(), lr = LEARNING_RATE)
scheduler = optim.lr_scheduler.OneCycleLR(optimizer, LEARNING_RATE, epochs = EPOCHS, steps_per_epoch = len(train_loader), verbose = False)
scheduler = optim.lr_scheduler.OneCycleLR(optimizer, LEARNING_RATE, epochs=EPOCHS, steps_per_epoch=len(train_loader))
criterion = nn.MSELoss()

loss_dict = {'train_loss':[],'val_loss':[], 'train_kld_loss':[], 'val_kld_loss':[]}
Expand Down Expand Up @@ -170,10 +170,7 @@ def fit_model(model, checkpoint_path):
model = VAE(encoder, decoder).to(device)

if LOAD_PRETRAINED_MODEL:
if device != 'cpu':
model.load_state_dict(torch.load(MODEL_PATH))
else:
model.load_state_dict(torch.load(MODEL_PATH, map_location = torch.device('cpu')))
model.load_state_dict(torch.load(MODEL_PATH, map_location=device, weights_only=True))

model, loss_dict = fit_model(model, checkpoint_path = MODEL_PATH)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,9 @@ def final_test_epoch(model, dataloader,criterion):
decoder = Decoder().to(device)
disc = Discriminator().to(device)

if device != 'cpu':
encoder.load_state_dict(torch.load(MODEL_PATH + 'encoder.pth'))
decoder.load_state_dict(torch.load(MODEL_PATH + 'decoder.pth'))
disc.load_state_dict(torch.load(MODEL_PATH + 'discriminator.pth'))
else:
encoder.load_state_dict(torch.load(MODEL_PATH + 'encoder.pth', map_location = torch.device('cpu')))
decoder.load_state_dict(torch.load(MODEL_PATH + 'decoder.pth', map_location = torch.device('cpu')))
disc.load_state_dict(torch.load(MODEL_PATH + 'discriminator.pth', map_location = torch.device('cpu')))
encoder.load_state_dict(torch.load(MODEL_PATH + 'encoder.pth', map_location=device, weights_only=True))
decoder.load_state_dict(torch.load(MODEL_PATH + 'decoder.pth', map_location=device, weights_only=True))
disc.load_state_dict(torch.load(MODEL_PATH + 'discriminator.pth', map_location=device, weights_only=True))

model = {'enc':encoder,
'dec': decoder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,9 @@ def fit_model(model, checkpoint_path):
disc = Discriminator().to(device)

if LOAD_PRETRAINED_MODEL:
if device != 'cpu':
encoder.load_state_dict(torch.load(MODEL_PATH + 'encoder.pth'))
decoder.load_state_dict(torch.load(MODEL_PATH + 'decoder.pth'))
disc.load_state_dict(torch.load(MODEL_PATH + 'discriminator.pth'))
else:
encoder.load_state_dict(torch.load(MODEL_PATH + 'encoder.pth', map_location = torch.device('cpu')))
decoder.load_state_dict(torch.load(MODEL_PATH + 'decoder.pth', map_location = torch.device('cpu')))
disc.load_state_dict(torch.load(MODEL_PATH + 'discriminator.pth', map_location = torch.device('cpu')))
encoder.load_state_dict(torch.load(MODEL_PATH + 'encoder.pth', map_location=device, weights_only=True))
decoder.load_state_dict(torch.load(MODEL_PATH + 'decoder.pth', map_location=device, weights_only=True))
disc.load_state_dict(torch.load(MODEL_PATH + 'discriminator.pth', map_location=device, weights_only=True))

model = {'enc':encoder,
'dec': decoder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ def final_test_epoch(model, dataloader,criterion):
set_seed(7)

model = Autoencoder().to(device)
if device != 'cpu':
model.load_state_dict(torch.load(MODEL_PATH))
else:
model.load_state_dict(torch.load(MODEL_PATH, map_location = torch.device('cpu')))
model.load_state_dict(torch.load(MODEL_PATH, map_location=device, weights_only=True))

full_test_loader, class_map = create_full_test_dataloader(FULL_TEST_DATA_PATH, test_transforms, BATCH_SIZE)
criterion = nn.MSELoss()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,7 @@ def fit_model(model, checkpoint_path):
model = Autoencoder().to(device)

if LOAD_PRETRAINED_MODEL:
if device != 'cpu':
model.load_state_dict(torch.load(MODEL_PATH))
else:
model.load_state_dict(torch.load(MODEL_PATH, map_location = torch.device('cpu')))
model.load_state_dict(torch.load(MODEL_PATH, map_location=device, weights_only=True))

model, loss_dict = fit_model(model, checkpoint_path = MODEL_PATH)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,5 @@ def forward(self, x):
encoder = Encoder()
decoder = Decoder()
model = VAE(encoder, decoder)
if device != 'cpu':
model.load_state_dict(torch.load(MODEL_PATH))
else:
model.load_state_dict(torch.load(MODEL_PATH, map_location = torch.device('cpu')))
model.load_state_dict(torch.load(MODEL_PATH, map_location=device, weights_only=True))
print(model)
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ def final_test_epoch(model, dataloader,criterion):
encoder = Encoder().to(device)
decoder = Decoder().to(device)
model = VAE(encoder, decoder).to(device)
if device != 'cpu':
model.load_state_dict(torch.load(MODEL_PATH))
else:
model.load_state_dict(torch.load(MODEL_PATH, map_location = torch.device('cpu')))
model.load_state_dict(torch.load(MODEL_PATH, map_location=device, weights_only=True))

full_test_loader, class_map = create_full_test_dataloader(FULL_TEST_DATA_PATH, test_transforms, BATCH_SIZE)
criterion = nn.MSELoss()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def fit_model(model,checkpoint_path):


optimizer = optim.Adam(model.parameters(), lr = LEARNING_RATE)
scheduler = optim.lr_scheduler.OneCycleLR(optimizer, LEARNING_RATE, epochs = EPOCHS, steps_per_epoch = len(train_loader), verbose = False)
scheduler = optim.lr_scheduler.OneCycleLR(optimizer, LEARNING_RATE, epochs=EPOCHS, steps_per_epoch=len(train_loader))
criterion = nn.MSELoss()

loss_dict = {'train_loss':[],'val_loss':[], 'train_kld_loss':[], 'val_kld_loss':[]}
Expand Down Expand Up @@ -171,10 +171,7 @@ def fit_model(model,checkpoint_path):
model = VAE(encoder, decoder).to(device)

if LOAD_PRETRAINED_MODEL:
if device != 'cpu':
model.load_state_dict(torch.load(MODEL_PATH))
else:
model.load_state_dict(torch.load(MODEL_PATH, map_location = torch.device('cpu')))
model.load_state_dict(torch.load(MODEL_PATH, map_location=device, weights_only=True))

model, loss_dict = fit_model(model, checkpoint_path = MODEL_PATH)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,7 @@ def flatten_list(x):
criterion = nn.CrossEntropyLoss()
model = EffNetB2_backbone_model().to(device)

if device != 'cpu':
model.load_state_dict(torch.load(MODEL_PATH))
else:
model.load_state_dict(torch.load(MODEL_PATH, map_location = torch.device('cpu')))
model.load_state_dict(torch.load(MODEL_PATH, map_location=device, weights_only=True))

_, _, test_loader, class_map = create_data_loaders(TRAIN_DATA_PATH, TEST_DATA_PATH,
val_split = 0.2, batch_size = BATCH_SIZE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def fit_model(model, criterion, optimizer):
loss_dict = {'train_loss':[],'val_loss':[]}
acc_dict = {'train_accuracy':[],'val_accuracy':[]}

scheduler = CosineAnnealingWarmRestarts(optimizer,T_0 = 15, T_mult = 1,eta_min = 1e-6, verbose=True)
scheduler = CosineAnnealingWarmRestarts(optimizer, T_0=15, T_mult=1, eta_min=1e-6)

for epoch in range(EPOCHS):
print(f"Epoch {epoch+1}/{EPOCHS}:")
Expand All @@ -100,10 +100,7 @@ def fit_model(model, criterion, optimizer):
model = EffNetB2_backbone_model().to(device)

if LOAD_PRETRAINED_MODEL:
if device != 'cpu':
model.load_state_dict(torch.load(MODEL_PATH))
else:
model.load_state_dict(torch.load(MODEL_PATH, map_location = torch.device('cpu')))
model.load_state_dict(torch.load(MODEL_PATH, map_location=device, weights_only=True))

criterion = nn.CrossEntropyLoss()
optimizer = optim.Adam(model.parameters(),lr = LEARNING_RATE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,7 @@ def flatten_list(x):
criterion = nn.CrossEntropyLoss()
model = EffNetB1_backbone_model().to(device)

if device != 'cpu':
model.load_state_dict(torch.load(MODEL_PATH))
else:
model.load_state_dict(torch.load(MODEL_PATH, map_location = torch.device('cpu')))
model.load_state_dict(torch.load(MODEL_PATH, map_location=device, weights_only=True))

_, _, test_loader, class_map = create_data_loaders(TRAIN_DATA_PATH, TEST_DATA_PATH,
val_split = 0.2, batch_size = BATCH_SIZE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def fit_model(model, criterion, optimizer):
loss_dict = {'train_loss':[],'val_loss':[]}
acc_dict = {'train_accuracy':[],'val_accuracy':[]}

scheduler = CosineAnnealingWarmRestarts(optimizer,T_0 = 15, T_mult = 1,eta_min = 1e-6, verbose=True)
scheduler = CosineAnnealingWarmRestarts(optimizer, T_0=15, T_mult=1, eta_min=1e-6)

# scheduler = ReduceLROnPlateau(optimizer, 'min',patience=2,factor=0.3,verbose=True)

Expand Down Expand Up @@ -105,10 +105,7 @@ def fit_model(model, criterion, optimizer):
model = EffNetB1_backbone_model().to(device)

if LOAD_PRETRAINED_MODEL:
if device != 'cpu':
model.load_state_dict(torch.load(MODEL_PATH))
else:
model.load_state_dict(torch.load(MODEL_PATH, map_location = torch.device('cpu')))
model.load_state_dict(torch.load(MODEL_PATH, map_location=device, weights_only=True))

criterion = nn.CrossEntropyLoss()
optimizer = optim.Adam(model.parameters(),lr = LEARNING_RATE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,7 @@ def flatten_list(x):
criterion = nn.CrossEntropyLoss()
model = EffNetB1_backbone_model().to(device)

if device != 'cpu':
model.load_state_dict(torch.load(MODEL_PATH))
else:
model.load_state_dict(torch.load(MODEL_PATH, map_location = torch.device('cpu')))
model.load_state_dict(torch.load(MODEL_PATH, map_location=device, weights_only=True))

_, _, test_loader, class_map = create_data_loaders(TRAIN_DATA_PATH, TEST_DATA_PATH,
val_split = 0.2, batch_size = BATCH_SIZE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def fit_model(model, criterion, optimizer):
loss_dict = {'train_loss':[],'val_loss':[]}
acc_dict = {'train_accuracy':[],'val_accuracy':[]}

scheduler = CosineAnnealingWarmRestarts(optimizer,T_0 = 15, T_mult = 1,eta_min = 1e-6, verbose=True)
scheduler = CosineAnnealingWarmRestarts(optimizer, T_0=15, T_mult=1, eta_min=1e-6)

# scheduler = ReduceLROnPlateau(optimizer, 'min',patience=2,factor=0.3,verbose=True)

Expand Down Expand Up @@ -105,10 +105,7 @@ def fit_model(model, criterion, optimizer):
model = EffNetB1_backbone_model().to(device)

if LOAD_PRETRAINED_MODEL:
if device != 'cpu':
model.load_state_dict(torch.load(MODEL_PATH))
else:
model.load_state_dict(torch.load(MODEL_PATH, map_location = torch.device('cpu')))
model.load_state_dict(torch.load(MODEL_PATH, map_location=device, weights_only=True))

criterion = nn.CrossEntropyLoss()
optimizer = optim.Adam(model.parameters(),lr = LEARNING_RATE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ def flatten_list(x):
set_seed(7)
criterion = nn.HuberLoss()
model = Regressor().to(device)
if device != 'cpu':
model.load_state_dict(torch.load(MODEL_PATH))
else:
model.load_state_dict(torch.load(MODEL_PATH, map_location = torch.device('cpu')))
model.load_state_dict(torch.load(MODEL_PATH, map_location=device, weights_only=True))

train_loader, val_loader, test_loader = create_dataloaders(
TRAIN_DATA_PATH, TEST_DATA_PATH,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import gc
import numpy as np
from tqdm import tqdm
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -99,7 +98,7 @@ def flatten_list(x):
def fit_model(model, checkpoint_path):

optimizer = Ranger(model.parameters(), lr = LEARNING_RATE)
scheduler = optim.lr_scheduler.OneCycleLR(optimizer, LEARNING_RATE, epochs = EPOCHS, steps_per_epoch = len(train_loader), verbose = False)
scheduler = optim.lr_scheduler.OneCycleLR(optimizer, LEARNING_RATE, epochs=EPOCHS, steps_per_epoch=len(train_loader))
criterion = nn.HuberLoss()

loss_dict = {'train_loss':[],'val_loss':[]}
Expand Down Expand Up @@ -140,10 +139,7 @@ def fit_model(model, checkpoint_path):
model = Regressor().to(device)

if LOAD_PRETRAINED_MODEL:
if device != 'cpu':
model.load_state_dict(torch.load(MODEL_PATH))
else:
model.load_state_dict(torch.load(MODEL_PATH, map_location = torch.device('cpu')))
model.load_state_dict(torch.load(MODEL_PATH, map_location=device, weights_only=True))

model, loss_dict = fit_model(model, checkpoint_path = MODEL_PATH)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ def flatten_list(x):
set_seed(7)
criterion = nn.MSELoss()
model = Regressor().to(device)
if device != 'cpu':
model.load_state_dict(torch.load(MODEL_PATH))
else:
model.load_state_dict(torch.load(MODEL_PATH, map_location = torch.device('cpu')))
model.load_state_dict(torch.load(MODEL_PATH, map_location=device, weights_only=True))

train_loader, val_loader, test_loader = create_dataloaders(
TRAIN_DATA_PATH, TEST_DATA_PATH,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import gc
import numpy as np
from tqdm import tqdm
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -99,7 +98,7 @@ def flatten_list(x):
def fit_model(model, checkpoint_path):

optimizer = Ranger(model.parameters(), lr = LEARNING_RATE)
scheduler = optim.lr_scheduler.OneCycleLR(optimizer, LEARNING_RATE, epochs = EPOCHS, steps_per_epoch = len(train_loader), verbose = False)
scheduler = optim.lr_scheduler.OneCycleLR(optimizer, LEARNING_RATE, epochs=EPOCHS, steps_per_epoch=len(train_loader))
criterion = nn.MSELoss()

loss_dict = {'train_loss':[],'val_loss':[]}
Expand Down Expand Up @@ -140,10 +139,7 @@ def fit_model(model, checkpoint_path):
model = Regressor().to(device)

if LOAD_PRETRAINED_MODEL:
if device != 'cpu':
model.load_state_dict(torch.load(MODEL_PATH))
else:
model.load_state_dict(torch.load(MODEL_PATH, map_location = torch.device('cpu')))
model.load_state_dict(torch.load(MODEL_PATH, map_location=device, weights_only=True))

model, loss_dict = fit_model(model, checkpoint_path = MODEL_PATH)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ def flatten_list(x):
set_seed(7)
criterion = nn.MSELoss()
model = Regressor().to(device)
if device != 'cpu':
model.load_state_dict(torch.load(MODEL_PATH))
else:
model.load_state_dict(torch.load(MODEL_PATH, map_location = torch.device('cpu')))
model.load_state_dict(torch.load(MODEL_PATH, map_location=device, weights_only=True))

train_loader, val_loader, test_loader = create_dataloaders(
TRAIN_DATA_PATH, TEST_DATA_PATH,
Expand Down
Loading