{ "cells": [ { "cell_type": "markdown", "metadata": { "tags": [] }, "source": [ "# Siamese\n", "\n", "> We are building a function that predicts how similary two signatures are with a probability score between 0-1." ] }, { "cell_type": "markdown", "metadata": { "tags": [] }, "source": [ "## Imports, Paths" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "#| default_exp siamese" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "#| hide\n", "from nbdev.showdoc import *" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "tags": [] }, "outputs": [], "source": [ "#| export\n", "import pathlib, os, shutil, sys, cv2, torch, random, glob\n", "\n", "import pandas as pd\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import math\n", "import statistics\n", "\n", "from PIL import Image\n", "from tqdm import tqdm\n", "from pathlib import Path\n", "from itertools import zip_longest\n", "from copy import copy\n", "from operator import attrgetter\n", "from functools import partial\n", "from collections.abc import Mapping\n", "\n", "import torch.nn as nn\n", "import torch.nn.functional as F\n", "import torchvision.models as models\n", "import torch.optim as optim\n", "import torchvision.transforms as transforms\n", "import torchvision\n", "from torch.utils.data import DataLoader, Dataset\n", "from torcheval.metrics import MulticlassAccuracy,Mean, BinaryAccuracy\n", "from torch.nn import init\n", "from fastprogress import progress_bar,master_bar\n", "from torch.optim.lr_scheduler import ExponentialLR" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[34m\u001b[1mwandb\u001b[0m: Appending key for api.wandb.ai to your netrc file: /root/.netrc\n" ] } ], "source": [ "!wandb login bc5f620f80eb84aedebb3c164d4ae6dda77a0ef2\n", "import wandb" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "torch.manual_seed(0)\n", "random.seed(0)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "tags": [] }, "outputs": [], "source": [ "basePath = Path(\"/storage/projects/signature/signify\")\n", "dataPath = basePath / \"sigData\"/\"train_aug2\"\n", "dataPath_clean = basePath / \"sigData\"/\"train\"" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "#| export\n", "def compare(pic1, pic2): \n", " return random.random()" ] }, { "cell_type": "markdown", "metadata": { "tags": [] }, "source": [ "## Dataset" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "def get_v_t_dirpaths(lst, n=53, index=False): # if index true we return list of indices instead list of elements\n", " \n", " lst = [el for el in lst if not str(el.name).startswith(\".\")]\n", " idxs = list(range(len(lst)))\n", " train_idx = random.sample(idxs, n)\n", " valid_idx = [idx for idx in idxs if idx not in train_idx]\n", " \n", " if index:\n", " return train_idx, valid_idx\n", " else: # return actual elements\n", " return list(np.array(lst)[train_idx]), list(np.array(lst)[valid_idx])\n", "\n", "def get_valid_clean_dirpaths(valid, path): # get same validation samples as in valid, however, this dir only any images that have background noice etc. used for 2nd valid ds\n", " dir_names = [p.name for p in valid] \n", " return [p for p in path.iterdir() if p.name in dir_names]\n", "\n", "def get_dirnames_each_ds(root_dir, clean_root_dir):\n", "\n", " dirpaths = list(root_dir.iterdir())\n", " train, valid = get_v_t_dirpaths(dirpaths)\n", " valid_clean = get_valid_clean_dirpaths(valid, clean_root_dir)\n", "\n", " classes = sorted(os.listdir(root_dir))\n", " return {\"train\": train, \"valid\": valid, \"valid_clean\": valid_clean}\n", "\n", "class SiameseDataset(Dataset):\n", " def __init__(self, dirpaths, n_samples, transform_both=None, transform_seperate=None):\n", " self.dirpaths = dirpaths\n", " self.transform_both = transform_both\n", " self.transform_seperate = transform_seperate\n", " self.samples = self._make_samples(n_samples)\n", " \n", " def _make_samples(self, n_samples):\n", " samples = []\n", " pairs_per_sample = n_samples // (len(self.dirpaths) * 3)\n", " false_pairs_per_class = pairs_per_sample // len(self.dirpaths)\n", " false_pairs_per_class = max(1, false_pairs_per_class * 2)\n", " print(false_pairs_per_class * 2)\n", " \n", " for idx, class_path in enumerate(self.dirpaths[:-1]):\n", " \n", " class_samples = glob.glob(os.path.join(class_path, '*.png')) + glob.glob(os.path.join(class_path, '*.PNG'))\n", " for _ in range(pairs_per_sample):\n", " img1_path, img2_path = random.sample(class_samples, 2)\n", " label = int(os.path.dirname(img1_path) == os.path.dirname(img2_path))\n", " samples.append((img1_path, img2_path, label))\n", " \n", " \n", " for fdirpath in (self.dirpaths[:idx] + self.dirpaths[idx+1:]):\n", " pngs = glob.glob(str(fdirpath / '*.png')) + glob.glob(str(fdirpath / '*.PNG'))\n", " \n", " for _ in range(false_pairs_per_class):\n", " img1_path = random.choice(class_samples)\n", " img2_path = random.choice(pngs)\n", " label = 0\n", " samples.append((img1_path, img2_path, label))\n", "\n", " return samples\n", " \n", " def __len__(self):\n", " return len(self.samples)\n", " \n", " def __repr__(self):\n", " len_positives = 0\n", " for sample in self.samples:\n", " if sample[2]:\n", " len_positives += 1 \n", " return f'number of positive sample {str(len_positives)} ; number of negative sample {str(len(self) - len_positives)}'\n", " \n", " def __getitem__(self, idx):\n", " img1_path, img2_path, label = self.samples[idx]\n", " img1 = Image.open(img1_path).convert('RGB')\n", " img2 = Image.open(img2_path).convert('RGB')\n", " label = torch.tensor(label, dtype=torch.float32)\n", "\n", "\n", " if self.transform_both:\n", " \n", " seed = torch.seed()\n", " img1 = self.transform_both(img1)\n", " torch.manual_seed(seed)\n", " img2 = self.transform_both(img2)\n", " \n", " if self.transform_seperate:\n", " img1 = self.transform_seperate(img1)\n", " img2 = self.transform_seperate(img2)\n", "\n", " return img1, img2, label" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "tags": [] }, "outputs": [], "source": [ "dirnames = {'train': [Path('/storage/projects/signature/signify/sigData/train_aug2/069'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/006'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/067'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/063'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/028'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/009'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/058'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/054'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/024'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/038'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/048'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/064'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/060'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/051'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/047'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/032'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/057'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/002'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/015'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/065'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/040'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/014'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/004'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/041'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/035'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/050'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/022'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/059'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/034'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/056'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/019'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/053'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/036'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/037'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/030'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/066'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/026'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/017'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/013'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/046'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/033'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/044'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/049'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/031'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/061'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/003'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/027'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/023'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/029'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/062'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/016'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/012'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/020')],\n", " 'valid': [Path('/storage/projects/signature/signify/sigData/train_aug2/042'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/068'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/001'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/055'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/045'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/025'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/052'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/021'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/018'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/043'),\n", " Path('/storage/projects/signature/signify/sigData/train_aug2/039')],\n", " 'valid_clean': [Path('/storage/projects/signature/signify/sigData/train/042'),\n", " Path('/storage/projects/signature/signify/sigData/train/068'),\n", " Path('/storage/projects/signature/signify/sigData/train/001'),\n", " Path('/storage/projects/signature/signify/sigData/train/055'),\n", " Path('/storage/projects/signature/signify/sigData/train/045'),\n", " Path('/storage/projects/signature/signify/sigData/train/025'),\n", " Path('/storage/projects/signature/signify/sigData/train/052'),\n", " Path('/storage/projects/signature/signify/sigData/train/021'),\n", " Path('/storage/projects/signature/signify/sigData/train/018'),\n", " Path('/storage/projects/signature/signify/sigData/train/043'),\n", " Path('/storage/projects/signature/signify/sigData/train/039')]}" ] }, { "cell_type": "markdown", "metadata": { "tags": [] }, "source": [ "## Model" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "class SiameseDropout(nn.Module):\n", " \"\"\" Siamese dropout ... adaptation from LockedDropout\n", "\n", " **Thank you** to Sales Force for their initial implementation of :class:`WeightDrop`. Here is\n", " their `License\n", " `__.\n", "\n", " Args:\n", " p (float): Probability of an element in the dropout mask to be zeroed.\n", " \"\"\"\n", "\n", " def __init__(self, p=0.5):\n", " self.p = p\n", " super().__init__()\n", "\n", " def forward(self, x1,x2, train):\n", " \"\"\"\n", " Args:\n", " x (:class:`torch.FloatTensor` [batch size, rnn hidden size]): Input to\n", " apply dropout too.\n", " \"\"\"\n", " if not train or not self.p:\n", " return x1, x2\n", "\n", " stacked = torch.stack([x1, x2])\n", " x = stacked.clone()\n", " mask = x.new_empty(1, x.size(1), x.size(2), requires_grad=False).bernoulli_(1 - self.p)\n", " mask = mask.div_(1 - self.p)\n", " mask = mask.expand_as(x)\n", " x1,x2 =torch.chunk(x*mask,2)\n", " return x1,x2\n", "\n", "\n", " def __repr__(self):\n", " return self.__class__.__name__ + '(' \\\n", " + 'p=' + str(self.p) + ')'\n" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "tags": [] }, "outputs": [], "source": [ "class SiameseNetwork(nn.Module):\n", " def __init__(self, model, embedding_size=4000, bce=True, dropout_p=0, add_layer=False):\n", " super(SiameseNetwork, self).__init__()\n", "\n", " self.dropout = SiameseDropout(dropout_p)\n", " self.bce = bce\n", " self.backbone = model\n", " self.rgb_grayscale = nn.Conv2d(1,3,kernel_size=3,stride=1,padding=1)\n", " self.a = nn.Sigmoid()\n", " self.fc1 = nn.Linear(in_features=1000, out_features=embedding_size) \n", "\n", " if add_layer:\n", " self.fc21 = nn.Linear(in_features=embedding_size, out_features=50) \n", " self.fc2 = nn.Linear(in_features=50,out_features=1) \n", " else:\n", " self.fc2 = nn.Linear(in_features=embedding_size,out_features=1) \n", " def forward_once(self, x):\n", " \n", " x = self.rgb_grayscale(x) # keeps the img size the same. just from 1 to 3 channels\n", " resnet_output = self.backbone(x)\n", " return resnet_output\n", " \n", " def forward(self, x1,x2):\n", " # forward pass for two images through ResNet34\n", " x1 = self.forward_once(x1)\n", " x2 = self.forward_once(x2)\n", " \n", " out1, out2 = self.dropout(x1,x2, self.train)\n", " out1, out2 = self.fc1(out1), self.fc1(out2)\n", " \n", " if self.bce:\n", " dis = torch.abs(out1 - out2) # crucial !! \n", " \n", " if hasattr(self, 'fc21'):\n", " return self.a(self.fc2(self.fc21(dis))).squeeze()\n", " else:\n", " return self.a(self.fc2(dis)).squeeze()\n", " else:\n", " return out1, out2\n", " \n", " \n", "class ContrastiveLoss(torch.nn.Module):\n", " \"\"\"\n", " Contrastive loss function.\n", " Based on: http://yann.lecun.com/exdb/publis/pdf/hadsell-chopra-lecun-06.pdf\n", " \"\"\"\n", "\n", " def __init__(self, margin=2.0):\n", " super(ContrastiveLoss, self).__init__()\n", " self.margin = margin\n", "\n", " def forward(self, *args):\n", " output1, output2, label = args\n", " euclidean_distance = F.pairwise_distance(output1, output2, keepdim = False)\n", " loss_contrastive = torch.mean((1-label) * torch.pow(euclidean_distance, 2) +\n", " (label) * torch.pow(torch.clamp(self.margin - euclidean_distance, min=0.0), 2))\n", "\n", "\n", " return loss_contrastive" ] }, { "cell_type": "markdown", "metadata": { "tags": [] }, "source": [ "## Callbacks" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [], "source": [ "#|export\n", "class with_cbs:\n", " def __init__(self, nm): self.nm = nm\n", " def __call__(self, f):\n", " def _f(o, *args, **kwargs):\n", " try:\n", " o.callback(f'before_{self.nm}')\n", " f(o, *args, **kwargs)\n", " o.callback(f'after_{self.nm}')\n", " except globals()[f'Cancel{self.nm.title()}Exception']: pass\n", " finally: o.callback(f'cleanup_{self.nm}')\n", " return _f\n", "\n", " \n", "def run_cbs(cbs, method_nm, learn=None):\n", " for cb in sorted(cbs, key=attrgetter('order')):\n", " method = getattr(cb, method_nm, None)\n", " if method is not None: method(learn)" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [], "source": [ "#|export\n", "def to_cpu(x):\n", " if isinstance(x, Mapping): return {k:to_cpu(v) for k,v in x.items()}\n", " if isinstance(x, list): return [to_cpu(o) for o in x]\n", " if isinstance(x, tuple): return tuple(to_cpu(list(x)))\n", " res = x.detach().cpu()\n", " return res.float() if res.dtype==torch.float16 else res\n", "\n", "def_device = 'mps' if torch.backends.mps.is_available() else 'cuda' if torch.cuda.is_available() else 'cpu'\n", "\n", "def to_device(x, device=def_device):\n", " if isinstance(x, list): return [to_device(o) for o in x]\n", " if isinstance(x, tuple): return tuple(to_device(list(x)))\n", " if isinstance(x, torch.Tensor): return x.to(device)" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [], "source": [ "#|export\n", "class CancelFitException(Exception): pass\n", "class CancelBatchException(Exception): pass\n", "class CancelEpochException(Exception): pass" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [], "source": [ "#|export\n", "class Callback(): order = 0\n", "\n", "class MetricsCB(Callback):\n", " def __init__(self, wandb, *ms, **metrics):\n", " for o in ms: metrics[type(o).__name__] = o\n", " self.metrics = metrics\n", " self.all_metrics = copy(metrics)\n", " self.all_metrics['loss'] = self.loss = Mean()\n", " self.wandb = wandb\n", "\n", " def _log(self, d): print(d)\n", " def before_fit(self, learn): learn.metrics = self\n", " def before_epoch(self, learn): [o.reset() for o in self.all_metrics.values()]\n", "\n", " def after_epoch(self, learn):\n", " log = {k:f'{v.compute():.3f}' for k,v in self.all_metrics.items()}\n", " log['epoch'] = learn.epoch\n", " log['train'] = 'train' if learn.model.training else 'eval'\n", " self._log(log)\n", " \n", " log_wandb = {f'{k}_{log[\"train\"]}':round(float(v.compute()), 3) for k,v in self.all_metrics.items()}\n", " self.wandb.log(log_wandb)\n", " \n", "\n", " def after_batch(self, learn):\n", " x,x2, y = to_cpu(learn.batch)\n", " for m in self.metrics.values():\n", " m.update(to_cpu(learn.preds), y)\n", " \n", " loss = to_cpu(learn.loss)\n", " self.loss.update(loss, weight=len(x))\n", " self.wandb.log({\"batch loss\": loss.item()})\n", "\n", "class TrainCB(Callback):\n", " def __init__(self, n_inp=1): self.n_inp = n_inp\n", " def predict(self, learn): \n", " learn.x, learn.y = learn.batch[:self.n_inp], learn.batch[self.n_inp]\n", " learn.preds = learn.model(*learn.x)\n", " def get_loss(self, learn): \n", " learn.loss = learn.loss_func(learn.preds, *learn.batch[self.n_inp:])\n", " def backward(self, learn): learn.loss.backward()\n", " def step(self, learn): learn.opt.step()\n", " def zero_grad(self, learn): learn.opt.zero_grad()\n", " \n", "class TrainContrastiveCB(Callback):\n", " def __init__(self, n_inp=1): \n", " self.n_inp = n_inp\n", " self.loss_func\n", " def predict(self, learn): \n", " learn.preds = learn.model(*learn.batch[:self.n_inp])\n", " def get_loss(self, learn): \n", " pred1, pred2 = learn.preds\n", " label = learn.batch[self.n_inp]\n", " learn.loss = learn.loss_func(pred1, pred2, label)\n", " def backward(self, learn): learn.loss.backward()\n", " def step(self, learn): learn.opt.step()\n", " def zero_grad(self, learn): learn.opt.zero_grad()\n", "\n", "class TrainBceCB(Callback):\n", " def __init__(self, n_inp=1): \n", " self.n_inp = n_inp\n", " self.loss_func = torch.nn.BCELoss()\n", " def predict(self, learn): \n", " learn.x, learn.y = learn.batch[:self.n_inp], learn.batch[self.n_inp]\n", " learn.preds = learn.model(*learn.x)\n", " def get_loss(self, learn): \n", " label = learn.batch[self.n_inp]\n", " learn.loss = self.loss_func(learn.preds, label)\n", " def backward(self, learn): learn.loss.backward()\n", " def step(self, learn): learn.opt.step()\n", " def zero_grad(self, learn): learn.opt.zero_grad()\n", " \n", "class DeviceCB(Callback):\n", " order = 1\n", " def __init__(self, device): fc.store_attr()\n", " def before_fit(self, learn):\n", " if hasattr(learn.model, 'to'): learn.model.to(self.device)\n", " def before_batch(self, learn): \n", " learn.batch = to_device(learn.batch, device=self.device)\n", " \n", "class ProgressCB(Callback):\n", " order = MetricsCB.order+1\n", " def __init__(self, plot=False): self.plot = plot\n", " def before_fit(self, learn):\n", " learn.epochs = self.mbar = master_bar(learn.epochs)\n", " self.first = True\n", " if hasattr(learn, 'metrics'): learn.metrics._log = self._log\n", " self.losses = []\n", " self.val_losses = []\n", "\n", "\n", " def _log(self, d):\n", " if self.first:\n", " self.mbar.write(list(d), table=True)\n", " self.first = False\n", " self.mbar.write(list(d.values()), table=True)\n", "\n", " def before_epoch(self, learn): learn.dl = progress_bar(learn.dl, leave=False, parent=self.mbar)\n", " def after_batch(self, learn):\n", " learn.dl.comment = f'{learn.loss:.3f}'\n", " if self.plot and hasattr(learn, 'metrics') and learn.training:\n", " self.losses.append(learn.loss.item())\n", " if self.val_losses: self.mbar.update_graph([[fc.L.range(self.losses), self.losses],[fc.L.range(learn.epoch).map(lambda x: (x+1)*len(learn.dlt)), self.val_losses]])\n", " \n", " def after_epoch(self, learn): \n", " if not learn.training:\n", " if self.plot and hasattr(learn, 'metrics'): \n", " self.val_losses.append(learn.metrics.all_metrics['loss'].compute())\n", " self.mbar.update_graph([[fc.L.range(self.losses), self.losses],[fc.L.range(learn.epoch+1).map(lambda x: (x+1)*len(learn.dlt)), self.val_losses]])\n", "\n", " \n", "class SaveModelCallback(Callback):\n", " \"A `TrackerCallback` that saves the model's best during training and loads it at the end.\"\n", " order = ProgressCB.order + 1\n", " def __init__(self):\n", " \n", " try:\n", " old_loss = torch.load(\"model.pth\")[\"loss\"]\n", " except:\n", " old_loss = 1000\n", " \n", " self.valid_losses = [old_loss]\n", " self.valid_losses_batch = []\n", " \n", " def after_batch(self, learn):\n", " if not learn.training:\n", " self.valid_losses_batch.append(learn.loss.item())\n", "\n", " def after_epoch(self,learn):\n", " \n", " if not learn.training:\n", " \n", " current_valid_loss = statistics.mean(self.valid_losses_batch)\n", " prev_best = min(self.valid_losses)\n", " if current_valid_loss < prev_best:\n", " print(f\"saving model in epoch {learn.epoch} with loss {current_valid_loss} (prev: {prev_best})\")\n", " torch.save({\n", " 'epoch': learn.epoch,\n", " 'model_state_dict': learn.model.state_dict(),\n", " 'optimizer_state_dict': learn.opt.state_dict(),\n", " 'loss':current_valid_loss,\n", " }, \"model.pth\")\n", " self.valid_losses.append(current_valid_loss)\n", " self.valid_losses_batch = []\n", "\n", " \n", "class LRFinderCB(Callback):\n", " order = 1\n", " def __init__(self, gamma=1.3, max_mult=3): fc.store_attr()\n", " \n", " def before_fit(self, learn):\n", " self.sched = ExponentialLR(learn.opt, self.gamma)\n", " self.lrs,self.losses = [],[]\n", " self.min = math.inf\n", "\n", " def after_batch(self, learn):\n", " if not learn.training: raise CancelEpochException()\n", " self.lrs.append(learn.opt.param_groups[0]['lr'])\n", " loss = to_cpu(learn.loss)\n", " self.losses.append(loss)\n", " if loss < self.min: self.min = loss\n", " if math.isnan(loss) or (loss > self.min*self.max_mult):\n", " raise CancelFitException()\n", " self.sched.step()\n", "\n", " def cleanup_fit(self, learn):\n", " plt.plot(self.lrs, self.losses)\n", " plt.xscale('log')\n", " \n", "#| export\n", "class HooksCallback(Callback):\n", " def __init__(self, hookfunc, mod_filter=fc.noop, on_train=True, on_valid=False, mods=None):\n", " fc.store_attr()\n", " super().__init__()\n", " \n", " def before_fit(self, learn):\n", " if self.mods: mods=self.mods\n", " else: mods = fc.filter_ex(learn.model.modules(), self.mod_filter)\n", " self.hooks = Hooks(mods, partial(self._hookfunc, learn))\n", "\n", " def _hookfunc(self, learn, *args, **kwargs):\n", " if (self.on_train and learn.training) or (self.on_valid and not learn.training): self.hookfunc(*args, **kwargs)\n", "\n", " def after_fit(self, learn): self.hooks.remove()\n", " def __iter__(self): return iter(self.hooks)\n", " def __len__(self): return len(self.hooks)\n", "\n", "#| export\n", "def append_stats(hook, mod, inp, outp):\n", " if not hasattr(hook,'stats'): hook.stats = ([],[],[])\n", " acts = to_cpu(outp)\n", " hook.stats[0].append(acts.mean())\n", " hook.stats[1].append(acts.std())\n", " hook.stats[2].append(acts.abs().histc(40,0,10))\n", " \n", "#|export\n", "class ActivationStats(HooksCallback):\n", " def __init__(self, mod_filter=fc.noop): super().__init__(append_stats, mod_filter)\n", "\n", " def color_dim(self, figsize=(11,5)):\n", " fig,axes = get_grid(len(self), figsize=figsize)\n", " for ax,h in zip(axes.flat, self):\n", " show_image(get_hist(h), ax, origin='lower')\n", "\n", " def dead_chart(self, figsize=(11,5)):\n", " fig,axes = get_grid(len(self), figsize=figsize)\n", " for ax,h in zip(axes.flatten(), self):\n", " ax.plot(get_min(h))\n", " ax.set_ylim(0,1)\n", "\n", " def plot_stats(self, figsize=(10,4)):\n", " fig,axs = plt.subplots(1,2, figsize=figsize)\n", " for h in self:\n", " for i in 0,1: axs[i].plot(h.stats[i])\n", " axs[0].set_title('Means')\n", " axs[1].set_title('Stdevs')\n", " plt.legend(fc.L.range(self))\n", "\n", " \n", "\n", "class LoadModelCallback(Callback):\n", " order = 0\n", " def __init__(self, path):\n", " self.path = path\n", " \n", " def before_fit(self, learn):\n", " learn.model.load_state_dict(torch.load(self.path)[\"model_state_dict\"])\n", "\n", "class TwoDLVCallback(Callback):\n", " order = 0\n", " def __init__(self, dlv):\n", " self.dlv = dlv\n", " \n", " def after_epoch(self, learn):\n", " print(\"2nd valid\")\n", " storedlearner = deepcopy(learn) #.copy()\n", " storedlearner.dlv = self.dlv\n", " torch.no_grad()(storedlearner._one_epoch)()\n", "\n", " \n", "#| export\n", "class BatchTransformCB(Callback):\n", " def __init__(self, tfm, on_train=True, on_val=True): fc.store_attr()\n", "\n", " def before_batch(self, learn):\n", " if (self.on_train and learn.training) or (self.on_val and not learn.training):\n", " learn.batch = self.tfm(learn.batch)\n", " " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Schedulers" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [], "source": [ "#|export\n", "class BaseSchedCB(Callback):\n", " def __init__(self, sched): self.sched = sched\n", " def before_fit(self, learn): self.schedo = self.sched(learn.opt)\n", " def _step(self, learn):\n", " if learn.training: self.schedo.step()\n", "#|export\n", "class BatchSchedCB(BaseSchedCB):\n", " def after_batch(self, learn): self._step(learn)" ] }, { "cell_type": "markdown", "metadata": { "jp-MarkdownHeadingCollapsed": true, "tags": [] }, "source": [ "## Data Augmentation" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [], "source": [ "\n", "#|export\n", "def _rand_erase1(x, pct, xm, xs, mn, mx):\n", " szx = int(pct*x.shape[-2])\n", " szy = int(pct*x.shape[-1])\n", " stx = int(random.random()*(1-pct)*x.shape[-2])\n", " sty = int(random.random()*(1-pct)*x.shape[-1])\n", " init.normal_(x[:,:,stx:stx+szx,sty:sty+szy], mean=xm, std=xs)\n", " x.clamp_(mn, mx)\n", "\n", "#|export\n", "def rand_erase(x, pct=0.2, max_num = 4):\n", " xm,xs,mn,mx = x.mean(),x.std(),x.min(),x.max()\n", " num = random.randint(0, max_num)\n", " for i in range(num): _rand_erase1(x, pct, xm, xs, mn, mx)\n", " return x\n", " \n", "class RandErase(nn.Module):\n", " def __init__(self, pct=0.2, max_num=4):\n", " super().__init__()\n", " self.pct,self.max_num = pct,max_num\n", " def forward(self, x): return rand_erase(x, self.pct, self.max_num)\n", "class SquareReflectPad:\n", " def __call__(self, image):\n", " image = image.squeeze()\n", " s = image.size()\n", " max_wh = np.min([s[-1], s[-2] * 2.9])\n", " hp = np.max(int((max_wh - s[-1]) / 2), 0)\n", " vp = np.max(int((max_wh - s[-2]) / 2), 0)\n", " padding = (hp, vp, hp, vp)\n", " new_img = torchvision.transforms.functional.pad(image, padding, padding_mode='reflect')\n", " new_img = new_img.unsqueeze(1).expand(new_img.shape[0],3, new_img.shape[1]).permute(1,0,2)\n", " return new_img\n" ] }, { "cell_type": "markdown", "metadata": { "tags": [] }, "source": [ "## Learner" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [], "source": [ "#|export \n", "def _flops(x, h, w):\n", " if x.dim()<3: return x.numel()\n", " if x.dim()==4: return x.numel()*h*w\n", "\n", "class Learner():\n", " def __init__(self, model, dlt, dlv, lr=0.1, cbs=None, opt_func=optim.SGD):\n", " cbs = fc.L(cbs)\n", " fc.store_attr()\n", "\n", " @with_cbs('batch')\n", " def _one_batch(self):\n", " self.predict()\n", " self.callback('after_predict')\n", " self.get_loss()\n", " self.callback('after_loss')\n", " if self.training:\n", " self.backward()\n", " self.callback('after_backward')\n", " self.step()\n", " self.callback('after_step')\n", " self.zero_grad()\n", "\n", " @with_cbs('epoch')\n", " def _one_epoch(self):\n", " for self.iter ,self.batch in enumerate(self.dl): \n", " self._one_batch()\n", " if self.iter > 100:\n", " break\n", "\n", " def one_epoch(self, training):\n", " self.model.train(training)\n", " self.dl = self.dlt if training else self.dlv\n", " self._one_epoch()\n", "\n", " @with_cbs('fit')\n", " def _fit(self, train, valid):\n", " for self.epoch in self.epochs:\n", " if train: self.one_epoch(True)\n", " if valid: torch.no_grad()(self.one_epoch)(False)\n", "\n", " def fit(self, n_epochs=1, train=True, valid=True, cbs=None, lr=None):\n", " cbs = fc.L(cbs)\n", " # `add_cb` and `rm_cb` were added in lesson 18\n", " for cb in cbs: self.cbs.append(cb)\n", " try:\n", " self.n_epochs = n_epochs\n", " self.epochs = range(n_epochs)\n", " if lr is None: lr = self.lr\n", " if self.opt_func: self.opt = self.opt_func(self.model.parameters(), lr)\n", " self._fit(train, True)\n", " finally:\n", " for cb in cbs: self.cbs.remove(cb)\n", "\n", " def __getattr__(self, name):\n", " if name in ('predict','get_loss','backward','step','zero_grad'): return partial(self.callback, name)\n", " raise AttributeError(name)\n", "\n", " def callback(self, method_nm): run_cbs(self.cbs, method_nm, self)\n", " \n", " @property\n", " def training(self): return self.model.training\n", " \n", " def lr_find(self, gamma=1.3, max_mult=3, start_lr=1e-5, max_epochs=10):\n", " self.fit(max_epochs, lr=start_lr, cbs=LRFinderCB(gamma=gamma, max_mult=max_mult))\n", "\n", " def summary(self):\n", " res = '|Module|Input|Output|Num params|MFLOPS|\\n|--|--|--|--|--|\\n'\n", " totp,totf = 0,0\n", " def _f(hook, mod, inp, outp):\n", " nonlocal res,totp,totf\n", " nparms = sum(o.numel() for o in mod.parameters())\n", " totp += nparms\n", " *_,h,w = outp.shape\n", " flops = sum(_flops(o, h, w) for o in mod.parameters())/1e6\n", " totf += flops\n", " res += f'|{type(mod).__name__}|{tuple(inp[0].shape)}|{tuple(outp.shape)}|{nparms}|{flops:.1f}|\\n'\n", " with Hooks(self.model, _f) as hooks: self.fit(1, lr=1, cbs=SingleBatchCB())\n", " print(f\"Tot params: {totp}; MFLOPS: {totf:.1f}\")\n", " if fc.IN_NOTEBOOK:\n", " from IPython.display import Markdown\n", " return Markdown(res)\n", " else: print(res)\n", "\n" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [], "source": [ "def train(config=None):\n", " # Initialize a new wandb run\n", " with wandb.init(config=config):\n", " # If called by wandb.agent, as below,\n", " # this config will be set by Sweep Controller\n", " \n", "\n", " config = wandb.config\n", " wandb.init(project=\"signify\", config=config)\n", "\n", " if config[\"reflectpad_tfm\"]:\n", " nouts = 1\n", " else:\n", " nouts = 3\n", " \n", " tfm_train = []\n", " tfm_train.append(transforms.ToTensor())\n", " tfm_train.append(transforms.Grayscale(num_output_channels=1))\n", " tfm_train.append(transforms.RandomErasing(scale=(0.02,config[\"erase_max\"]))) if config[\"randomerase_tfm\"] else None\n", " tfm_train.append(transforms.RandomAffine(config[\"aff1\"], \n", " (config[\"aff2\"], config[\"aff2\"]), \n", " (1-config[\"aff3\"], 1+config[\"aff3\"]), \n", " [-config[\"aff4\"], config[\"aff4\"],-config[\"aff4\"], config[\"aff4\"]], fill=1.))\n", " tfm_train.append(transforms.Resize((config[\"img_size\"], config[\"img_size\"])))\n", " tfm_train.append(transforms.RandomApply(torch.nn.ModuleList([transforms.ColorJitter(brightness=(0.7,1.3),\n", " contrast=(0.7,1.3),\n", " saturation=(0.7,1.3), \n", " hue=(-0.1, 0.1))]), p=0.7)) if config[\"jitter_tfm\"] else None\n", " tfm_train.append(transforms.RandomApply(torch.nn.ModuleList([transforms.GaussianBlur(3)]), p=0.5)) if config[\"blur_tfm\"] else None\n", " tfm_train.append(transforms.RandomApply(torch.nn.ModuleList([transforms.AugMix(severity=1)]), p=0.3)) if config[\"augmix_tfm\"] else None\n", " tfm_train.append(transforms.Normalize((0.8981), (0.1322))) \n", "\n", " tfm_valid = []\n", " tfm_valid.append(transforms.ToTensor())\n", " tfm_valid.append(transforms.Grayscale(num_output_channels=1))\n", " tfm_valid.append(SquareReflectPad()) if config[\"reflectpad_tfm\"] else None\n", " tfm_valid.append(transforms.Resize((config[\"img_size\"],config[\"img_size\"])))\n", " tfm_valid.append(transforms.Normalize((0.8981), (0.1322)))\n", "\n", "\n", " transform_train = transforms.Compose(tfm_train)\n", " transform_valid = transforms.Compose(tfm_valid)\n", " \n", " dst = SiameseDataset(dirnames[\"train\"], n_samples=7000, transform=transform_train)\n", " dsv = SiameseDataset(dirnames[\"valid\"], n_samples=640, transform=transform_valid)\n", "\n", " dlt = DataLoader(dst, config[\"bs\"], shuffle=True)\n", " dlv = DataLoader(dsv, config[\"bs\"], shuffle=False)\n", "\n", " # Set up the model\n", " if config[\"backbone\"] == \"resnet\":\n", " backbone = models.resnet34(pretrained=True)\n", " elif config[\"backbone\"] == \"efficientnet\":\n", " backbone = models.efficientnet_v2_s(pretrained=True)\n", " else:\n", " print(\"Unknown architecture\")\n", " backbone = models.efficientnet_v2_s(pretrained=True)\n", "\n", " model = SiameseNetwork(backbone, embedding_size=config[\"embedding_size\"])\n", " #, dropout_p=config[\"dropout_p\"]\n", " metrics = MetricsCB(wandb=wandb, accuracy=BinaryAccuracy()) # ProgressCB(plot=False), SaveModelCallback(), metrics,\n", " cbs = [TrainBceCB(n_inp=2), DeviceCB(def_device), ProgressCB(plot=False), SaveModelCallback(), metrics] #astats # LoadModelCallback(\"model_saved.pth\")\n", " \n", " optimizer = partial(optim.Adam, weight_decay=config[\"wd\"])\n", " learner = Learner(model, dlt, dlv, config[\"lr\"], cbs, opt_func=optimizer)\n", " learner.fit(config[\"epochs\"])\n", " \n", " #import pdb; pdb.set_trace()\n", " wandb.finish()" ] }, { "cell_type": "markdown", "metadata": { "tags": [] }, "source": [ "## Training" ] }, { "cell_type": "markdown", "metadata": { "tags": [] }, "source": [ "### Pretrained resnet34" ] }, { "cell_type": "code", "execution_count": 26, "metadata": { "tags": [] }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "\u001b[34m\u001b[1mwandb\u001b[0m: Currently logged in as: \u001b[33mcrashedice\u001b[0m. Use \u001b[1m`wandb login --relogin`\u001b[0m to force relogin\n" ] }, { "data": { "text/html": [ "Tracking run with wandb version 0.15.3" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "Run data is saved locally in /storage/projects/signature/signify/nbs/wandb/run-20230530_093336-mm42ixkb" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "Syncing run dandy-sound-212 to Weights & Biases (docs)
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ " View project at https://wandb.ai/crashedice/signify" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ " View run at https://wandb.ai/crashedice/signify/runs/mm42ixkb" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "20\n", "4\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "/usr/local/lib/python3.9/dist-packages/torchvision/models/_utils.py:208: UserWarning: The parameter 'pretrained' is deprecated since 0.13 and will be removed in 0.15, please use 'weights' instead.\n", " warnings.warn(\n", "/usr/local/lib/python3.9/dist-packages/torchvision/models/_utils.py:223: UserWarning: Arguments other than a weight enum or `None` for 'weights' are deprecated since 0.13 and will be removed in 0.15. The current behavior is equivalent to passing `weights=EfficientNet_V2_S_Weights.IMAGENET1K_V1`. You can also use `weights=EfficientNet_V2_S_Weights.DEFAULT` to get the most up-to-date weights.\n", " warnings.warn(msg)\n" ] } ], "source": [ "transform_train = transforms.Compose([\n", " transforms.ToTensor(),\n", " transforms.Grayscale(num_output_channels=1),\n", " transforms.Resize((124, 124)),\n", " transforms.RandomErasing(scale=(0.02,0.3)),\n", " transforms.RandomAffine(20, (0.2, 0.2), (0.7, 1.1), [-20,20,-20,20], fill=1.),\n", "])\n", "\n", "transform_train_indiv = transforms.Compose([\n", " transforms.RandomApply(torch.nn.ModuleList([transforms.ColorJitter(brightness=(0.7,1.3),contrast=(0.7,1.3),saturation=(0.7,1.3), hue=(-0.1, 0.1))]), p=0.5),\n", " transforms.RandomApply(torch.nn.ModuleList([transforms.GaussianBlur(3)]), p=.2)\n", "])\n", "\n", "transform_valid = transforms.Compose([\n", " transforms.ToTensor(),\n", " transforms.Grayscale(num_output_channels=1),\n", " transforms.Resize((124, 124)),\n", "])\n", "#ransforms.Normalize((0.8981),(0.1322))\n", "\n", "config = {\n", " \"lr\": 0.0001,\n", " \"epochs\": 15,\n", " \"bs\": 32,\n", " \"data_aug_train\": transform_train.__repr__(),\n", " \"data_aug_valid\": transform_valid.__repr__(),\n", " }\n", "\n", "run = wandb.init(project=\"signify\", config=config)\n", "\n", "dst = SiameseDataset(dirnames[\"train\"], n_samples=50000, transform_both=transform_train, transform_seperate=transform_train_indiv)\n", "dsv = SiameseDataset(dirnames[\"valid_clean\"], n_samples=500, transform_both=transform_valid)\n", "\n", "dlt = DataLoader(dst, config[\"bs\"], shuffle=True)\n", "dlv = DataLoader(dsv, config[\"bs\"], shuffle=True)\n", "\n", "# Set up the model\n", "#ackbone = models.resnet18(pretrained=True)\n", "backbone = models.efficientnet_v2_s(pretrained=True)\n", "model = SiameseNetwork(backbone, embedding_size=1000, add_layer=False)\n", "\n", "metrics = MetricsCB(wandb=wandb, accuracy=BinaryAccuracy()) # ProgressCB(plot=False), SaveModelCallback(), metrics,\n", "cbs = [TrainBceCB(n_inp=2), DeviceCB(def_device), SaveModelCallback(), ProgressCB(plot=True), metrics] #astats # LoadModelCallback(\"model_saved.pth\")\n", "\n", "optimizer = partial(optim.Adam, weight_decay=1e-5)\n", "learner = Learner(model, dlt, dlv, config[\"lr\"], cbs, opt_func=optimizer)" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
accuracylossepochtrain
0.6140.6750train
0.5710.6540eval
0.6260.6511train
0.5740.5971eval
0.6490.5942train
0.6690.5132eval
0.6850.5503train
0.7310.4823eval
0.7360.5104train
0.7830.4514eval
0.7790.4505train
0.7800.4325eval
0.7960.4176train
0.7830.4346eval
0.8080.4027train
0.7630.4587eval
0.8350.3718train
0.8030.4188eval
0.8400.3489train
0.7690.4689eval
0.8430.33810train
0.7910.39910eval
0.8370.34411train
0.7290.46711eval
0.8630.31712train
0.7970.40112eval
0.8740.29613train
0.8230.38113eval
0.8730.30414train
0.8230.38214eval
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD4CAYAAAD8Zh1EAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8qNh9FAAAACXBIWXMAAAsTAAALEwEAmpwYAAAmdElEQVR4nO3deZgU1b3/8feXYRlW2UZBhmVUFFARdCAqiBg1AiqYuADuRsUYjVs0l8RcY7xZjCbG6/1hDEYiMSoibqgYXAIhcWVQRJBt2GQAYUBW2eH8/jgFNkPPTM9MdVd3z+f1PP1QXV1d9e2a4TPVp06dMuccIiKS+epEXYCIiIRDgS4ikiUU6CIiWUKBLiKSJRToIiJZom5UG27durXr1KlTVJsXEclIM2bMWOucy4v3WmSB3qlTJ4qKiqLavIhIRjKzZeW9piYXEZEsoUAXEckSCnQRkSwRWRu6iEhV7dq1i5KSErZv3x51KUmXm5tLfn4+9erVS/g9C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FeiTMrAnwAnCbc24T8CfgSKAHsAr/NTCV+jrnTsTf5/UmM+sX+2LwFz6S/qhBO+lg4PlgVtT76gBR7pvymNndwG7g6WDWKqCDc64ncAfwjJk1S3R9NfyMafXzKmM4Bx4opHw/xcmCGq0vbJkW6Cm/2YaZ1cP/AJ92zr0I4Jxb7Zzb45zbCzyO/9pZUX2h1u2cWxH8uwZ4Kdj+6uBr276vnGtSWVOMgcDHzrnVQY2R7qtAWPtmBQc2i9S4NjO7GjgPuCwIBIJmjXXB9Ax8G/XRlWy/vM9YJSH+vNbhmxnqlplfLcF6vgc8F1NrSvdTvCyoYH3R/G5VtdE9ygd+uN/F+JMy+07AHJvE7Rm+LevhMvPbxkzfjm9bBDiWA08cLcafNAqtbqAx0DRm+j182/eDHHhy5oFg+lwOPDnzkfvm5MwS/ImZFsF0yxD22Tjgmij3FWVOloW5bzj4xNWgGtQ1AH+z9bwyy+UBOcH0Efj/2BVuv7zPWI2aQvt54b+lxZ4U/WF1aorZV/+KcD+VlwVp8bu1v56a/gdO9QN/9ngB/q/x3UneVl/8V6hZwMzgMQh4CvgsmD+xzH+Cu4Pa5hNzljqsuoNf3E+Dx5x968K3Wb4DLATejvklMWBUsN3PgMKYdX0ff3KrmJgQrkFtjfFHZofEzEvpvsJ/JV8F7MK3Q14b5r4BCoHZwXv+H8HV1tWsqxjfnrrvd+uxYNkLg5/tTOBj4PzKtl/eZ6xGTaH9vILf1Y+Cz/k80KA6NQXznwR+UGbZlOynSrIg8t+t2Icu/RcRyRKZ1oYuIiLlUKCLiGQJBbqISJZQoIuIZAkFuohIllCgi4hkCQW6iEiW+P+D774kyd8ZbwAAAABJRU5ErkJggg==", "text/plain": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "learner.fit(config[\"epochs\"])" ] }, { "cell_type": "markdown", "metadata": { "tags": [] }, "source": [ "### Pretrained with wandb sweep" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Create sweep with ID: 4khr9r9h\n", "Sweep URL: https://wandb.ai/crashedice/signify/sweeps/4khr9r9h\n" ] } ], "source": [ "sweep_config = {'method': 'random',\n", " 'metric': {'goal': 'minimize', 'name': 'loss_eval'},\n", " 'parameters': {'img_size': {'value': 128},\n", " 'epochs': {'value': 5},\n", " 'bs': {'values': [16]},\n", " 'lr': {'values': [0.0001, 0.00005]},\n", " 'embedding_size': {'values': [500, 1000, 2000]},\n", " 'backbone': {'values': [\"efficientnet\",\"resnet\"]},\n", " 'augmix_tfm': {'values': [True, False]},\n", " 'jitter_tfm': {'value': True},\n", " 'blur_tfm': {'value': False},\n", " 'randomerase_tfm': {'value': True},\n", " 'reflectpad_tfm': {'value': False},\n", " 'erase_max': {'values': [0.25, 0.3, 0.35]},\n", " 'aff1': {'values': [5,10,20,30]},\n", " 'aff2': {'values': [0.05,0.12,0.20,0.25]},\n", " 'aff3': {'values': [0.05,0.10,0.15,0.20]},\n", " 'aff4': {'values': [10,15,20,25]},\n", " 'wd': {'values': [1e-4, 5e-5, 1e-5, 5e-6]},\n", " 'droupout_p': {'value': 0}\n", " }}\n", "\n", "sweep_id = wandb.sweep(sweep_config, project=\"signify\")" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "\u001b[34m\u001b[1mwandb\u001b[0m: \u001b[33mWARNING\u001b[0m Calling wandb.login() after wandb.init() has no effect.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "\n", "\n", "\n", "\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "\u001b[34m\u001b[1mwandb\u001b[0m: Agent Starting Run: 8q6ja3l9 with config:\n", "\u001b[34m\u001b[1mwandb\u001b[0m: \taff1: 5\n", "\u001b[34m\u001b[1mwandb\u001b[0m: \taff2: 0.05\n", "\u001b[34m\u001b[1mwandb\u001b[0m: \taff3: 0.15\n", "\u001b[34m\u001b[1mwandb\u001b[0m: \taff4: 20\n", "\u001b[34m\u001b[1mwandb\u001b[0m: \taugmix_tfm: False\n", "\u001b[34m\u001b[1mwandb\u001b[0m: \tbackbone: resnet\n", "\u001b[34m\u001b[1mwandb\u001b[0m: \tblur_tfm: False\n", "\u001b[34m\u001b[1mwandb\u001b[0m: \tbs: 16\n", "\u001b[34m\u001b[1mwandb\u001b[0m: \tdroupout_p: 0\n", "\u001b[34m\u001b[1mwandb\u001b[0m: \tembedding_size: 2000\n", "\u001b[34m\u001b[1mwandb\u001b[0m: \tepochs: 5\n", "\u001b[34m\u001b[1mwandb\u001b[0m: \terase_max: 0.25\n", "\u001b[34m\u001b[1mwandb\u001b[0m: \timg_size: 128\n", "\u001b[34m\u001b[1mwandb\u001b[0m: \tjitter_tfm: True\n", "\u001b[34m\u001b[1mwandb\u001b[0m: \tlr: 5e-05\n", "\u001b[34m\u001b[1mwandb\u001b[0m: \trandomerase_tfm: True\n", "\u001b[34m\u001b[1mwandb\u001b[0m: \treflectpad_tfm: False\n", "\u001b[34m\u001b[1mwandb\u001b[0m: \twd: 0.0001\n" ] }, { "data": { "text/html": [ "Tracking run with wandb version 0.15.3" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "Run data is saved locally in /storage/projects/signature/signify/nbs/wandb/run-20230530_101355-8q6ja3l9" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "Syncing run youthful-sweep-1 to Weights & Biases (docs)
Sweep page: https://wandb.ai/crashedice/signify/sweeps/4khr9r9h" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ " View project at https://wandb.ai/crashedice/signify" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ " View sweep at https://wandb.ai/crashedice/signify/sweeps/4khr9r9h" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ " View run at https://wandb.ai/crashedice/signify/runs/8q6ja3l9" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stderr", "output_type": "stream", "text": [ "\u001b[34m\u001b[1mwandb\u001b[0m: \u001b[33mWARNING\u001b[0m Ignored wandb.init() arg project when running a sweep.\n" ] }, { "data": { "text/html": [ "Finishing last run (ID:8q6ja3l9) before initializing another..." ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "Waiting for W&B process to finish... (success)." ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ " View run youthful-sweep-1 at: https://wandb.ai/crashedice/signify/runs/8q6ja3l9
Synced 5 W&B file(s), 0 media file(s), 0 artifact file(s) and 0 other file(s)" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "Find logs at: ./wandb/run-20230530_101355-8q6ja3l9/logs" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "Successfully finished last run (ID:8q6ja3l9). Initializing new run:
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "Tracking run with wandb version 0.15.3" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "Run data is saved locally in /storage/projects/signature/signify/nbs/wandb/run-20230530_101356-8q6ja3l9" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "Syncing run youthful-sweep-1 to Weights & Biases (docs)
Sweep page: https://wandb.ai/crashedice/signify/sweeps/4khr9r9h" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ " View project at https://wandb.ai/crashedice/signify" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ " View sweep at https://wandb.ai/crashedice/signify/sweeps/4khr9r9h" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ " View run at https://wandb.ai/crashedice/signify/runs/8q6ja3l9" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stderr", "output_type": "stream", "text": [ "\u001b[34m\u001b[1mwandb\u001b[0m: \u001b[32m\u001b[41mERROR\u001b[0m Run 8q6ja3l9 errored: TypeError(\"__init__() got an unexpected keyword argument 'transform'\")\n", "\u001b[34m\u001b[1mwandb\u001b[0m: Ctrl + C detected. Stopping sweep.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Error in callback (for post_run_cell):\n" ] }, { "ename": "BrokenPipeError", "evalue": "[Errno 32] Broken pipe", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mBrokenPipeError\u001b[0m Traceback (most recent call last)", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/backcall/backcall.py:104\u001b[0m, in \u001b[0;36mcallback_prototype..adapt..adapted\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 102\u001b[0m kwargs\u001b[38;5;241m.\u001b[39mpop(name)\n\u001b[1;32m 103\u001b[0m \u001b[38;5;66;03m# print(args, kwargs, unmatched_pos, cut_positional, unmatched_kw)\u001b[39;00m\n\u001b[0;32m--> 104\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mcallback\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/wandb_init.py:419\u001b[0m, in \u001b[0;36m_WandbInit._pause_backend\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 417\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mbackend\u001b[38;5;241m.\u001b[39minterface \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 418\u001b[0m logger\u001b[38;5;241m.\u001b[39minfo(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mpausing backend\u001b[39m\u001b[38;5;124m\"\u001b[39m) \u001b[38;5;66;03m# type: ignore\u001b[39;00m\n\u001b[0;32m--> 419\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mbackend\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43minterface\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mpublish_pause\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/interface/interface.py:665\u001b[0m, in \u001b[0;36mInterfaceBase.publish_pause\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 663\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mpublish_pause\u001b[39m(\u001b[38;5;28mself\u001b[39m) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 664\u001b[0m pause \u001b[38;5;241m=\u001b[39m pb\u001b[38;5;241m.\u001b[39mPauseRequest()\n\u001b[0;32m--> 665\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_publish_pause\u001b[49m\u001b[43m(\u001b[49m\u001b[43mpause\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/interface/interface_shared.py:340\u001b[0m, in \u001b[0;36mInterfaceShared._publish_pause\u001b[0;34m(self, pause)\u001b[0m\n\u001b[1;32m 338\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_publish_pause\u001b[39m(\u001b[38;5;28mself\u001b[39m, pause: pb\u001b[38;5;241m.\u001b[39mPauseRequest) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 339\u001b[0m rec \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_make_request(pause\u001b[38;5;241m=\u001b[39mpause)\n\u001b[0;32m--> 340\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_publish\u001b[49m\u001b[43m(\u001b[49m\u001b[43mrec\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/interface/interface_sock.py:51\u001b[0m, in \u001b[0;36mInterfaceSock._publish\u001b[0;34m(self, record, local)\u001b[0m\n\u001b[1;32m 49\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_publish\u001b[39m(\u001b[38;5;28mself\u001b[39m, record: \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mpb.Record\u001b[39m\u001b[38;5;124m\"\u001b[39m, local: Optional[\u001b[38;5;28mbool\u001b[39m] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 50\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_assign(record)\n\u001b[0;32m---> 51\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_sock_client\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msend_record_publish\u001b[49m\u001b[43m(\u001b[49m\u001b[43mrecord\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/lib/sock_client.py:221\u001b[0m, in \u001b[0;36mSockClient.send_record_publish\u001b[0;34m(self, record)\u001b[0m\n\u001b[1;32m 219\u001b[0m server_req \u001b[38;5;241m=\u001b[39m spb\u001b[38;5;241m.\u001b[39mServerRequest()\n\u001b[1;32m 220\u001b[0m server_req\u001b[38;5;241m.\u001b[39mrecord_publish\u001b[38;5;241m.\u001b[39mCopyFrom(record)\n\u001b[0;32m--> 221\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msend_server_request\u001b[49m\u001b[43m(\u001b[49m\u001b[43mserver_req\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/lib/sock_client.py:155\u001b[0m, in \u001b[0;36mSockClient.send_server_request\u001b[0;34m(self, msg)\u001b[0m\n\u001b[1;32m 154\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21msend_server_request\u001b[39m(\u001b[38;5;28mself\u001b[39m, msg: Any) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[0;32m--> 155\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_send_message\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmsg\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/lib/sock_client.py:152\u001b[0m, in \u001b[0;36mSockClient._send_message\u001b[0;34m(self, msg)\u001b[0m\n\u001b[1;32m 150\u001b[0m header \u001b[38;5;241m=\u001b[39m struct\u001b[38;5;241m.\u001b[39mpack(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m 152\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_sendall_with_error_handle\u001b[49m\u001b[43m(\u001b[49m\u001b[43mheader\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43m \u001b[49m\u001b[43mdata\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/lib/sock_client.py:130\u001b[0m, in \u001b[0;36mSockClient._sendall_with_error_handle\u001b[0;34m(self, data)\u001b[0m\n\u001b[1;32m 128\u001b[0m start_time \u001b[38;5;241m=\u001b[39m time\u001b[38;5;241m.\u001b[39mmonotonic()\n\u001b[1;32m 129\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m--> 130\u001b[0m sent \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_sock\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msend\u001b[49m\u001b[43m(\u001b[49m\u001b[43mdata\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 131\u001b[0m \u001b[38;5;66;03m# sent equal to 0 indicates a closed socket\u001b[39;00m\n\u001b[1;32m 132\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m sent \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m0\u001b[39m:\n", "\u001b[0;31mBrokenPipeError\u001b[0m: [Errno 32] Broken pipe" ] } ], "source": [ "wandb.agent(sweep_id, train, count=30)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Inference" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Error in callback (for pre_run_cell):\n" ] }, { "ename": "BrokenPipeError", "evalue": "[Errno 32] Broken pipe", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mBrokenPipeError\u001b[0m Traceback (most recent call last)", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/backcall/backcall.py:104\u001b[0m, in \u001b[0;36mcallback_prototype..adapt..adapted\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 102\u001b[0m kwargs\u001b[38;5;241m.\u001b[39mpop(name)\n\u001b[1;32m 103\u001b[0m \u001b[38;5;66;03m# print(args, kwargs, unmatched_pos, cut_positional, unmatched_kw)\u001b[39;00m\n\u001b[0;32m--> 104\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mcallback\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/wandb_init.py:424\u001b[0m, in \u001b[0;36m_WandbInit._resume_backend\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 422\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mbackend \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mbackend\u001b[38;5;241m.\u001b[39minterface \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 423\u001b[0m logger\u001b[38;5;241m.\u001b[39minfo(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mresuming backend\u001b[39m\u001b[38;5;124m\"\u001b[39m) \u001b[38;5;66;03m# type: ignore\u001b[39;00m\n\u001b[0;32m--> 424\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mbackend\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43minterface\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mpublish_resume\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/interface/interface.py:673\u001b[0m, in \u001b[0;36mInterfaceBase.publish_resume\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 671\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mpublish_resume\u001b[39m(\u001b[38;5;28mself\u001b[39m) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 672\u001b[0m resume \u001b[38;5;241m=\u001b[39m pb\u001b[38;5;241m.\u001b[39mResumeRequest()\n\u001b[0;32m--> 673\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_publish_resume\u001b[49m\u001b[43m(\u001b[49m\u001b[43mresume\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/interface/interface_shared.py:344\u001b[0m, in \u001b[0;36mInterfaceShared._publish_resume\u001b[0;34m(self, resume)\u001b[0m\n\u001b[1;32m 342\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_publish_resume\u001b[39m(\u001b[38;5;28mself\u001b[39m, resume: pb\u001b[38;5;241m.\u001b[39mResumeRequest) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 343\u001b[0m rec \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_make_request(resume\u001b[38;5;241m=\u001b[39mresume)\n\u001b[0;32m--> 344\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_publish\u001b[49m\u001b[43m(\u001b[49m\u001b[43mrec\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/interface/interface_sock.py:51\u001b[0m, in \u001b[0;36mInterfaceSock._publish\u001b[0;34m(self, record, local)\u001b[0m\n\u001b[1;32m 49\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_publish\u001b[39m(\u001b[38;5;28mself\u001b[39m, record: \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mpb.Record\u001b[39m\u001b[38;5;124m\"\u001b[39m, local: Optional[\u001b[38;5;28mbool\u001b[39m] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 50\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_assign(record)\n\u001b[0;32m---> 51\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_sock_client\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msend_record_publish\u001b[49m\u001b[43m(\u001b[49m\u001b[43mrecord\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/lib/sock_client.py:221\u001b[0m, in \u001b[0;36mSockClient.send_record_publish\u001b[0;34m(self, record)\u001b[0m\n\u001b[1;32m 219\u001b[0m server_req \u001b[38;5;241m=\u001b[39m spb\u001b[38;5;241m.\u001b[39mServerRequest()\n\u001b[1;32m 220\u001b[0m server_req\u001b[38;5;241m.\u001b[39mrecord_publish\u001b[38;5;241m.\u001b[39mCopyFrom(record)\n\u001b[0;32m--> 221\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msend_server_request\u001b[49m\u001b[43m(\u001b[49m\u001b[43mserver_req\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/lib/sock_client.py:155\u001b[0m, in \u001b[0;36mSockClient.send_server_request\u001b[0;34m(self, msg)\u001b[0m\n\u001b[1;32m 154\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21msend_server_request\u001b[39m(\u001b[38;5;28mself\u001b[39m, msg: Any) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[0;32m--> 155\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_send_message\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmsg\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/lib/sock_client.py:152\u001b[0m, in \u001b[0;36mSockClient._send_message\u001b[0;34m(self, msg)\u001b[0m\n\u001b[1;32m 150\u001b[0m header \u001b[38;5;241m=\u001b[39m struct\u001b[38;5;241m.\u001b[39mpack(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m 152\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_sendall_with_error_handle\u001b[49m\u001b[43m(\u001b[49m\u001b[43mheader\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43m \u001b[49m\u001b[43mdata\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/lib/sock_client.py:130\u001b[0m, in \u001b[0;36mSockClient._sendall_with_error_handle\u001b[0;34m(self, data)\u001b[0m\n\u001b[1;32m 128\u001b[0m start_time \u001b[38;5;241m=\u001b[39m time\u001b[38;5;241m.\u001b[39mmonotonic()\n\u001b[1;32m 129\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m--> 130\u001b[0m sent \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_sock\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msend\u001b[49m\u001b[43m(\u001b[49m\u001b[43mdata\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 131\u001b[0m \u001b[38;5;66;03m# sent equal to 0 indicates a closed socket\u001b[39;00m\n\u001b[1;32m 132\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m sent \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m0\u001b[39m:\n", "\u001b[0;31mBrokenPipeError\u001b[0m: [Errno 32] Broken pipe" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Error in callback (for post_run_cell):\n" ] }, { "ename": "BrokenPipeError", "evalue": "[Errno 32] Broken pipe", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mBrokenPipeError\u001b[0m Traceback (most recent call last)", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/backcall/backcall.py:104\u001b[0m, in \u001b[0;36mcallback_prototype..adapt..adapted\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 102\u001b[0m kwargs\u001b[38;5;241m.\u001b[39mpop(name)\n\u001b[1;32m 103\u001b[0m \u001b[38;5;66;03m# print(args, kwargs, unmatched_pos, cut_positional, unmatched_kw)\u001b[39;00m\n\u001b[0;32m--> 104\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mcallback\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/wandb_init.py:419\u001b[0m, in \u001b[0;36m_WandbInit._pause_backend\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 417\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mbackend\u001b[38;5;241m.\u001b[39minterface \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 418\u001b[0m logger\u001b[38;5;241m.\u001b[39minfo(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mpausing backend\u001b[39m\u001b[38;5;124m\"\u001b[39m) \u001b[38;5;66;03m# type: ignore\u001b[39;00m\n\u001b[0;32m--> 419\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mbackend\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43minterface\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mpublish_pause\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/interface/interface.py:665\u001b[0m, in \u001b[0;36mInterfaceBase.publish_pause\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 663\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mpublish_pause\u001b[39m(\u001b[38;5;28mself\u001b[39m) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 664\u001b[0m pause \u001b[38;5;241m=\u001b[39m pb\u001b[38;5;241m.\u001b[39mPauseRequest()\n\u001b[0;32m--> 665\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_publish_pause\u001b[49m\u001b[43m(\u001b[49m\u001b[43mpause\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/interface/interface_shared.py:340\u001b[0m, in \u001b[0;36mInterfaceShared._publish_pause\u001b[0;34m(self, pause)\u001b[0m\n\u001b[1;32m 338\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_publish_pause\u001b[39m(\u001b[38;5;28mself\u001b[39m, pause: pb\u001b[38;5;241m.\u001b[39mPauseRequest) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 339\u001b[0m rec \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_make_request(pause\u001b[38;5;241m=\u001b[39mpause)\n\u001b[0;32m--> 340\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_publish\u001b[49m\u001b[43m(\u001b[49m\u001b[43mrec\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/interface/interface_sock.py:51\u001b[0m, in \u001b[0;36mInterfaceSock._publish\u001b[0;34m(self, record, local)\u001b[0m\n\u001b[1;32m 49\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_publish\u001b[39m(\u001b[38;5;28mself\u001b[39m, record: \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mpb.Record\u001b[39m\u001b[38;5;124m\"\u001b[39m, local: Optional[\u001b[38;5;28mbool\u001b[39m] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 50\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_assign(record)\n\u001b[0;32m---> 51\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_sock_client\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msend_record_publish\u001b[49m\u001b[43m(\u001b[49m\u001b[43mrecord\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/lib/sock_client.py:221\u001b[0m, in \u001b[0;36mSockClient.send_record_publish\u001b[0;34m(self, record)\u001b[0m\n\u001b[1;32m 219\u001b[0m server_req \u001b[38;5;241m=\u001b[39m spb\u001b[38;5;241m.\u001b[39mServerRequest()\n\u001b[1;32m 220\u001b[0m server_req\u001b[38;5;241m.\u001b[39mrecord_publish\u001b[38;5;241m.\u001b[39mCopyFrom(record)\n\u001b[0;32m--> 221\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msend_server_request\u001b[49m\u001b[43m(\u001b[49m\u001b[43mserver_req\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/lib/sock_client.py:155\u001b[0m, in \u001b[0;36mSockClient.send_server_request\u001b[0;34m(self, msg)\u001b[0m\n\u001b[1;32m 154\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21msend_server_request\u001b[39m(\u001b[38;5;28mself\u001b[39m, msg: Any) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[0;32m--> 155\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_send_message\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmsg\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/lib/sock_client.py:152\u001b[0m, in \u001b[0;36mSockClient._send_message\u001b[0;34m(self, msg)\u001b[0m\n\u001b[1;32m 150\u001b[0m header \u001b[38;5;241m=\u001b[39m struct\u001b[38;5;241m.\u001b[39mpack(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m 152\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_sendall_with_error_handle\u001b[49m\u001b[43m(\u001b[49m\u001b[43mheader\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43m \u001b[49m\u001b[43mdata\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/lib/sock_client.py:130\u001b[0m, in \u001b[0;36mSockClient._sendall_with_error_handle\u001b[0;34m(self, data)\u001b[0m\n\u001b[1;32m 128\u001b[0m start_time \u001b[38;5;241m=\u001b[39m time\u001b[38;5;241m.\u001b[39mmonotonic()\n\u001b[1;32m 129\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m--> 130\u001b[0m sent \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_sock\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msend\u001b[49m\u001b[43m(\u001b[49m\u001b[43mdata\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 131\u001b[0m \u001b[38;5;66;03m# sent equal to 0 indicates a closed socket\u001b[39;00m\n\u001b[1;32m 132\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m sent \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m0\u001b[39m:\n", "\u001b[0;31mBrokenPipeError\u001b[0m: [Errno 32] Broken pipe" ] } ], "source": [ "model =None" ] }, { "cell_type": "code", "execution_count": 31, "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Error in callback (for pre_run_cell):\n" ] }, { "ename": "BrokenPipeError", "evalue": "[Errno 32] Broken pipe", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mBrokenPipeError\u001b[0m Traceback (most recent call last)", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/backcall/backcall.py:104\u001b[0m, in \u001b[0;36mcallback_prototype..adapt..adapted\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 102\u001b[0m kwargs\u001b[38;5;241m.\u001b[39mpop(name)\n\u001b[1;32m 103\u001b[0m \u001b[38;5;66;03m# print(args, kwargs, unmatched_pos, cut_positional, unmatched_kw)\u001b[39;00m\n\u001b[0;32m--> 104\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mcallback\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/wandb_init.py:424\u001b[0m, in \u001b[0;36m_WandbInit._resume_backend\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 422\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mbackend \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mbackend\u001b[38;5;241m.\u001b[39minterface \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 423\u001b[0m logger\u001b[38;5;241m.\u001b[39minfo(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mresuming backend\u001b[39m\u001b[38;5;124m\"\u001b[39m) \u001b[38;5;66;03m# type: ignore\u001b[39;00m\n\u001b[0;32m--> 424\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mbackend\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43minterface\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mpublish_resume\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/interface/interface.py:673\u001b[0m, in \u001b[0;36mInterfaceBase.publish_resume\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 671\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mpublish_resume\u001b[39m(\u001b[38;5;28mself\u001b[39m) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 672\u001b[0m resume \u001b[38;5;241m=\u001b[39m pb\u001b[38;5;241m.\u001b[39mResumeRequest()\n\u001b[0;32m--> 673\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_publish_resume\u001b[49m\u001b[43m(\u001b[49m\u001b[43mresume\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/interface/interface_shared.py:344\u001b[0m, in \u001b[0;36mInterfaceShared._publish_resume\u001b[0;34m(self, resume)\u001b[0m\n\u001b[1;32m 342\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_publish_resume\u001b[39m(\u001b[38;5;28mself\u001b[39m, resume: pb\u001b[38;5;241m.\u001b[39mResumeRequest) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 343\u001b[0m rec \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_make_request(resume\u001b[38;5;241m=\u001b[39mresume)\n\u001b[0;32m--> 344\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_publish\u001b[49m\u001b[43m(\u001b[49m\u001b[43mrec\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/interface/interface_sock.py:51\u001b[0m, in \u001b[0;36mInterfaceSock._publish\u001b[0;34m(self, record, local)\u001b[0m\n\u001b[1;32m 49\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_publish\u001b[39m(\u001b[38;5;28mself\u001b[39m, record: \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mpb.Record\u001b[39m\u001b[38;5;124m\"\u001b[39m, local: Optional[\u001b[38;5;28mbool\u001b[39m] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 50\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_assign(record)\n\u001b[0;32m---> 51\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_sock_client\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msend_record_publish\u001b[49m\u001b[43m(\u001b[49m\u001b[43mrecord\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/lib/sock_client.py:221\u001b[0m, in \u001b[0;36mSockClient.send_record_publish\u001b[0;34m(self, record)\u001b[0m\n\u001b[1;32m 219\u001b[0m server_req \u001b[38;5;241m=\u001b[39m spb\u001b[38;5;241m.\u001b[39mServerRequest()\n\u001b[1;32m 220\u001b[0m server_req\u001b[38;5;241m.\u001b[39mrecord_publish\u001b[38;5;241m.\u001b[39mCopyFrom(record)\n\u001b[0;32m--> 221\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msend_server_request\u001b[49m\u001b[43m(\u001b[49m\u001b[43mserver_req\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/lib/sock_client.py:155\u001b[0m, in \u001b[0;36mSockClient.send_server_request\u001b[0;34m(self, msg)\u001b[0m\n\u001b[1;32m 154\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21msend_server_request\u001b[39m(\u001b[38;5;28mself\u001b[39m, msg: Any) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[0;32m--> 155\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_send_message\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmsg\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/lib/sock_client.py:152\u001b[0m, in \u001b[0;36mSockClient._send_message\u001b[0;34m(self, msg)\u001b[0m\n\u001b[1;32m 150\u001b[0m header \u001b[38;5;241m=\u001b[39m struct\u001b[38;5;241m.\u001b[39mpack(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m 152\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_sendall_with_error_handle\u001b[49m\u001b[43m(\u001b[49m\u001b[43mheader\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43m \u001b[49m\u001b[43mdata\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/lib/sock_client.py:130\u001b[0m, in \u001b[0;36mSockClient._sendall_with_error_handle\u001b[0;34m(self, data)\u001b[0m\n\u001b[1;32m 128\u001b[0m start_time \u001b[38;5;241m=\u001b[39m time\u001b[38;5;241m.\u001b[39mmonotonic()\n\u001b[1;32m 129\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m--> 130\u001b[0m sent \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_sock\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msend\u001b[49m\u001b[43m(\u001b[49m\u001b[43mdata\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 131\u001b[0m \u001b[38;5;66;03m# sent equal to 0 indicates a closed socket\u001b[39;00m\n\u001b[1;32m 132\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m sent \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m0\u001b[39m:\n", "\u001b[0;31mBrokenPipeError\u001b[0m: [Errno 32] Broken pipe" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Error in callback (for post_run_cell):\n" ] }, { "ename": "BrokenPipeError", "evalue": "[Errno 32] Broken pipe", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mBrokenPipeError\u001b[0m Traceback (most recent call last)", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/backcall/backcall.py:104\u001b[0m, in \u001b[0;36mcallback_prototype..adapt..adapted\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 102\u001b[0m kwargs\u001b[38;5;241m.\u001b[39mpop(name)\n\u001b[1;32m 103\u001b[0m \u001b[38;5;66;03m# print(args, kwargs, unmatched_pos, cut_positional, unmatched_kw)\u001b[39;00m\n\u001b[0;32m--> 104\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mcallback\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/wandb_init.py:419\u001b[0m, in \u001b[0;36m_WandbInit._pause_backend\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 417\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mbackend\u001b[38;5;241m.\u001b[39minterface \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 418\u001b[0m logger\u001b[38;5;241m.\u001b[39minfo(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mpausing backend\u001b[39m\u001b[38;5;124m\"\u001b[39m) \u001b[38;5;66;03m# type: ignore\u001b[39;00m\n\u001b[0;32m--> 419\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mbackend\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43minterface\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mpublish_pause\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/interface/interface.py:665\u001b[0m, in \u001b[0;36mInterfaceBase.publish_pause\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 663\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mpublish_pause\u001b[39m(\u001b[38;5;28mself\u001b[39m) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 664\u001b[0m pause \u001b[38;5;241m=\u001b[39m pb\u001b[38;5;241m.\u001b[39mPauseRequest()\n\u001b[0;32m--> 665\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_publish_pause\u001b[49m\u001b[43m(\u001b[49m\u001b[43mpause\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/interface/interface_shared.py:340\u001b[0m, in \u001b[0;36mInterfaceShared._publish_pause\u001b[0;34m(self, pause)\u001b[0m\n\u001b[1;32m 338\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_publish_pause\u001b[39m(\u001b[38;5;28mself\u001b[39m, pause: pb\u001b[38;5;241m.\u001b[39mPauseRequest) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 339\u001b[0m rec \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_make_request(pause\u001b[38;5;241m=\u001b[39mpause)\n\u001b[0;32m--> 340\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_publish\u001b[49m\u001b[43m(\u001b[49m\u001b[43mrec\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/interface/interface_sock.py:51\u001b[0m, in \u001b[0;36mInterfaceSock._publish\u001b[0;34m(self, record, local)\u001b[0m\n\u001b[1;32m 49\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_publish\u001b[39m(\u001b[38;5;28mself\u001b[39m, record: \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mpb.Record\u001b[39m\u001b[38;5;124m\"\u001b[39m, local: Optional[\u001b[38;5;28mbool\u001b[39m] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 50\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_assign(record)\n\u001b[0;32m---> 51\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_sock_client\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msend_record_publish\u001b[49m\u001b[43m(\u001b[49m\u001b[43mrecord\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/lib/sock_client.py:221\u001b[0m, in \u001b[0;36mSockClient.send_record_publish\u001b[0;34m(self, record)\u001b[0m\n\u001b[1;32m 219\u001b[0m server_req \u001b[38;5;241m=\u001b[39m spb\u001b[38;5;241m.\u001b[39mServerRequest()\n\u001b[1;32m 220\u001b[0m server_req\u001b[38;5;241m.\u001b[39mrecord_publish\u001b[38;5;241m.\u001b[39mCopyFrom(record)\n\u001b[0;32m--> 221\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msend_server_request\u001b[49m\u001b[43m(\u001b[49m\u001b[43mserver_req\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/lib/sock_client.py:155\u001b[0m, in \u001b[0;36mSockClient.send_server_request\u001b[0;34m(self, msg)\u001b[0m\n\u001b[1;32m 154\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21msend_server_request\u001b[39m(\u001b[38;5;28mself\u001b[39m, msg: Any) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[0;32m--> 155\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_send_message\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmsg\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/lib/sock_client.py:152\u001b[0m, in \u001b[0;36mSockClient._send_message\u001b[0;34m(self, msg)\u001b[0m\n\u001b[1;32m 150\u001b[0m header \u001b[38;5;241m=\u001b[39m struct\u001b[38;5;241m.\u001b[39mpack(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m 152\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_sendall_with_error_handle\u001b[49m\u001b[43m(\u001b[49m\u001b[43mheader\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43m \u001b[49m\u001b[43mdata\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/lib/sock_client.py:130\u001b[0m, in \u001b[0;36mSockClient._sendall_with_error_handle\u001b[0;34m(self, data)\u001b[0m\n\u001b[1;32m 128\u001b[0m start_time \u001b[38;5;241m=\u001b[39m time\u001b[38;5;241m.\u001b[39mmonotonic()\n\u001b[1;32m 129\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m--> 130\u001b[0m sent \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_sock\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msend\u001b[49m\u001b[43m(\u001b[49m\u001b[43mdata\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 131\u001b[0m \u001b[38;5;66;03m# sent equal to 0 indicates a closed socket\u001b[39;00m\n\u001b[1;32m 132\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m sent \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m0\u001b[39m:\n", "\u001b[0;31mBrokenPipeError\u001b[0m: [Errno 32] Broken pipe" ] } ], "source": [ "weights = torch.load(\"siamese.pth\")" ] }, { "cell_type": "code", "execution_count": 32, "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Error in callback (for pre_run_cell):\n" ] }, { "ename": "BrokenPipeError", "evalue": "[Errno 32] Broken pipe", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mBrokenPipeError\u001b[0m Traceback (most recent call last)", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/backcall/backcall.py:104\u001b[0m, in \u001b[0;36mcallback_prototype..adapt..adapted\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 102\u001b[0m kwargs\u001b[38;5;241m.\u001b[39mpop(name)\n\u001b[1;32m 103\u001b[0m \u001b[38;5;66;03m# print(args, kwargs, unmatched_pos, cut_positional, unmatched_kw)\u001b[39;00m\n\u001b[0;32m--> 104\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mcallback\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/wandb_init.py:424\u001b[0m, in \u001b[0;36m_WandbInit._resume_backend\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 422\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mbackend \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mbackend\u001b[38;5;241m.\u001b[39minterface \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 423\u001b[0m logger\u001b[38;5;241m.\u001b[39minfo(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mresuming backend\u001b[39m\u001b[38;5;124m\"\u001b[39m) \u001b[38;5;66;03m# type: ignore\u001b[39;00m\n\u001b[0;32m--> 424\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mbackend\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43minterface\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mpublish_resume\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/interface/interface.py:673\u001b[0m, in \u001b[0;36mInterfaceBase.publish_resume\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 671\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mpublish_resume\u001b[39m(\u001b[38;5;28mself\u001b[39m) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 672\u001b[0m resume \u001b[38;5;241m=\u001b[39m pb\u001b[38;5;241m.\u001b[39mResumeRequest()\n\u001b[0;32m--> 673\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_publish_resume\u001b[49m\u001b[43m(\u001b[49m\u001b[43mresume\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/interface/interface_shared.py:344\u001b[0m, in \u001b[0;36mInterfaceShared._publish_resume\u001b[0;34m(self, resume)\u001b[0m\n\u001b[1;32m 342\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_publish_resume\u001b[39m(\u001b[38;5;28mself\u001b[39m, resume: pb\u001b[38;5;241m.\u001b[39mResumeRequest) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 343\u001b[0m rec \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_make_request(resume\u001b[38;5;241m=\u001b[39mresume)\n\u001b[0;32m--> 344\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_publish\u001b[49m\u001b[43m(\u001b[49m\u001b[43mrec\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/interface/interface_sock.py:51\u001b[0m, in \u001b[0;36mInterfaceSock._publish\u001b[0;34m(self, record, local)\u001b[0m\n\u001b[1;32m 49\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_publish\u001b[39m(\u001b[38;5;28mself\u001b[39m, record: \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mpb.Record\u001b[39m\u001b[38;5;124m\"\u001b[39m, local: Optional[\u001b[38;5;28mbool\u001b[39m] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 50\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_assign(record)\n\u001b[0;32m---> 51\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_sock_client\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msend_record_publish\u001b[49m\u001b[43m(\u001b[49m\u001b[43mrecord\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/lib/sock_client.py:221\u001b[0m, in \u001b[0;36mSockClient.send_record_publish\u001b[0;34m(self, record)\u001b[0m\n\u001b[1;32m 219\u001b[0m server_req \u001b[38;5;241m=\u001b[39m spb\u001b[38;5;241m.\u001b[39mServerRequest()\n\u001b[1;32m 220\u001b[0m server_req\u001b[38;5;241m.\u001b[39mrecord_publish\u001b[38;5;241m.\u001b[39mCopyFrom(record)\n\u001b[0;32m--> 221\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msend_server_request\u001b[49m\u001b[43m(\u001b[49m\u001b[43mserver_req\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/lib/sock_client.py:155\u001b[0m, in \u001b[0;36mSockClient.send_server_request\u001b[0;34m(self, msg)\u001b[0m\n\u001b[1;32m 154\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21msend_server_request\u001b[39m(\u001b[38;5;28mself\u001b[39m, msg: Any) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[0;32m--> 155\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_send_message\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmsg\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/lib/sock_client.py:152\u001b[0m, in \u001b[0;36mSockClient._send_message\u001b[0;34m(self, msg)\u001b[0m\n\u001b[1;32m 150\u001b[0m header \u001b[38;5;241m=\u001b[39m struct\u001b[38;5;241m.\u001b[39mpack(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m 152\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_sendall_with_error_handle\u001b[49m\u001b[43m(\u001b[49m\u001b[43mheader\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43m \u001b[49m\u001b[43mdata\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/lib/sock_client.py:130\u001b[0m, in \u001b[0;36mSockClient._sendall_with_error_handle\u001b[0;34m(self, data)\u001b[0m\n\u001b[1;32m 128\u001b[0m start_time \u001b[38;5;241m=\u001b[39m time\u001b[38;5;241m.\u001b[39mmonotonic()\n\u001b[1;32m 129\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m--> 130\u001b[0m sent \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_sock\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msend\u001b[49m\u001b[43m(\u001b[49m\u001b[43mdata\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 131\u001b[0m \u001b[38;5;66;03m# sent equal to 0 indicates a closed socket\u001b[39;00m\n\u001b[1;32m 132\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m sent \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m0\u001b[39m:\n", "\u001b[0;31mBrokenPipeError\u001b[0m: [Errno 32] Broken pipe" ] }, { "name": "stderr", "output_type": "stream", "text": [ "/usr/local/lib/python3.9/dist-packages/torchvision/models/_utils.py:208: UserWarning: The parameter 'pretrained' is deprecated since 0.13 and will be removed in 0.15, please use 'weights' instead.\n", " warnings.warn(\n", "/usr/local/lib/python3.9/dist-packages/torchvision/models/_utils.py:223: UserWarning: Arguments other than a weight enum or `None` for 'weights' are deprecated since 0.13 and will be removed in 0.15. The current behavior is equivalent to passing `weights=EfficientNet_V2_S_Weights.IMAGENET1K_V1`. You can also use `weights=EfficientNet_V2_S_Weights.DEFAULT` to get the most up-to-date weights.\n", " warnings.warn(msg)\n" ] }, { "ename": "TypeError", "evalue": "Expected state_dict to be dict-like, got .", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", "Input \u001b[0;32mIn [32]\u001b[0m, in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 2\u001b[0m backbone \u001b[38;5;241m=\u001b[39m models\u001b[38;5;241m.\u001b[39mefficientnet_v2_s(pretrained\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n\u001b[1;32m 3\u001b[0m model \u001b[38;5;241m=\u001b[39m SiameseNetwork(backbone, embedding_size\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m1000\u001b[39m)\u001b[38;5;241m.\u001b[39mto(device)\n\u001b[0;32m----> 4\u001b[0m \u001b[43mmodel\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mload_state_dict\u001b[49m\u001b[43m(\u001b[49m\u001b[43mweights\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/torch/nn/modules/module.py:1559\u001b[0m, in \u001b[0;36mModule.load_state_dict\u001b[0;34m(self, state_dict, strict)\u001b[0m\n\u001b[1;32m 1536\u001b[0m \u001b[38;5;124mr\u001b[39m\u001b[38;5;124;03m\"\"\"Copies parameters and buffers from :attr:`state_dict` into\u001b[39;00m\n\u001b[1;32m 1537\u001b[0m \u001b[38;5;124;03mthis module and its descendants. If :attr:`strict` is ``True``, then\u001b[39;00m\n\u001b[1;32m 1538\u001b[0m \u001b[38;5;124;03mthe keys of :attr:`state_dict` must exactly match the keys returned\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 1556\u001b[0m \u001b[38;5;124;03m ``RuntimeError``.\u001b[39;00m\n\u001b[1;32m 1557\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 1558\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(state_dict, Mapping):\n\u001b[0;32m-> 1559\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mTypeError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mExpected state_dict to be dict-like, got \u001b[39m\u001b[38;5;132;01m{}\u001b[39;00m\u001b[38;5;124m.\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;241m.\u001b[39mformat(\u001b[38;5;28mtype\u001b[39m(state_dict)))\n\u001b[1;32m 1561\u001b[0m missing_keys: List[\u001b[38;5;28mstr\u001b[39m] \u001b[38;5;241m=\u001b[39m []\n\u001b[1;32m 1562\u001b[0m unexpected_keys: List[\u001b[38;5;28mstr\u001b[39m] \u001b[38;5;241m=\u001b[39m []\n", "\u001b[0;31mTypeError\u001b[0m: Expected state_dict to be dict-like, got ." ] }, { "name": "stdout", "output_type": "stream", "text": [ "Error in callback (for post_run_cell):\n" ] }, { "ename": "BrokenPipeError", "evalue": "[Errno 32] Broken pipe", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mBrokenPipeError\u001b[0m Traceback (most recent call last)", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/backcall/backcall.py:104\u001b[0m, in \u001b[0;36mcallback_prototype..adapt..adapted\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 102\u001b[0m kwargs\u001b[38;5;241m.\u001b[39mpop(name)\n\u001b[1;32m 103\u001b[0m \u001b[38;5;66;03m# print(args, kwargs, unmatched_pos, cut_positional, unmatched_kw)\u001b[39;00m\n\u001b[0;32m--> 104\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mcallback\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/wandb_init.py:419\u001b[0m, in \u001b[0;36m_WandbInit._pause_backend\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 417\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mbackend\u001b[38;5;241m.\u001b[39minterface \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 418\u001b[0m logger\u001b[38;5;241m.\u001b[39minfo(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mpausing backend\u001b[39m\u001b[38;5;124m\"\u001b[39m) \u001b[38;5;66;03m# type: ignore\u001b[39;00m\n\u001b[0;32m--> 419\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mbackend\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43minterface\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mpublish_pause\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/interface/interface.py:665\u001b[0m, in \u001b[0;36mInterfaceBase.publish_pause\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 663\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mpublish_pause\u001b[39m(\u001b[38;5;28mself\u001b[39m) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 664\u001b[0m pause \u001b[38;5;241m=\u001b[39m pb\u001b[38;5;241m.\u001b[39mPauseRequest()\n\u001b[0;32m--> 665\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_publish_pause\u001b[49m\u001b[43m(\u001b[49m\u001b[43mpause\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/interface/interface_shared.py:340\u001b[0m, in \u001b[0;36mInterfaceShared._publish_pause\u001b[0;34m(self, pause)\u001b[0m\n\u001b[1;32m 338\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_publish_pause\u001b[39m(\u001b[38;5;28mself\u001b[39m, pause: pb\u001b[38;5;241m.\u001b[39mPauseRequest) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 339\u001b[0m rec \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_make_request(pause\u001b[38;5;241m=\u001b[39mpause)\n\u001b[0;32m--> 340\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_publish\u001b[49m\u001b[43m(\u001b[49m\u001b[43mrec\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/interface/interface_sock.py:51\u001b[0m, in \u001b[0;36mInterfaceSock._publish\u001b[0;34m(self, record, local)\u001b[0m\n\u001b[1;32m 49\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_publish\u001b[39m(\u001b[38;5;28mself\u001b[39m, record: \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mpb.Record\u001b[39m\u001b[38;5;124m\"\u001b[39m, local: Optional[\u001b[38;5;28mbool\u001b[39m] \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 50\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_assign(record)\n\u001b[0;32m---> 51\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_sock_client\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msend_record_publish\u001b[49m\u001b[43m(\u001b[49m\u001b[43mrecord\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/lib/sock_client.py:221\u001b[0m, in \u001b[0;36mSockClient.send_record_publish\u001b[0;34m(self, record)\u001b[0m\n\u001b[1;32m 219\u001b[0m server_req \u001b[38;5;241m=\u001b[39m spb\u001b[38;5;241m.\u001b[39mServerRequest()\n\u001b[1;32m 220\u001b[0m server_req\u001b[38;5;241m.\u001b[39mrecord_publish\u001b[38;5;241m.\u001b[39mCopyFrom(record)\n\u001b[0;32m--> 221\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msend_server_request\u001b[49m\u001b[43m(\u001b[49m\u001b[43mserver_req\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/lib/sock_client.py:155\u001b[0m, in \u001b[0;36mSockClient.send_server_request\u001b[0;34m(self, msg)\u001b[0m\n\u001b[1;32m 154\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21msend_server_request\u001b[39m(\u001b[38;5;28mself\u001b[39m, msg: Any) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[0;32m--> 155\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_send_message\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmsg\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/lib/sock_client.py:152\u001b[0m, in \u001b[0;36mSockClient._send_message\u001b[0;34m(self, msg)\u001b[0m\n\u001b[1;32m 150\u001b[0m header \u001b[38;5;241m=\u001b[39m struct\u001b[38;5;241m.\u001b[39mpack(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m 152\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_sendall_with_error_handle\u001b[49m\u001b[43m(\u001b[49m\u001b[43mheader\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43m \u001b[49m\u001b[43mdata\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/usr/local/lib/python3.9/dist-packages/wandb/sdk/lib/sock_client.py:130\u001b[0m, in \u001b[0;36mSockClient._sendall_with_error_handle\u001b[0;34m(self, data)\u001b[0m\n\u001b[1;32m 128\u001b[0m start_time \u001b[38;5;241m=\u001b[39m time\u001b[38;5;241m.\u001b[39mmonotonic()\n\u001b[1;32m 129\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[0;32m--> 130\u001b[0m sent \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_sock\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msend\u001b[49m\u001b[43m(\u001b[49m\u001b[43mdata\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 131\u001b[0m \u001b[38;5;66;03m# sent equal to 0 indicates a closed socket\u001b[39;00m\n\u001b[1;32m 132\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m sent \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m0\u001b[39m:\n", "\u001b[0;31mBrokenPipeError\u001b[0m: [Errno 32] Broken pipe" ] } ], "source": [ "device = torch.device('cuda')\n", "backbone = models.efficientnet_v2_s(pretrained=True)\n", "model = SiameseNetwork(backbone, embedding_size=1000).to(device)\n", "model.load_state_dict(weights)\n", "\n", "#learner = Learner(model, dlt, dlv, config[\"lr\"], cbs, opt_func=optimizer)\n", "#learner.fit(config[\"epochs\"], train=False, valid=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "\n", "\n", "dsv = SiameseDataset(dirnames[\"valid_clean\"], n_samples=100, transform=transform_valid)\n", "dlvdel = DataLoader(dsv, 1, shuffle=True)\n", "\n", "for i in dlvdel:\n", " print(weights(i[0],i[1]))\n", " show_images(torch.cat((i[0], i[1])))\n", " break" ] }, { "cell_type": "markdown", "metadata": { "tags": [] }, "source": [ "### Visualize" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#|export\n", "@fc.delegates(plt.Axes.imshow)\n", "def show_image(im, ax=None, figsize=None, title=None, noframe=True, **kwargs):\n", " \"Show a PIL or PyTorch image on `ax`.\"\n", " if fc.hasattrs(im, ('cpu','permute','detach')):\n", " im = im.detach().cpu()\n", " if len(im.shape)==3 and im.shape[0]<5: im=im.permute(1,2,0)\n", " elif not isinstance(im,np.ndarray): im=np.array(im)\n", " if im.shape[-1]==1: im=im[...,0]\n", " if ax is None: _,ax = plt.subplots(figsize=figsize)\n", " ax.imshow(im, **kwargs, cmap='gray')\n", " if title is not None: ax.set_title(title, color=\"red\")\n", " ax.set_xticks([]) \n", " ax.set_yticks([]) \n", " if noframe: ax.axis('off')\n", "\n", " return ax\n", "\n", "@fc.delegates(plt.subplots, keep=True)\n", "def subplots(\n", " nrows:int=1, # Number of rows in returned axes grid\n", " ncols:int=1, # Number of columns in returned axes grid\n", " figsize:tuple=None, # Width, height in inches of the returned figure\n", " imsize:int=3, # Size (in inches) of images that will be displayed in the returned figure\n", " suptitle:str=None, # Title to be set to returned figure\n", " **kwargs\n", "): # fig and axs\n", " \"A figure and set of subplots to display images of `imsize` inches\"\n", " if figsize is None: figsize=(ncols*imsize, nrows*imsize)\n", " fig,ax = plt.subplots(nrows, ncols, figsize=figsize, **kwargs)\n", " if suptitle is not None: fig.suptitle(suptitle)\n", " if nrows*ncols==1: ax = np.array([ax])\n", "\n", " return fig,ax\n", "\n", "@fc.delegates(subplots)\n", "def get_grid(\n", " n:int, # Number of axes\n", " nrows:int=None, # Number of rows, defaulting to `int(math.sqrt(n))`\n", " ncols:int=None, # Number of columns, defaulting to `ceil(n/rows)`\n", " title:str=None, # If passed, title set to the figure\n", " weight:str='bold', # Title font weight\n", " size:int=14, # Title font size\n", " **kwargs,\n", "): # fig and axs\n", " \"Return a grid of `n` axes, `rows` by `cols`\"\n", " if nrows: ncols = ncols or int(np.floor(n/nrows))\n", " elif ncols: nrows = nrows or int(np.ceil(n/ncols))\n", " else:\n", " nrows = int(math.sqrt(n))\n", " ncols = int(np.floor(n/nrows))\n", " fig,axs = subplots(nrows, ncols, **kwargs)\n", " for i in range(n, nrows*ncols): axs.flat[i].set_axis_off()\n", " if title is not None: fig.suptitle(title, weight=weight, size=size)\n", " return fig,axs\n", "\n", "@fc.delegates(subplots)\n", "def show_images(ims:list, # Images to show\n", " nrows:int|None=None, # Number of rows in grid\n", " ncols:int|None=None, # Number of columns in grid (auto-calculated if None)\n", " titles:list|None=None, # Optional list of titles for each image\n", " **kwargs):\n", " \"Show all images `ims` as subplots with `rows` using `titles`\"\n", " axs = get_grid(len(ims), nrows, ncols, **kwargs)[1].flat\n", " for im,t,ax in zip_longest(ims, titles or [], axs): show_image(im, ax=ax, title=t)\n", "\n", "def reshape_alternating(tens1, tens2):\n", " new = torch.stack((tens1, tens2), dim=0)\n", " return torch.transpose(new,0,1).flatten(start_dim=0, end_dim=1)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "class SquarePad:\n", "\tdef __call__(self, image):\n", "\t\tw, h = image.size\n", "\t\tmax_wh = np.max([w, h])\n", "\t\thp = int((max_wh - w) / 2)\n", "\t\tvp = int((max_wh - h) / 2)\n", "\t\tpadding = (hp, vp, hp, vp)\n", "\t\treturn F.pad(image, padding, 0, 'constant')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "basePath = Path(\"/storage/projects/signature/signify\")\n", "dataPath = basePath / \"sigData\"/\"train\"\n", "\n", "import torchvision.transforms.functional as F\n", "\n", "class SquarePad:\n", " def __call__(self, image):\n", " image = image.squeeze()\n", " s = image.size()\n", " max_wh = np.min([s[-1], s[-2] * 2.9])\n", " hp = np.max(int((max_wh - s[-1]) / 2), 0)\n", " vp = np.max(int((max_wh - s[-2]) / 2), 0)\n", " padding = (0, vp, 0, vp)\n", " new_img = F.pad(image, padding, padding_mode='reflect')\n", " return new_img.unsqueeze(0)\n", "transform_valid = transforms.Compose([\n", " transforms.ToTensor(),\n", " transforms.Grayscale(num_output_channels=1),\n", " transforms.Resize((124, 124)),\n", " transforms.Normalize((0.8981),(0.1322))\n", "])\n", "transform_train = transforms.Compose([\n", " transforms.ToTensor(),\n", " transforms.Grayscale(num_output_channels=1),\n", " transforms.Resize((124, 124)),\n", " transforms.RandomAffine(0, (0.2, 0.2), (0.5, 0.8), [-15,15,-15,15], fill=1.),\n", " transforms.RandomErasing(scale=(0.02,0.25)),\n", " transforms.RandomApply(torch.nn.ModuleList([transforms.ColorJitter(brightness=(0.7,1.3),contrast=(0.7,1.3),saturation=(0.7,1.3), hue=(-0.1, 0.1))]), p=0.7),\n", " transforms.Normalize((0.8981),(0.1322))\n", "])\n", "\n", "\n", "train_data = SiameseDataset(dirnames[\"valid\"], n_samples=500, transform=transform_train)\n", "#val_data = SiameseDataset(path_valid, transform=transform)\n", "it = iter(DataLoader(train_data, 10, shuffle=True))\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "train_data = SiameseDataset(dirnames[\"valid\"], n_samples=500, transform=None)\n", "\n", "transform_train = transforms.Compose([\n", " transforms.ToTensor(),\n", " transforms.Grayscale(num_output_channels=1),\n", " transforms.RandomErasing(scale=(0.02,0.25)),\n", " transforms.RandomAffine(20, (0.2, 0.2), (1., 1.), [-15,15,-15,15], fill=1.),\n", " transforms.Resize((124, 124)),\n", " transforms.RandomApply(torch.nn.ModuleList([transforms.ColorJitter(brightness=(0.7,1.3),contrast=(0.7,1.3),saturation=(0.7,1.3), hue=(-0.1, 0.1))]), p=0.7),\n", "\n", " ])\n", "\n", "seed = torch.seed()\n", "\n", "x1_first = transform_train(train_data[0][0])\n", "torch.manual_seed(seed)\n", "\n", "x1_sec = transform_train(train_data[0][1])\n", "\n", "show_images(x1_first)\n", "show_images(x1_sec)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "x1, x2, label = next(it)\n", "\n", "shear1, shear2 = random.sample(range(-20,20),10), random.sample(range(-20,20),10)\n", "\n", "labels = torch.repeat_interleave(label, 2)\n", "images = reshape_alternating(x1, x2)\n", "\n", "show_images(images,ncols=2,titles=labels.tolist())" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "train_data = SiameseDataset(dirnames[\"valid\"], n_samples=500, transform=transform_train)\n", "#val_data = SiameseDataset(path_valid, transform=transform)\n", "it = iter(DataLoader(train_data, 10, shuffle=True))\n", "\n", "x1, x2, label = next(it)\n", "\n", "labels = torch.repeat_interleave(label, 2)\n", "images = reshape_alternating(x1, x2)\n", "\n", "show_images(images,ncols=2,titles=labels.tolist())" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#| hide\n", "import nbdev; nbdev.nbdev_export()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.11.3 ('siglit')", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.3" }, "vscode": { "interpreter": { "hash": "58fbb3b322f4fd165dbe2df418fd689197a633c5b2065049c07cf881fd363779" } } }, "nbformat": 4, "nbformat_minor": 4 }