From a86fb56b7a751cefc709062722fefdcbcf4a0ea7 Mon Sep 17 00:00:00 2001 From: Johanmkr Date: Thu, 20 Feb 2025 12:31:28 +0100 Subject: [PATCH 1/7] Updated .gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 04f9680..264da51 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,8 @@ localtest.sh # Johanthings formatting.x +testrun.x +storage/ # Byte-compiled / optimized / DLL files __pycache__/ From ba5f17337edc2f71ae18c15972b025601b567f77 Mon Sep 17 00:00:00 2001 From: Johanmkr Date: Thu, 20 Feb 2025 12:33:28 +0100 Subject: [PATCH 2/7] Fixed minor bug --- CollaborativeCoding/dataloaders/mnist_4_9.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CollaborativeCoding/dataloaders/mnist_4_9.py b/CollaborativeCoding/dataloaders/mnist_4_9.py index 9ec8f50..9f3ee0a 100644 --- a/CollaborativeCoding/dataloaders/mnist_4_9.py +++ b/CollaborativeCoding/dataloaders/mnist_4_9.py @@ -28,7 +28,7 @@ def __init__( transform=None, nr_channels: int = 1, ): - super.__init__() + super().__init__() self.data_path = data_path self.mnist_path = self.data_path / "MNIST" self.samples = sample_ids From 7f9d06b809f9b56cc5b7bf2e6340acda9db9f6db Mon Sep 17 00:00:00 2001 From: Johanmkr Date: Thu, 20 Feb 2025 13:34:35 +0100 Subject: [PATCH 3/7] local johan changes --- CollaborativeCoding/dataloaders/mnist_4_9.py | 4 +++- main.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CollaborativeCoding/dataloaders/mnist_4_9.py b/CollaborativeCoding/dataloaders/mnist_4_9.py index 9f3ee0a..5426bc4 100644 --- a/CollaborativeCoding/dataloaders/mnist_4_9.py +++ b/CollaborativeCoding/dataloaders/mnist_4_9.py @@ -33,6 +33,8 @@ def __init__( self.mnist_path = self.data_path / "MNIST" self.samples = sample_ids self.train = train + self.transform = transform + self.num_classes = 6 self.images_path = self.mnist_path / ( MNIST_SOURCE["train_images"][1] if train else MNIST_SOURCE["test_images"][1] @@ -46,7 +48,7 @@ def __len__(self): def __getitem__(self, idx): with open(self.labels_path, "rb") as labelfile: - label_pos = 8 + self.sample[idx] + label_pos = 8 + self.samples[idx] labelfile.seek(label_pos) label = int.from_bytes(labelfile.read(1), byteorder="big") diff --git a/main.py b/main.py index 0f2a5d7..ca16c0f 100644 --- a/main.py +++ b/main.py @@ -145,7 +145,7 @@ def main(): for x, y in tqdm(trainloader, desc="Training"): x, y = x.to(device), y.to(device) logits = model.forward(x) - + from IPython import embed; embed() loss = criterion(logits, y) loss.backward() From fb0e3f83173de4fb65cedf0daa21ecc2fc7ce092 Mon Sep 17 00:00:00 2001 From: Johanmkr Date: Thu, 20 Feb 2025 13:54:39 +0100 Subject: [PATCH 4/7] fixed bug communicating with MetricWrapper --- main.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index e30b92a..faf5230 100644 --- a/main.py +++ b/main.py @@ -144,7 +144,6 @@ def main(): for x, y in tqdm(trainloader, desc="Training"): x, y = x.to(device), y.to(device) logits = model.forward(x) - from IPython import embed; embed() loss = criterion(logits, y) loss.backward() @@ -172,8 +171,8 @@ def main(): "Train loss": np.mean(trainingloss), "Validation loss": np.mean(valloss), } - | train_metrics.getmetric(str_prefix="Train ") - | val_metrics.getmetric(str_prefix="Validation ") + | train_metrics.getmetrics(str_prefix="Train ") + | val_metrics.getmetrics(str_prefix="Validation ") ) train_metrics.resetmetric() val_metrics.resetmetric() @@ -192,7 +191,7 @@ def main(): wandb.log( {"Epoch": 1, "Test loss": np.mean(testloss)} - | test_metrics.getmetric(str_prefix="Test ") + | test_metrics.getmetrics(str_prefix="Test ") ) test_metrics.resetmetric() From af3d8bc91819573dffbc400e94a84b98b227dac4 Mon Sep 17 00:00:00 2001 From: Johanmkr Date: Thu, 20 Feb 2025 13:56:49 +0100 Subject: [PATCH 5/7] Added epoch tracking in terminal --- main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/main.py b/main.py index faf5230..f974dbd 100644 --- a/main.py +++ b/main.py @@ -139,6 +139,7 @@ def main(): for epoch in range(args.epoch): # Training loop start + print(f"Epoch: {epoch+1}/{args.epoch}") trainingloss = [] model.train() for x, y in tqdm(trainloader, desc="Training"): From 09fa0d010f0984ab18babca68e1cd84e2249500c Mon Sep 17 00:00:00 2001 From: Johanmkr Date: Thu, 20 Feb 2025 14:55:19 +0100 Subject: [PATCH 6/7] updated mnist --- CollaborativeCoding/dataloaders/mnist_4_9.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/CollaborativeCoding/dataloaders/mnist_4_9.py b/CollaborativeCoding/dataloaders/mnist_4_9.py index cc6ff0e..55d2453 100644 --- a/CollaborativeCoding/dataloaders/mnist_4_9.py +++ b/CollaborativeCoding/dataloaders/mnist_4_9.py @@ -43,7 +43,12 @@ def __init__( self.labels_path = self.mnist_path / ( MNIST_SOURCE["train_labels"][1] if train else MNIST_SOURCE["test_labels"][1] ) - + + # Functions to map the labels from (4,9) -> (0,5) for CrossEntropyLoss to work properly. + self.label_shift = lambda x: x-4 + self.label_restore = lambda x: x+4 + + def __len__(self): return len(self.samples) @@ -66,4 +71,4 @@ def __getitem__(self, idx): if self.transform: image = self.transform(image) - return image, label + return image, self.label_shift(label) From cc9dce0a21968aec97ee5e5a3ec613936d70497f Mon Sep 17 00:00:00 2001 From: Johanmkr Date: Thu, 20 Feb 2025 15:22:07 +0100 Subject: [PATCH 7/7] Test now passing logits to metric --- main.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/main.py b/main.py index f974dbd..7225388 100644 --- a/main.py +++ b/main.py @@ -187,8 +187,7 @@ def main(): loss = criterion(logits, y) testloss.append(loss.item()) - preds = th.argmax(logits, dim=1) - test_metrics(y, preds) + test_metrics(y, logits) wandb.log( {"Epoch": 1, "Test loss": np.mean(testloss)}