Spaces:
Runtime error
Runtime error
File size: 46,657 Bytes
a1ece17 338bbe8 a1ece17 5fe67f2 a1ece17 d64050c 55abd01 338bbe8 c32023c 338bbe8 c32023c 55abd01 a1ece17 55abd01 338bbe8 c32023c 0bbec58 338bbe8 0bbec58 55abd01 338bbe8 55abd01 c32023c 55abd01 c32023c 338bbe8 c32023c 0bbec58 338bbe8 0bbec58 338bbe8 0bbec58 338bbe8 0bbec58 338bbe8 55abd01 338bbe8 55abd01 c32023c 338bbe8 c32023c 338bbe8 c32023c 55abd01 338bbe8 55abd01 338bbe8 8e35bc7 338bbe8 55abd01 338bbe8 55abd01 338bbe8 8e35bc7 55abd01 19d498a 55abd01 338bbe8 55abd01 5993d2f 056ab4f 55abd01 338bbe8 c32023c b85505a 338bbe8 b85505a 55abd01 5993d2f 55abd01 5993d2f 55abd01 338bbe8 55abd01 338bbe8 55abd01 338bbe8 55abd01 338bbe8 53075d2 c004d97 55abd01 c32023c 338bbe8 c32023c 338bbe8 c32023c 338bbe8 c32023c 338bbe8 c32023c 338bbe8 c32023c 338bbe8 c32023c 338bbe8 c32023c 338bbe8 c32023c 55abd01 0bbec58 53075d2 48f5984 0bbec58 48f5984 0bbec58 338bbe8 53075d2 0bbec58 8e35bc7 338bbe8 0bbec58 8e35bc7 0bbec58 c32023c a1ece17 48f5984 a1ece17 d64050c a1ece17 d64050c a1ece17 d64050c 5fe67f2 a1ece17 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import torch\n",
"from torch import nn\n",
"import torch.nn.functional as F\n",
"from datasets import load_dataset\n",
"import fastcore.all as fc\n",
"import matplotlib.pyplot as plt\n",
"import matplotlib as mpl\n",
"import torchvision.transforms.functional as TF\n",
"from torch.utils.data import default_collate, DataLoader\n",
"import torch.optim as optim\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"tags": [
"exclude"
]
},
"outputs": [],
"source": [
"%matplotlib inline\n",
"plt.rcParams['figure.figsize'] = [2, 2]"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"tags": [
"exclude"
]
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Found cached dataset mnist (/Users/arun/.cache/huggingface/datasets/mnist/mnist/1.0.0/9d494b7f466d6931c64fb39d58bb1249a4d85c9eb9865d9bc20960b999e2a332)\n",
"100%|██████████| 2/2 [00:00<00:00, 112.23it/s]\n"
]
}
],
"source": [
"dataset_nm = 'mnist'\n",
"x,y = 'image', 'label'\n",
"ds = load_dataset(dataset_nm)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"def transform_ds(b):\n",
" b[x] = [TF.to_tensor(ele) for ele in b[x]]\n",
" return b"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"tags": [
"exclude"
]
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAI4AAACOCAYAAADn/TAIAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAIsUlEQVR4nO3df2yU9R0H8PfHtrQroFJBVrGjHVRAweHWCASCJBuumiXOLAyYWTbjQiYy58Y2fmzZ5oILJgsJMjSRrCsmig7mAjFsZBIlLkNGdeBgrOWnWqnFwkDmUNrrZ3/0bPu59cfTz3P33NPr+5WQu89zd32+MW+/z/eeu+dzoqogGqgrsj0AGpwYHHJhcMiFwSEXBodcGBxyCRUcEakWkXoROSYiK9M1KIo/8Z7HEZE8AA0A5gNoBLAfwGJV/Wf6hkdxlR/itbcCOKaqJwBARJ4FcBeAXoMzTAq1CMND7JK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buVFaMTjkwuCQC4NDLgwOuTA45MLgkAuDQy4MDrkwOOTC4JBLpJ9Vich7AN4EMBqAv09IZnFs1nhVHZO6MdLgdO5UpK6nD87igGMLhocqcmFwyCVbwXkyS/sNgmMLICtrHBr8eKgil0iDIyLVIlIvIsdEJKvtbUWkRkTOiMihbtti0bt5MPSWjiw4IpIHYCOAOwDcCGBxsl9yttQCqE7ZFpfezfHvLa2qkfwDMAvArm71KgCrotp/L2MqB3CoW10PoDR5vxRAfTbH121c2wHMj9P4ojxUjQPwdre6MbktTmLXuzmuvaWjDE5PfQT5lq4P3t7SUYgyOI0AyrrV1wM4HeH+gwjUuzkKYXpLRyHK4OwHUCkiFSIyDMAidPRKjpOPezcDWezdHKC3NJDt3tIRL/LuBNAA4DiAH2d5wbkFHT9u0oqO2fA+ANeg493K0eRtSZbGNgcdh/E3ABxI/rszLuNTVZ45Jh+eOSYXBodcGBxyYXDIhcEhFwaHXBgccmFwyOV/atVD7hyCzrEAAAAASUVORK5CYII=",
"text/plain": [
"<Figure size 144x144 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"dst = ds.with_transform(transform_ds)\n",
"plt.imshow(dst['train'][0]['image'].permute(1,2,0));"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"bs = 1024\n",
"class DataLoaders:\n",
" def __init__(self, train_ds, valid_ds, bs, collate_fn, **kwargs):\n",
" self.train = DataLoader(train_ds, batch_size=bs, shuffle=True, collate_fn=collate_fn, **kwargs)\n",
" self.valid = DataLoader(valid_ds, batch_size=bs, shuffle=False, collate_fn=collate_fn, **kwargs)\n",
"\n",
"def collate_fn(b):\n",
" collate = default_collate(b)\n",
" return (collate[x], collate[y])"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"tags": [
"exclude"
]
},
"outputs": [
{
"data": {
"text/plain": [
"(torch.Size([1024, 1, 28, 28]), torch.Size([1024]))"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dls = DataLoaders(dst['train'], dst['test'], bs=bs, collate_fn=collate_fn)\n",
"xb,yb = next(iter(dls.train))\n",
"xb.shape, yb.shape"
]
},
{
"cell_type": "code",
"execution_count": 147,
"metadata": {},
"outputs": [],
"source": [
"class Reshape(nn.Module):\n",
" def __init__(self, dim):\n",
" super().__init__()\n",
" self.dim = dim\n",
" \n",
" def forward(self, x):\n",
" return x.reshape(self.dim)"
]
},
{
"cell_type": "code",
"execution_count": 148,
"metadata": {},
"outputs": [],
"source": [
"def conv(ni, nf, ks=3, s=2, act=nn.ReLU, norm=None):\n",
" layers = [nn.Conv2d(ni, nf, kernel_size=ks, stride=s, padding=ks//2)]\n",
" if norm:\n",
" layers.append(norm)\n",
" if act:\n",
" layers.append(act())\n",
" return nn.Sequential(*layers)\n",
"\n",
"def _conv_block(ni, nf, ks=3, s=2, act=nn.ReLU, norm=None):\n",
" return nn.Sequential(\n",
" conv(ni, nf, ks=ks, s=1, norm=norm, act=act),\n",
" conv(nf, nf, ks=ks, s=s, norm=norm, act=act),\n",
" )\n",
"\n",
"class ResBlock(nn.Module):\n",
" def __init__(self, ni, nf, s=2, ks=3, act=nn.ReLU, norm=None):\n",
" super().__init__()\n",
" self.convs = _conv_block(ni, nf, s=s, ks=ks, act=act, norm=norm)\n",
" self.idconv = fc.noop if ni==nf else conv(ni, nf, ks=1, s=1, act=None)\n",
" self.pool = fc.noop if s==1 else nn.AvgPool2d(2, ceil_mode=True)\n",
" self.act = act()\n",
" \n",
" def forward(self, x):\n",
" return self.act(self.convs(x) + self.idconv(self.pool(x)))"
]
},
{
"cell_type": "code",
"execution_count": 149,
"metadata": {},
"outputs": [],
"source": [
"# def cnn_classifier():\n",
"# return nn.Sequential(\n",
"# ResBlock(1, 8, norm=nn.BatchNorm2d(8)),\n",
"# ResBlock(8, 16, norm=nn.BatchNorm2d(16)),\n",
"# ResBlock(16, 32, norm=nn.BatchNorm2d(32)),\n",
"# ResBlock(32, 64, norm=nn.BatchNorm2d(64)),\n",
"# ResBlock(64, 64, norm=nn.BatchNorm2d(64)),\n",
"# conv(64, 10, act=False),\n",
"# nn.Flatten(),\n",
"# )\n",
"\n",
"def cnn_classifier():\n",
" return nn.Sequential(\n",
" ResBlock(1, 8,),\n",
" ResBlock(8, 16, ),\n",
" ResBlock(16, 32,),\n",
" ResBlock(32, 64, ),\n",
" ResBlock(64, 64,),\n",
" conv(64, 10, act=False),\n",
" nn.Flatten(),\n",
" )"
]
},
{
"cell_type": "code",
"execution_count": 150,
"metadata": {},
"outputs": [],
"source": [
"def kaiming_init(m):\n",
" if isinstance(m, (nn.Conv1d, nn.Conv2d, nn.Conv3d)):\n",
" nn.init.kaiming_normal_(m.weight) "
]
},
{
"cell_type": "code",
"execution_count": 151,
"metadata": {
"tags": [
"exclude"
]
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"train, epoch:1, loss: 1.3684, accuracy: 0.5153\n",
"eval, epoch:1, loss: 0.4238, accuracy: 0.8648\n",
"train, epoch:2, loss: 0.2660, accuracy: 0.9162\n",
"eval, epoch:2, loss: 0.1468, accuracy: 0.9552\n",
"train, epoch:3, loss: 0.1479, accuracy: 0.9545\n",
"eval, epoch:3, loss: 0.1101, accuracy: 0.9647\n",
"train, epoch:4, loss: 0.1149, accuracy: 0.9650\n",
"eval, epoch:4, loss: 0.0997, accuracy: 0.9705\n",
"train, epoch:5, loss: 0.2118, accuracy: 0.9399\n",
"eval, epoch:5, loss: 0.1625, accuracy: 0.9478\n"
]
}
],
"source": [
"model = cnn_classifier()\n",
"model.apply(kaiming_init)\n",
"lr = 0.1\n",
"max_lr = 0.3\n",
"epochs = 5\n",
"opt = optim.AdamW(model.parameters(), lr=lr)\n",
"sched = optim.lr_scheduler.OneCycleLR(opt, max_lr, total_steps=len(dls.train), epochs=epochs)\n",
"for epoch in range(epochs):\n",
" for train in (True, False):\n",
" accuracy = 0\n",
" total_loss = 0\n",
" dl = dls.train if train else dls.valid\n",
" for xb,yb in dl:\n",
" preds = model(xb)\n",
" loss = F.cross_entropy(preds, yb)\n",
" if train:\n",
" loss.backward()\n",
" opt.step()\n",
" opt.zero_grad()\n",
" with torch.no_grad():\n",
" accuracy += (preds.argmax(1).detach().cpu() == yb).float().mean()\n",
" total_loss += loss.item()\n",
" if train:\n",
" sched.step()\n",
" accuracy /= len(dl)\n",
" total_loss /= len(dl)\n",
" print(f\"{'train' if train else 'eval'}, epoch:{epoch+1}, loss: {total_loss:.4f}, accuracy: {accuracy:.4f}\")"
]
},
{
"cell_type": "code",
"execution_count": 152,
"metadata": {
"tags": [
"exclude"
]
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"eval, epoch:1, loss: 0.1625, accuracy: 0.9478\n",
"eval, epoch:2, loss: 0.1625, accuracy: 0.9478\n",
"eval, epoch:3, loss: 0.1625, accuracy: 0.9478\n",
"eval, epoch:4, loss: 0.1625, accuracy: 0.9478\n",
"eval, epoch:5, loss: 0.1625, accuracy: 0.9478\n"
]
}
],
"source": [
"for epoch in range(epochs):\n",
" train = False\n",
" accuracy = 0\n",
" total_loss = 0\n",
" dl = dls.valid\n",
" for xb,yb in dl:\n",
" preds = model(xb)\n",
" loss = F.cross_entropy(preds, yb)\n",
" with torch.no_grad():\n",
" accuracy += (preds.argmax(1).detach().cpu() == yb).float().mean()\n",
" total_loss += loss.item()\n",
" accuracy /= len(dl)\n",
" total_loss /= len(dl)\n",
" print(f\"{'train' if train else 'eval'}, epoch:{epoch+1}, loss: {total_loss:.4f}, accuracy: {accuracy:.4f}\")"
]
},
{
"cell_type": "code",
"execution_count": 153,
"metadata": {
"tags": [
"exclude"
]
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAj8AAAB+CAYAAADLN3DXAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMA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y88PERER+QobP0REROQropRK9DkQERERxQ17foiIiMhX2PghIiIiX2Hjh4iIiHyFjR8iIiLyFTZ+iIiIyFfY+CEiIiJf+X8m3SJfmhtA0wAAAABJRU5ErkJggg==",
"text/plain": [
"<Figure size 720x720 with 5 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"xbv,ybv = next(iter(dls.train))\n",
"logits = model(xbv)\n",
"probs = F.softmax(logits, dim=1)\n",
"idx = 5\n",
"_,axs = plt.subplots(1, idx, figsize=(10, 10))\n",
"for actual, pred, im, ax in zip(ybv[:idx], probs[:idx],xbv.permute(0,2,3,1)[:idx], axs.flat):\n",
" ax.imshow(im)\n",
" ax.set_axis_off()\n",
" ax.set_title(f'pred: {pred.argmax(0).item()}, actual:{actual.item()}')\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 158,
"metadata": {
"tags": [
"exclude"
]
},
"outputs": [],
"source": [
"torch.save(model.state_dict(), 'classifier.pth')"
]
},
{
"cell_type": "code",
"execution_count": 159,
"metadata": {},
"outputs": [],
"source": [
"loaded_model = cnn_classifier()\n",
"loaded_model.load_state_dict(torch.load('classifier.pth'));\n",
"loaded_model.eval();"
]
},
{
"cell_type": "code",
"execution_count": 160,
"metadata": {
"tags": [
"exclude"
]
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAj8AAAB+CAYAAADLN3DXAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAbn0lEQVR4nO3deZgU1dUG8PfMwLAj+y4gwiDiguICLoALEAEFiUYBURTihgtBjRENCp/RqEFAQZSI+xqIiEgMGo3ivqAIDmSGfd8d9m1m+n5/VFO3TjPdFE1PT0/X+3seHs+dU11VPXe6vF13KTHGgIiIiCgoMkr7BIiIiIiSiY0fIiIiChQ2foiIiChQ2P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sd+ManjhyzE3TeYk/Nsf1HL2NP+ixNTip+O0S5bGtbd3468v0gITQJvt4htAejvE5WnUn2aVCvplkH010Gc6M+pqW0GPnOM6n9IR27lTlBn0WufH47vbRT6OOz1LbXTzE1vsj9eN7FMy4mb1UucWK0lt2hnd+iIiIKFDY+CEiIqJAYbcXESVc8wd0N8elo88pdru1d7RX5T2No3c6tp6w0Y1Dq/VTpRGyq3ubglV+T5OIPLJm2+6siOfCY77n4ey90B7xaIHUeboC7/wQERFRoLDxQ0RERIHCxg8REREFCsf8EFHiGaOL+/cXu1mjJ/w/0TvIT10nosTinR8iIiIKFDZ+iIiIKFDY+CEiIqJAYeOHiIiIAoWNHyIiIgoUNn6IiIgoUNj4ISIiokBh44eIiIgChY0fIiIiChQxESuxEhEREaUz3vkhIiKiQGHjh4iIiAKFjR8iIiIKFDZ+iIiIKFDY+CEiIqJAYeOHiIiIAuX/AW21zFHP4lndAAAAAElFTkSuQmCC",
"text/plain": [
"<Figure size 720x720 with 5 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"with torch.no_grad():\n",
" xbv,ybv = next(iter(dls.train))\n",
" logits = loaded_model(xbv)\n",
" probs = F.softmax(logits, dim=1)\n",
" idx = 5\n",
" _,axs = plt.subplots(1, idx, figsize=(10, 10))\n",
" for actual, pred, im, ax in zip(ybv[:idx], probs[:idx],xbv.permute(0,2,3,1)[:idx], axs.flat):\n",
" ax.imshow(im)\n",
" ax.set_axis_off()\n",
" ax.set_title(f'pred: {pred.argmax(0).item()}, actual:{actual.item()}')\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 161,
"metadata": {
"tags": [
"exclude"
]
},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAj8AAAB+CAYAAADLN3DXAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWX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oLtqvtVvSucdTn0eBbvVpwxc/tKqQtd+suNz1hl8oCb1fXj10bqFzR5s1JPpuywczNcePac3VucrnL3Hj9zXPceESdeVH3d+Lbt6vyCVPtVOnCyI0p4QpXr3HjnZdUU7kzXr3GjUe1tdPge1bW11o1RV6vjODb5O3NVVl27y1+wyTgnR8iIiIKFDZ+iIiIKFDY+CEiIqJASYkxP0SRipYsd+ManjhyzE3TeYk/Nsf1HL2NP+ixNTip+O0S5bGtbd3468v0gITQJvt4htAejvE5WnUn2aVCvplkH010Gc6M+pqW0GPnOM6n9IR27lTlBn0WufH47vbRT6OOz1LbXTzE1vsj9eN7FMy4mb1UucWK0lt2hnd+iIiIKFDY+CEiIqJAYbcXESVc8wd0N8elo88pdru1d7RX5T2No3c6tp6w0Y1Dq/VTpRGyq3ubglV+T5OIPLJm2+6siOfCY77n4ey90B7xaIHUeboC7/wQERFRoLDxQ0RERIHCxg8REREFCsf8EFHiGaOL+/cXu1mjJ/w/0TvIT10nosTinR8iIiIKFDZ+iIiIKFDY+CEiIqJAYeOHiIiIAoWNHyIiIgoUNn6IiIgoUNj4ISIiokBh44eIiIgChY0fIiIiChQxESuxEhEREaUz3vkhIiKiQGHjh4iIiAKFjR8iIiIKFDZ+iIiIKFDY+CEiIqJAYeOHiIiIAuX/AW21zFHP4lndAAAAAElFTkSuQmCC",
"text/plain": [
"<Figure size 720x720 with 5 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"logits = model(xbv)\n",
"probs = F.softmax(logits, dim=1)\n",
"idx = 5\n",
"_,axs = plt.subplots(1, idx, figsize=(10, 10))\n",
"for actual, pred, im, ax in zip(ybv[:idx], probs[:idx],xbv.permute(0,2,3,1)[:idx], axs.flat):\n",
" ax.imshow(im)\n",
" ax.set_axis_off()\n",
" ax.set_title(f'pred: {pred.argmax(0).item()}, actual:{actual.item()}')\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 164,
"metadata": {},
"outputs": [],
"source": [
"def predict(img):\n",
" with torch.no_grad():\n",
" img = img[None,]\n",
" pred = loaded_model(img)[0]\n",
" pred_probs = F.softmax(pred, dim=0)\n",
" pred = [{\"digit\": i, \"prob\": f'{prob*100:.2f}%', 'logits': pred[i]} for i, prob in enumerate(pred_probs)]\n",
" pred = sorted(pred, key=lambda ele: ele['digit'], reverse=False)\n",
" return pred"
]
},
{
"cell_type": "code",
"execution_count": 167,
"metadata": {
"tags": [
"exclude"
]
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"tensor(4)\n"
]
},
{
"data": {
"text/plain": [
"[{'digit': 0, 'prob': '0.12%', 'logits': tensor(-1.1319)},\n",
" {'digit': 1, 'prob': '0.00%', 'logits': tensor(-4.7852)},\n",
" {'digit': 2, 'prob': '2.15%', 'logits': tensor(1.7912)},\n",
" {'digit': 3, 'prob': '0.07%', 'logits': tensor(-1.6584)},\n",
" {'digit': 4, 'prob': '97.03%', 'logits': tensor(5.5990)},\n",
" {'digit': 5, 'prob': '0.01%', 'logits': tensor(-3.5289)},\n",
" {'digit': 6, 'prob': '0.00%', 'logits': tensor(-4.4016)},\n",
" {'digit': 7, 'prob': '0.09%', 'logits': tensor(-1.3343)},\n",
" {'digit': 8, 'prob': '0.07%', 'logits': tensor(-1.6577)},\n",
" {'digit': 9, 'prob': '0.45%', 'logits': tensor(0.2194)}]"
]
},
"execution_count": 167,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"img = xb[1].reshape(1, 28, 28)\n",
"print(yb[1])\n",
"predict(img)"
]
},
{
"cell_type": "markdown",
"metadata": {
"tags": [
"exclude"
]
},
"source": [
"#### commit to .py file for deployment"
]
},
{
"cell_type": "code",
"execution_count": 168,
"metadata": {
"tags": [
"exclude"
]
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[NbConvertApp] Converting notebook mnist_classifier.ipynb to script\n",
"[NbConvertApp] Writing 3187 bytes to mnist_classifier.py\n"
]
}
],
"source": [
"!jupyter nbconvert --to script --TagRemovePreprocessor.remove_cell_tags=\"exclude\" --TemplateExporter.exclude_input_prompt=True mnist_classifier.ipynb\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "python_main",
"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.9.7"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
|