[BUGFIX] examples/glvq_spiral.py
works again
This commit is contained in:
parent
68034d56f6
commit
3afced8662
@ -25,7 +25,6 @@ if __name__ == "__main__":
|
|||||||
distribution=(num_classes, prototypes_per_class),
|
distribution=(num_classes, prototypes_per_class),
|
||||||
transfer_function="swish_beta",
|
transfer_function="swish_beta",
|
||||||
transfer_beta=10.0,
|
transfer_beta=10.0,
|
||||||
# lr=0.1,
|
|
||||||
proto_lr=0.1,
|
proto_lr=0.1,
|
||||||
bb_lr=0.1,
|
bb_lr=0.1,
|
||||||
input_dim=2,
|
input_dim=2,
|
||||||
@ -36,7 +35,7 @@ if __name__ == "__main__":
|
|||||||
model = pt.models.GMLVQ(
|
model = pt.models.GMLVQ(
|
||||||
hparams,
|
hparams,
|
||||||
optimizer=torch.optim.Adam,
|
optimizer=torch.optim.Adam,
|
||||||
prototype_initializer=pt.components.SSI(train_ds, noise=1e-2),
|
prototypes_initializer=pt.initializers.SSCI(train_ds, noise=1e-2),
|
||||||
)
|
)
|
||||||
|
|
||||||
# Callbacks
|
# Callbacks
|
||||||
@ -46,12 +45,12 @@ if __name__ == "__main__":
|
|||||||
block=False,
|
block=False,
|
||||||
)
|
)
|
||||||
pruning = pt.models.PruneLoserPrototypes(
|
pruning = pt.models.PruneLoserPrototypes(
|
||||||
threshold=0.02,
|
threshold=0.01,
|
||||||
idle_epochs=10,
|
idle_epochs=10,
|
||||||
prune_quota_per_epoch=5,
|
prune_quota_per_epoch=5,
|
||||||
frequency=2,
|
frequency=5,
|
||||||
replace=True,
|
replace=True,
|
||||||
initializer=pt.components.SSI(train_ds, noise=1e-2),
|
prototypes_initializer=pt.initializers.SSCI(train_ds, noise=1e-1),
|
||||||
verbose=True,
|
verbose=True,
|
||||||
)
|
)
|
||||||
es = pl.callbacks.EarlyStopping(
|
es = pl.callbacks.EarlyStopping(
|
||||||
@ -67,7 +66,7 @@ if __name__ == "__main__":
|
|||||||
args,
|
args,
|
||||||
callbacks=[
|
callbacks=[
|
||||||
vis,
|
vis,
|
||||||
# es,
|
# es, # FIXME
|
||||||
pruning,
|
pruning,
|
||||||
],
|
],
|
||||||
terminate_on_nan=True,
|
terminate_on_nan=True,
|
||||||
|
@ -16,7 +16,7 @@ class PruneLoserPrototypes(pl.Callback):
|
|||||||
prune_quota_per_epoch=-1,
|
prune_quota_per_epoch=-1,
|
||||||
frequency=1,
|
frequency=1,
|
||||||
replace=False,
|
replace=False,
|
||||||
initializer=None,
|
prototypes_initializer=None,
|
||||||
verbose=False):
|
verbose=False):
|
||||||
self.threshold = threshold # minimum win ratio
|
self.threshold = threshold # minimum win ratio
|
||||||
self.idle_epochs = idle_epochs # epochs to wait before pruning
|
self.idle_epochs = idle_epochs # epochs to wait before pruning
|
||||||
@ -24,7 +24,7 @@ class PruneLoserPrototypes(pl.Callback):
|
|||||||
self.frequency = frequency
|
self.frequency = frequency
|
||||||
self.replace = replace
|
self.replace = replace
|
||||||
self.verbose = verbose
|
self.verbose = verbose
|
||||||
self.initializer = initializer
|
self.prototypes_initializer = prototypes_initializer
|
||||||
|
|
||||||
def on_epoch_end(self, trainer, pl_module):
|
def on_epoch_end(self, trainer, pl_module):
|
||||||
if (trainer.current_epoch + 1) < self.idle_epochs:
|
if (trainer.current_epoch + 1) < self.idle_epochs:
|
||||||
@ -55,8 +55,9 @@ class PruneLoserPrototypes(pl.Callback):
|
|||||||
if self.verbose:
|
if self.verbose:
|
||||||
print(f"Re-adding pruned prototypes...")
|
print(f"Re-adding pruned prototypes...")
|
||||||
print(f"{distribution=}")
|
print(f"{distribution=}")
|
||||||
pl_module.add_prototypes(distribution=distribution,
|
pl_module.add_prototypes(
|
||||||
initializer=self.initializer)
|
distribution=distribution,
|
||||||
|
components_initializer=self.prototypes_initializer)
|
||||||
new_num_protos = pl_module.num_prototypes
|
new_num_protos = pl_module.num_prototypes
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
print(f"`num_prototypes` changed from {cur_num_protos} "
|
print(f"`num_prototypes` changed from {cur_num_protos} "
|
||||||
|
Loading…
Reference in New Issue
Block a user