2021-10-14 13:49:12 +00:00
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
import prototorch as pt
|
|
|
|
import pytorch_lightning as pl
|
|
|
|
import torch
|
|
|
|
from prototorch.core.initializers import SMCI, RandomNormalCompInitializer
|
2021-10-15 11:01:01 +00:00
|
|
|
from prototorch.models.clcc.clcc_glvq import GLVQ, GLVQhparams
|
|
|
|
from prototorch.models.vis import Visualize2DVoronoiCallback
|
2021-10-14 13:49:12 +00:00
|
|
|
|
2021-10-15 11:01:01 +00:00
|
|
|
# NEW STUFF
|
|
|
|
# ##############################################################################
|
|
|
|
# ##############################################################################
|
2021-10-14 13:49:12 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
# Dataset
|
|
|
|
train_ds = pt.datasets.Iris(dims=[0, 2])
|
|
|
|
# Dataloaders
|
|
|
|
train_loader = torch.utils.data.DataLoader(train_ds, batch_size=64)
|
|
|
|
|
|
|
|
components_initializer = SMCI(train_ds)
|
|
|
|
|
|
|
|
hparams = GLVQhparams(
|
|
|
|
distribution=dict(
|
|
|
|
num_classes=3,
|
|
|
|
per_class=2,
|
|
|
|
),
|
|
|
|
component_initializer=components_initializer,
|
|
|
|
)
|
|
|
|
model = GLVQ(hparams)
|
|
|
|
|
|
|
|
print(model)
|
|
|
|
# Callbacks
|
2021-10-15 11:01:01 +00:00
|
|
|
vis = Visualize2DVoronoiCallback(data=train_ds, resolution=500)
|
|
|
|
|
2021-10-14 13:49:12 +00:00
|
|
|
# Train
|
2021-10-15 11:01:01 +00:00
|
|
|
trainer = pl.Trainer(callbacks=[vis], gpus=1, max_epochs=100)
|
2021-10-14 13:49:12 +00:00
|
|
|
trainer.fit(model, train_loader)
|