I am using a sampler to try and counteract the model overfitting to one class in the model. However, I think I might be doing it wrong because the results from using a dataset that had balanced classes were better than using the unbalanced dataset and weighted classes (assuming I did it right and the unbalanced data set had nearly 50x more data in it). Also, I am wondering what are causing the increasing spikes in the training set? something with the way the Adam optimizer optimizes?
Unbalanced Dataset:

layers-5_parms-45_45_90_180_180_4_model-15782835091440×720 80.9 KB

Balanced Dataset:

model-1578181603_layers-5_parms-45_45_90_180_180_41440×720 106 KB

Code:
import time

net = Net().apply(weight_reset).to(device)
optimizer = optim.Adam(net.parameters(), lr = 0.001, weight_decay=1e-5)
loss_function = nn.CrossEntropyLoss(weight=1/torch.Tensor(list(Data_PreProcessing.dataCount.values())))

PATH = "/content/drive/My Drive/ECG_MODELS/"

layers, params = net_info(net)
MODEL_NAME = f"layers-{layers}_parms-{str(params)[1:-1].replace(', ', '_')}_model-{int(time.time())}"  # gives a dynamic model name, to just help with things getting messy over time.

def train(net):
    BATCH_SIZE = 5000
    EPOCHS = 100

    with open(PATH+"data/"+f"{MODEL_NAME}.log", "a") as f:
        for epoch in tqdm(range(EPOCHS)):
            for i in range(0, len(train_X), BATCH_SIZE):
                batch_X = train_X[i:i+BATCH_SIZE].view(-1,1,180)
                batch_y = train_y[i:i+BATCH_SIZE]

                batch_X, batch_y = batch_X.to(device), batch_y.to(device)

                acc, loss = fwd_pass(batch_X, batch_y, train=True)

                if i % 50 == 0:
                    val_acc, val_loss = test(size=100)
                    f.write(f"{round(time.time(),3)},{round(float(acc),2)},{round(float(loss), 4)},{round(float(val_acc),2)},{round(float(val_loss),4)},{epoch}\n")

print(MODEL_NAME)
train(net)
torch.save(net, PATH+"model_params/"+f'{MODEL_NAME}.pt')

model_data = open(PATH+"model_data/"+f"{MODEL_NAME}.txt", "w")
model_data.write(net)
model_data.write("/n")
model_data.write(optimizer)
model_data.write("/n")
model_data.write(loss_function)
model_data.close()