Sort imports in example scripts

This commit is contained in:
Jensun Ravichandran 2021-05-31 00:52:16 +02:00
parent 7b7bc3693d
commit e9d2075fed
11 changed files with 43 additions and 50 deletions

View File

@ -2,10 +2,11 @@
import argparse
import prototorch as pt
import pytorch_lightning as pl
import torch
import prototorch as pt
if __name__ == "__main__":
# Command-line arguments
parser = argparse.ArgumentParser()

View File

@ -2,10 +2,10 @@
import argparse
import prototorch as pt
import pytorch_lightning as pl
import torch
from sklearn.datasets import load_iris
import prototorch as pt
if __name__ == "__main__":
# Command-line arguments
@ -14,14 +14,10 @@ if __name__ == "__main__":
args = parser.parse_args()
# Dataset
x_train, y_train = load_iris(return_X_y=True)
x_train = x_train[:, [0, 2]]
train_ds = pt.datasets.NumpyDataset(x_train, y_train)
train_ds = pt.datasets.Iris(dims=[0, 2])
# Dataloaders
train_loader = torch.utils.data.DataLoader(train_ds,
num_workers=0,
batch_size=150)
train_loader = torch.utils.data.DataLoader(train_ds, batch_size=64)
# Hyperparameters
hparams = dict(
@ -38,7 +34,7 @@ if __name__ == "__main__":
prototype_initializer=pt.components.SMI(train_ds))
# Callbacks
vis = pt.models.VisGLVQ2D(data=(x_train, y_train), block=False)
vis = pt.models.VisGLVQ2D(data=train_ds)
# Setup trainer
trainer = pl.Trainer.from_argparse_args(

View File

@ -2,10 +2,11 @@
import argparse
import prototorch as pt
import pytorch_lightning as pl
import torch
import prototorch as pt
if __name__ == "__main__":
# Command-line arguments
parser = argparse.ArgumentParser()

View File

@ -2,11 +2,12 @@
import argparse
import prototorch as pt
import pytorch_lightning as pl
import torch
from sklearn.datasets import load_iris
import prototorch as pt
if __name__ == "__main__":
# Command-line arguments
parser = argparse.ArgumentParser()
@ -18,9 +19,8 @@ if __name__ == "__main__":
train_ds = pt.datasets.NumpyDataset(x_train, y_train)
# Dataloaders
train_loader = torch.utils.data.DataLoader(train_ds,
num_workers=0,
batch_size=150)
train_loader = torch.utils.data.DataLoader(train_ds, batch_size=150)
# Hyperparameters
num_classes = 3
prototypes_per_class = 1

View File

@ -2,12 +2,13 @@
import argparse
import prototorch as pt
import pytorch_lightning as pl
import torch
from torchvision import transforms
from torchvision.datasets import MNIST
import prototorch as pt
if __name__ == "__main__":
# Command-line arguments
parser = argparse.ArgumentParser()

View File

@ -2,11 +2,12 @@
import argparse
import prototorch as pt
import pytorch_lightning as pl
import torch
from sklearn.datasets import load_iris
import prototorch as pt
if __name__ == "__main__":
# Command-line arguments
parser = argparse.ArgumentParser()
@ -19,9 +20,7 @@ if __name__ == "__main__":
train_ds = pt.datasets.NumpyDataset(x_train, y_train)
# Dataloaders
train_loader = torch.utils.data.DataLoader(train_ds,
num_workers=0,
batch_size=150)
train_loader = torch.utils.data.DataLoader(train_ds, batch_size=150)
# Hyperparameters
hparams = dict(k=20)

View File

@ -2,10 +2,11 @@
import argparse
import prototorch as pt
import pytorch_lightning as pl
import torch
import prototorch as pt
if __name__ == "__main__":
# Command-line arguments
parser = argparse.ArgumentParser()
@ -24,10 +25,11 @@ if __name__ == "__main__":
test_loader = torch.utils.data.DataLoader(test_ds, batch_size=32)
# Hyperparameters
num_classes = 2
prototypes_per_class = 2
hparams = dict(
distribution=(num_classes, prototypes_per_class),
distribution={
"num_classes": 3,
"prototypes_per_class": 4
},
input_dim=100,
latent_dim=2,
proto_lr=0.001,

View File

@ -1,10 +1,12 @@
"""LVQMLN example using all four dimensions of the Iris dataset."""
import argparse
import prototorch as pt
import pytorch_lightning as pl
import torch
import prototorch as pt
class Backbone(torch.nn.Module):
def __init__(self, input_size=4, hidden_size=10, latent_size=2):
@ -35,9 +37,7 @@ if __name__ == "__main__":
pl.utilities.seed.seed_everything(seed=42)
# Dataloaders
train_loader = torch.utils.data.DataLoader(train_ds,
num_workers=0,
batch_size=150)
train_loader = torch.utils.data.DataLoader(train_ds, batch_size=150)
# Hyperparameters
hparams = dict(

View File

@ -2,12 +2,13 @@
import argparse
import prototorch as pt
import pytorch_lightning as pl
import torch
from sklearn.datasets import load_iris
from sklearn.preprocessing import StandardScaler
import prototorch as pt
if __name__ == "__main__":
# Command-line arguments
parser = argparse.ArgumentParser()
@ -24,9 +25,7 @@ if __name__ == "__main__":
train_ds = pt.datasets.NumpyDataset(x_train, y_train)
# Dataloaders
train_loader = torch.utils.data.DataLoader(train_ds,
num_workers=0,
batch_size=150)
train_loader = torch.utils.data.DataLoader(train_ds, batch_size=150)
# Hyperparameters
hparams = dict(num_prototypes=30, lr=0.03)

View File

@ -1,11 +1,11 @@
"""GLVQ example using the Iris dataset."""
"""Probabilistic-LVQ example using the Iris dataset."""
import argparse
import prototorch as pt
import pytorch_lightning as pl
import torch
from sklearn.datasets import load_iris
import prototorch as pt
if __name__ == "__main__":
# Command-line arguments
@ -14,14 +14,10 @@ if __name__ == "__main__":
args = parser.parse_args()
# Dataset
x_train, y_train = load_iris(return_X_y=True)
x_train = x_train[:, [0, 2]]
train_ds = pt.datasets.NumpyDataset(x_train, y_train)
train_ds = pt.datasets.Iris(dims=[0, 2])
# Dataloaders
train_loader = torch.utils.data.DataLoader(train_ds,
num_workers=0,
batch_size=150)
train_loader = torch.utils.data.DataLoader(train_ds, batch_size=64)
# Hyperparameters
num_classes = 3
@ -29,20 +25,19 @@ if __name__ == "__main__":
hparams = dict(
distribution=(num_classes, prototypes_per_class),
lr=0.05,
variance=1,
variance=1.0,
)
# Initialize the model
model = pt.models.probabilistic.LikelihoodRatioLVQ(
#model = pt.models.probabilistic.RSLVQ(
hparams,
optimizer=torch.optim.Adam,
#prototype_initializer=pt.components.SSI(train_ds, noise=2),
prototype_initializer=pt.components.UniformInitializer(2),
# prototype_initializer=pt.components.UniformInitializer(2),
prototype_initializer=pt.components.SMI(train_ds),
)
# Callbacks
vis = pt.models.VisGLVQ2D(data=(x_train, y_train), block=False)
vis = pt.models.VisGLVQ2D(data=train_ds)
# Setup trainer
trainer = pl.Trainer.from_argparse_args(

View File

@ -2,10 +2,11 @@
import argparse
import prototorch as pt
import pytorch_lightning as pl
import torch
import prototorch as pt
class Backbone(torch.nn.Module):
def __init__(self, input_size=4, hidden_size=10, latent_size=2):
@ -36,9 +37,7 @@ if __name__ == "__main__":
pl.utilities.seed.seed_everything(seed=2)
# Dataloaders
train_loader = torch.utils.data.DataLoader(train_ds,
num_workers=0,
batch_size=150)
train_loader = torch.utils.data.DataLoader(train_ds, batch_size=150)
# Hyperparameters
hparams = dict(