Spaces:
Running
Running
File size: 41,149 Bytes
f4ccc2a |
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 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 |
<!-- livebook:{"persist_outputs":true} -->
# Cleaned vs Dirty V2
```elixir
Mix.install(
[
{:stb_image, "~> 0.5.2"},
{:axon, "~> 0.5"},
{:polaris, "~> 0.1"},
{:exla, "~> 0.5"},
{:explorer, "~> 0.8.0"},
{:nx, "~> 0.5"},
{:kino_ripmd, github: "clm-a/kino_ripmd"},
{:kino_explorer, "~> 0.1.0"},
{:kino_vega_lite, "~> 0.1.0"},
{:kino, "~> 0.10.0"},
{:csv, "~> 3.2"}
],
config: [
nx: [
default_backend: EXLA.Backend,
default_defn_options: [compiler: EXLA]
],
exla: [
default_client: :cuda,
clients: [
cuda: [platform: :cuda],
rocm: [platform: :rocm],
tpu: [platform: :tpu],
host: [platform: :host]
],
memory_fraction: 0.9,
preallocate: false
]
],
system_env: [
XLA_TARGET: "cuda120"
]
)
```
## Goal
_Hi! It is boring to wash the dishes. Luckily, half of them are already clean. Train a classifier to determine clean ones to save time for the new machine learning course ;)_
_It is a few shot learning competition. We have a dataset of 20 clean and 20 dirty plates in train and hundreds of plates in test. Good luck!_
Igor.Slinko. (2019). Cleaned vs Dirty V2. Kaggle. https://kaggle.com/competitions/platesv2
## Setting up the model
```elixir
alias Axon.Loop.State
import Nx.Defn
directories =
"/home/le-moski/Documents/FEFU/7S/AI/lab1-dirtyplates/platesv2/plates/train/{cleaned,dirty}/*.jpg"
batch_size = 8
image_channels = 3
image_w = 256
image_h = 256
channel_value_max = 255
cleaned_class = Nx.tensor([1, 0], type: {:u, 8})
dirty_class = Nx.tensor([0, 1], type: {:u, 8})
```
<!-- livebook:{"output":true} -->
```
#Nx.Tensor<
u8[2]
EXLA.Backend<cuda:0, 0.463371035.4063887383.206028>
[0, 1]
>
```
```elixir
parse_img = fn filename ->
class =
if Path.dirname(filename)
|> String.split("/")
|> List.last() == "cleaned" do
cleaned_class
else
dirty_class
end
{:ok, img} = StbImage.read_file(filename)
img = StbImage.resize(img, image_h, image_w)
{StbImage.to_nx(img), class}
end
```
<!-- livebook:{"output":true} -->
```
#Function<42.39164016/1 in :erl_eval.expr/6>
```
```elixir
data =
Path.wildcard(directories)
|> Enum.shuffle()
|> Stream.chunk_every(batch_size, batch_size)
|> Task.async_stream(fn batch ->
{imgs, classes} = batch |> Enum.map(&parse_img.(&1)) |> Enum.unzip()
{Nx.stack(imgs), Nx.stack(classes)}
end)
|> Stream.map(fn {:ok, {imgs, classes}} -> {imgs |> Nx.divide(channel_value_max), classes} end)
```
<!-- livebook:{"output":true} -->
```
#Stream<[
enum: #Function<3.112894672/2 in Task.build_stream/3>,
funs: [#Function<50.38948127/1 in Stream.map/2>]
]>
```
```elixir
model =
Axon.input("input", shape: {nil, image_w, image_h, image_channels})
|> Axon.conv(64, kernel_size: {3, 3})
|> Axon.batch_norm()
|> Axon.relu()
|> Axon.max_pool(kernel_size: {2, 2})
|> Axon.conv(128, kernel_size: {3, 3})
|> Axon.batch_norm()
|> Axon.relu()
|> Axon.max_pool(kernel_size: {2, 2})
|> Axon.flatten()
|> Axon.dense(256, activation: :relu)
|> Axon.dropout()
|> Axon.dense(2, activation: :softmax)
```
<!-- livebook:{"output":true} -->
```
#Axon<
inputs: %{"input" => {nil, 256, 256, 3}}
outputs: "softmax_0"
nodes: 15
>
```
```elixir
optimizer = Polaris.Optimizers.adam(learning_rate: 1.0e-3)
centralized_optimizer = Polaris.Updates.compose(Polaris.Updates.centralize(), optimizer)
epochs = 4
model_state =
model
|> Axon.Loop.trainer(:binary_cross_entropy, centralized_optimizer, log: 1)
|> Axon.Loop.metric(:accuracy)
|> Axon.Loop.run(data, %{}, epochs: epochs, iterations: 30, compiler: EXLA)
```
<!-- livebook:{"output":true} -->
```
08:12:25.650 [debug] Forwarding options: [compiler: EXLA] to JIT compiler
08:12:37.790 [warning] Allocator (GPU_0_bfc) ran out of memory trying to allocate 480.50MiB (rounded to 503840768)requested by op
08:12:37.791 [info] BFCAllocator dump for GPU_0_bfc
08:12:37.791 [info] Bin (256): Total Chunks: 102, Chunks in use: 102. 25.5KiB allocated for chunks. 25.5KiB in use in bin. 11.5KiB client-requested in use in bin.
08:12:37.791 [info] Bin (512): Total Chunks: 20, Chunks in use: 20. 10.0KiB allocated for chunks. 10.0KiB in use in bin. 10.0KiB client-requested in use in bin.
08:12:37.792 [info] Bin (1024): Total Chunks: 4, Chunks in use: 4. 4.0KiB allocated for chunks. 4.0KiB in use in bin. 4.0KiB client-requested in use in bin.
08:12:37.792 [info] Bin (2048): Total Chunks: 16, Chunks in use: 16. 44.0KiB allocated for chunks. 44.0KiB in use in bin. 43.0KiB client-requested in use in bin.
08:12:37.793 [info] Bin (4096): Total Chunks: 4, Chunks in use: 4. 16.0KiB allocated for chunks. 16.0KiB in use in bin. 16.0KiB client-requested in use in bin.
08:12:37.793 [info] Bin (8192): Total Chunks: 0, Chunks in use: 0. 0B allocated for chunks. 0B in use in bin. 0B client-requested in use in bin.
08:12:37.795 [info] Bin (16384): Total Chunks: 0, Chunks in use: 0. 0B allocated for chunks. 0B in use in bin. 0B client-requested in use in bin.
08:12:37.795 [info] Bin (32768): Total Chunks: 0, Chunks in use: 0. 0B allocated for chunks. 0B in use in bin. 0B client-requested in use in bin.
08:12:37.796 [info] Bin (65536): Total Chunks: 8, Chunks in use: 8. 624.5KiB allocated for chunks. 624.5KiB in use in bin. 576.0KiB client-requested in use in bin.
08:12:37.797 [info] Bin (131072): Total Chunks: 8, Chunks in use: 8. 1.20MiB allocated for chunks. 1.20MiB in use in bin. 1.12MiB client-requested in use in bin.
08:12:37.797 [info] Bin (262144): Total Chunks: 4, Chunks in use: 4. 1.12MiB allocated for chunks. 1.12MiB in use in bin. 1.12MiB client-requested in use in bin.
08:12:37.797 [info] Bin (524288): Total Chunks: 2, Chunks in use: 0. 1.54MiB allocated for chunks. 0B in use in bin. 0B client-requested in use in bin.
08:12:37.798 [info] Bin (1048576): Total Chunks: 0, Chunks in use: 0. 0B allocated for chunks. 0B in use in bin. 0B client-requested in use in bin.
08:12:37.798 [info] Bin (2097152): Total Chunks: 4, Chunks in use: 1. 9.57MiB allocated for chunks. 2.50MiB in use in bin. 2.50MiB client-requested in use in bin.
08:12:37.798 [info] Bin (4194304): Total Chunks: 2, Chunks in use: 1. 11.25MiB allocated for chunks. 6.00MiB in use in bin. 6.00MiB client-requested in use in bin.
```
<!-- livebook:{"output":true} -->
```
08:12:37.798 [info] Bin (8388608): Total Chunks: 1, Chunks in use: 0. 10.49MiB allocated for chunks. 0B in use in bin. 0B client-requested in use in bin.
08:12:37.799 [info] Bin (16777216): Total Chunks: 0, Chunks in use: 0. 0B allocated for chunks. 0B in use in bin. 0B client-requested in use in bin.
08:12:37.799 [info] Bin (33554432): Total Chunks: 4, Chunks in use: 4. 133.00MiB allocated for chunks. 133.00MiB in use in bin. 133.00MiB client-requested in use in bin.
08:12:37.800 [info] Bin (67108864): Total Chunks: 0, Chunks in use: 0. 0B allocated for chunks. 0B in use in bin. 0B client-requested in use in bin.
08:12:37.800 [info] Bin (134217728): Total Chunks: 6, Chunks in use: 4. 994.80MiB allocated for chunks. 600.00MiB in use in bin. 600.00MiB client-requested in use in bin.
08:12:37.801 [info] Bin (268435456): Total Chunks: 2, Chunks in use: 0. 629.22MiB allocated for chunks. 0B in use in bin. 0B client-requested in use in bin.
08:12:37.801 [info] Bin for 480.50MiB was 256.00MiB, Chunk State:
08:12:37.801 [info] Size: 295.97MiB | Requested Size: 153.12MiB | in_use: 0 | bin_num: 20, prev: Size: 223.5KiB | Requested Size: 144.0KiB | in_use: 1 | bin_num: -1, next: Size: 144.0KiB | Requested Size: 144.0KiB | in_use: 1 | bin_num: -1
08:12:37.803 [info] Size: 333.25MiB | Requested Size: 153.12MiB | in_use: 0 | bin_num: 20, prev: Size: 33.25MiB | Requested Size: 33.25MiB | in_use: 1 | bin_num: -1
08:12:37.804 [info] Next region of size 1880004864
08:12:37.804 [info] Free at 736310000000 of size 2575616 next 65
08:12:37.806 [info] InUse at 736310274d00 of size 256 next 1947
08:12:37.806 [info] InUse at 736310274e00 of size 73728 next 438
08:12:37.807 [info] InUse at 736310286e00 of size 73728 next 1507
08:12:37.807 [info] InUse at 736310298e00 of size 115712 next 1943
08:12:37.807 [info] InUse at 7363102b5200 of size 256 next 420
08:12:37.808 [info] Free at 7363102b5300 of size 786688 next 238
08:12:37.808 [info] InUse at 736310375400 of size 256 next 259
08:12:37.809 [info] Free at 736310375500 of size 10996736 next 3677
08:12:37.809 [info] InUse at 736310df2100 of size 2618880 next 1580
08:12:37.810 [info] Free at 736311071700 of size 2671872 next 291
08:12:37.810 [info] InUse at 7363112fdc00 of size 147456 next 1912
08:12:37.810 [info] InUse at 736311321c00 of size 147456 next 386
08:12:37.811 [info] InUse at 736311345c00 of size 148736 next 39
08:12:37.811 [info] Free at 73631136a100 of size 5500672 next 1277
08:12:37.811 [info] InUse at 7363118a9000 of size 294912 next 3916
08:12:37.811 [info] InUse at 7363118f1000 of size 294912 next 3549
08:12:37.812 [info] InUse at 736311939000 of size 294912 next 1748
08:12:37.812 [info] InUse at 736311981000 of size 294912 next 1904
08:12:37.812 [info] InUse at 7363119c9000 of size 73728 next 1575
08:12:37.812 [info] InUse at 7363119db000 of size 3584 next 1797
08:12:37.812 [info] InUse at 7363119dbe00 of size 3584 next 1919
08:12:37.813 [info] InUse at 7363119dcc00 of size 3584 next 230
08:12:37.813 [info] InUse at 7363119dda00 of size 3584 next 1730
08:12:37.813 [info] InUse at 7363119de800 of size 2048 next 1774
08:12:37.813 [info] InUse at 7363119df000 of size 2048 next 1639
08:12:37.813 [info] InUse at 7363119df800 of size 2048 next 1728
08:12:37.814 [info] InUse at 7363119e0000 of size 2048 next 1531
08:12:37.814 [info] InUse at 7363119e0800 of size 1024 next 1504
08:12:37.814 [info] InUse at 7363119e0c00 of size 1024 next 1498
08:12:37.815 [info] InUse at 7363119e1000 of size 1024 next 1636
08:12:37.815 [info] InUse at 7363119e1400 of size 1024 next 1742
08:12:37.815 [info] InUse at 7363119e1800 of size 512 next 1855
08:12:37.815 [info] InUse at 7363119e1a00 of size 512 next 2919
08:12:37.816 [info] InUse at 7363119e1c00 of size 512 next 342
08:12:37.816 [info] InUse at 7363119e1e00 of size 512 next 1903
08:12:37.816 [info] InUse at 7363119e2000 of size 512 next 3877
08:12:37.816 [info] InUse at 7363119e2200 of size 512 next 1808
08:12:37.816 [info] InUse at 7363119e2400 of size 512 next 1749
08:12:37.817 [info] InUse at 7363119e2600 of size 512 next 3830
08:12:37.817 [info] InUse at 7363119e2800 of size 512 next 1832
08:12:37.817 [info] InUse at 7363119e2a00 of size 512 next 1656
08:12:37.817 [info] InUse at 7363119e2c00 of size 512 next 1491
08:12:37.817 [info] InUse at 7363119e2e00 of size 512 next 3251
08:12:37.818 [info] InUse at 7363119e3000 of size 512 next 3922
08:12:37.818 [info] InUse at 7363119e3200 of size 512 next 3914
08:12:37.818 [info] InUse at 7363119e3400 of size 512 next 3755
08:12:37.818 [info] InUse at 7363119e3600 of size 512 next 1768
08:12:37.818 [info] InUse at 7363119e3800 of size 512 next 1488
08:12:37.819 [info] InUse at 7363119e3a00 of size 512 next 1831
08:12:37.819 [info] InUse at 7363119e3c00 of size 512 next 1689
08:12:37.819 [info] InUse at 7363119e3e00 of size 512 next 1846
08:12:37.819 [info] InUse at 7363119e4000 of size 256 next 1861
08:12:37.821 [info] InUse at 7363119e4100 of size 256 next 1708
08:12:37.821 [info] InUse at 7363119e4200 of size 256 next 3907
08:12:37.821 [info] InUse at 7363119e4300 of size 256 next 1828
08:12:37.822 [info] InUse at 7363119e4400 of size 256 next 1892
08:12:37.822 [info] InUse at 7363119e4500 of size 256 next 1759
08:12:37.822 [info] InUse at 7363119e4600 of size 256 next 310
08:12:37.822 [info] InUse at 7363119e4700 of size 256 next 1670
08:12:37.823 [info] InUse at 7363119e4800 of size 256 next 1758
08:12:37.823 [info] InUse at 7363119e4900 of size 256 next 3781
08:12:37.823 [info] InUse at 7363119e4a00 of size 256 next 1851
08:12:37.823 [info] InUse at 7363119e4b00 of size 256 next 1741
08:12:37.823 [info] InUse at 7363119e4c00 of size 256 next 1674
08:12:37.823 [info] InUse at 7363119e4d00 of size 256 next 274
08:12:37.824 [info] InUse at 7363119e4e00 of size 256 next 1666
08:12:37.824 [info] InUse at 7363119e4f00 of size 256 next 1879
08:12:37.824 [info] InUse at 7363119e5000 of size 256 next 1744
08:12:37.824 [info] InUse at 7363119e5100 of size 256 next 72
08:12:37.824 [info] InUse at 7363119e5200 of size 256 next 1755
08:12:37.824 [info] InUse at 7363119e5300 of size 256 next 426
08:12:37.825 [info] InUse at 7363119e5400 of size 256 next 1702
08:12:37.825 [info] InUse at 7363119e5500 of size 256 next 1785
08:12:37.825 [info] InUse at 7363119e5600 of size 256 next 1553
08:12:37.825 [info] InUse at 7363119e5700 of size 256 next 1517
08:12:37.825 [info] InUse at 7363119e5800 of size 256 next 1733
08:12:37.825 [info] InUse at 7363119e5900 of size 256 next 3883
08:12:37.825 [info] InUse at 7363119e5a00 of size 256 next 146
08:12:37.826 [info] InUse at 7363119e5b00 of size 256 next 1726
08:12:37.826 [info] InUse at 7363119e5c00 of size 256 next 1678
08:12:37.826 [info] InUse at 7363119e5d00 of size 256 next 3708
08:12:37.826 [info] InUse at 7363119e5e00 of size 256 next 1539
08:12:37.826 [info] InUse at 7363119e5f00 of size 256 next 1684
08:12:37.826 [info] InUse at 7363119e6000 of size 256 next 1751
08:12:37.827 [info] InUse at 7363119e6100 of size 256 next 1552
08:12:37.827 [info] InUse at 7363119e6200 of size 256 next 1736
08:12:37.827 [info] InUse at 7363119e6300 of size 256 next 1543
08:12:37.827 [info] InUse at 7363119e6400 of size 256 next 1723
08:12:37.827 [info] InUse at 7363119e6500 of size 256 next 325
08:12:37.827 [info] InUse at 7363119e6600 of size 256 next 1880
08:12:37.827 [info] InUse at 7363119e6700 of size 256 next 1685
08:12:37.827 [info] InUse at 7363119e6800 of size 256 next 200
08:12:37.827 [info] InUse at 7363119e6900 of size 256 next 1900
08:12:37.828 [info] InUse at 7363119e6a00 of size 256 next 1677
08:12:37.828 [info] InUse at 7363119e6b00 of size 256 next 8
08:12:37.828 [info] InUse at 7363119e6c00 of size 256 next 1767
08:12:37.828 [info] InUse at 7363119e6d00 of size 256 next 1794
08:12:37.828 [info] InUse at 7363119e6e00 of size 256 next 1790
08:12:37.828 [info] InUse at 7363119e6f00 of size 256 next 1776
08:12:37.828 [info] InUse at 7363119e7000 of size 256 next 1579
08:12:37.828 [info] InUse at 7363119e7100 of size 256 next 1550
08:12:37.829 [info] InUse at 7363119e7200 of size 256 next 1698
08:12:37.829 [info] InUse at 7363119e7300 of size 256 next 1683
08:12:37.829 [info] InUse at 7363119e7400 of size 256 next 1839
08:12:37.829 [info] InUse at 7363119e7500 of size 256 next 1556
08:12:37.829 [info] InUse at 7363119e7600 of size 256 next 56
08:12:37.830 [info] InUse at 7363119e7700 of size 256 next 1893
08:12:37.830 [info] InUse at 7363119e7800 of size 256 next 3837
08:12:37.830 [info] Free at 7363119e7900 of size 2173440 next 2023
08:12:37.830 [info] InUse at 736311bfa300 of size 147456 next 3854
08:12:37.831 [info] InUse at 736311c1e300 of size 147456 next 3887
08:12:37.831 [info] InUse at 736311c42300 of size 228864 next 3908
08:12:37.831 [info] Free at 736311c7a100 of size 310345216 next 347
08:12:37.832 [info] InUse at 736324471f00 of size 147456 next 199
08:12:37.832 [info] InUse at 736324495f00 of size 147456 next 447
08:12:37.832 [info] InUse at 7363244b9f00 of size 73728 next 3843
08:12:37.833 [info] InUse at 7363244cbf00 of size 73728 next 7
08:12:37.833 [info] InUse at 7363244ddf00 of size 81408 next 256
08:12:37.833 [info] InUse at 7363244f1d00 of size 256 next 1657
08:12:37.833 [info] InUse at 7363244f1e00 of size 256 next 233
08:12:37.833 [info] Free at 7363244f1f00 of size 832512 next 3910
08:12:37.834 [info] InUse at 7363245bd300 of size 73728 next 257
08:12:37.834 [info] InUse at 7363245cf300 of size 4096 next 3790
08:12:37.834 [info] InUse at 7363245d0300 of size 4096 next 128
08:12:37.834 [info] InUse at 7363245d1300 of size 4096 next 335
08:12:37.834 [info] InUse at 7363245d2300 of size 4096 next 1908
08:12:37.834 [info] InUse at 7363245d3300 of size 3584 next 116
08:12:37.834 [info] InUse at 7363245d4100 of size 3584 next 410
08:12:37.834 [info] InUse at 7363245d4f00 of size 3584 next 307
08:12:37.834 [info] InUse at 7363245d5d00 of size 3584 next 139
08:12:37.835 [info] InUse at 7363245d6b00 of size 2048 next 1817
08:12:37.835 [info] InUse at 7363245d7300 of size 2048 next 1917
08:12:37.835 [info] InUse at 7363245d7b00 of size 2048 next 297
08:12:37.835 [info] InUse at 7363245d8300 of size 2048 next 1791
08:12:37.835 [info] InUse at 7363245d8b00 of size 256 next 1801
08:12:37.835 [info] InUse at 7363245d8c00 of size 256 next 348
08:12:37.835 [info] InUse at 7363245d8d00 of size 256 next 3741
08:12:37.835 [info] InUse at 7363245d8e00 of size 256 next 264
08:12:37.835 [info] InUse at 7363245d8f00 of size 256 next 324
08:12:37.835 [info] InUse at 7363245d9000 of size 256 next 1806
08:12:37.836 [info] InUse at 7363245d9100 of size 256 next 3713
08:12:37.836 [info] InUse at 7363245d9200 of size 256 next 117
08:12:37.836 [info] InUse at 7363245d9300 of size 256 next 1859
08:12:37.836 [info] InUse at 7363245d9400 of size 256 next 3745
08:12:37.836 [info] InUse at 7363245d9500 of size 256 next 20
08:12:37.836 [info] InUse at 7363245d9600 of size 256 next 3702
08:12:37.837 [info] InUse at 7363245d9700 of size 256 next 3879
08:12:37.837 [info] InUse at 7363245d9800 of size 256 next 226
08:12:37.837 [info] InUse at 7363245d9900 of size 256 next 1910
08:12:37.837 [info] InUse at 7363245d9a00 of size 256 next 237
08:12:37.837 [info] InUse at 7363245d9b00 of size 256 next 229
08:12:37.837 [info] InUse at 7363245d9c00 of size 256 next 136
08:12:37.837 [info] InUse at 7363245d9d00 of size 256 next 448
08:12:37.837 [info] InUse at 7363245d9e00 of size 256 next 286
08:12:37.837 [info] InUse at 7363245d9f00 of size 256 next 213
08:12:37.837 [info] InUse at 7363245da000 of size 256 next 37
08:12:37.837 [info] InUse at 7363245da100 of size 256 next 346
08:12:37.838 [info] InUse at 7363245da200 of size 256 next 165
08:12:37.838 [info] InUse at 7363245da300 of size 256 next 318
08:12:37.838 [info] InUse at 7363245da400 of size 256 next 372
08:12:37.838 [info] InUse at 7363245da500 of size 256 next 443
08:12:37.838 [info] InUse at 7363245da600 of size 256 next 193
08:12:37.838 [info] InUse at 7363245da700 of size 256 next 127
08:12:37.838 [info] InUse at 7363245da800 of size 256 next 43
08:12:37.838 [info] InUse at 7363245da900 of size 256 next 550
08:12:37.838 [info] InUse at 7363245daa00 of size 256 next 376
08:12:37.838 [info] InUse at 7363245dab00 of size 256 next 467
08:12:37.839 [info] InUse at 7363245dac00 of size 256 next 47
08:12:37.839 [info] InUse at 7363245dad00 of size 256 next 207
08:12:37.839 [info] InUse at 7363245dae00 of size 256 next 540
08:12:37.839 [info] InUse at 7363245daf00 of size 256 next 408
08:12:37.839 [info] InUse at 7363245db000 of size 256 next 279
08:12:37.839 [info] InUse at 7363245db100 of size 256 next 76
08:12:37.839 [info] InUse at 7363245db200 of size 256 next 532
08:12:37.839 [info] InUse at 7363245db300 of size 6291456 next 2880
08:12:37.840 [info] Free at 736324bdb300 of size 150994944 next 151
08:12:37.840 [info] InUse at 73632dbdb300 of size 157286400 next 1816
08:12:37.840 [info] InUse at 7363371db300 of size 157286400 next 1783
08:12:37.840 [info] InUse at 7363407db300 of size 157286400 next 3758
08:12:37.840 [info] InUse at 736349ddb300 of size 157286400 next 1731
08:12:37.840 [info] Free at 7363533db300 of size 262984704 next 48
08:12:37.840 [info] InUse at 736362ea8700 of size 34865152 next 319
08:12:37.840 [info] InUse at 736364fe8700 of size 34865152 next 321
08:12:37.840 [info] InUse at 736367128700 of size 34865152 next 221
08:12:37.840 [info] InUse at 736369268700 of size 34865152 next 419
08:12:37.840 [info] Free at 73636b3a8700 of size 349442560 next 18446744073709551615
08:12:37.840 [info] Summary of in-use Chunks by size:
08:12:37.841 [info] 102 Chunks of size 256 totalling 25.5KiB
08:12:37.841 [info] 20 Chunks of size 512 totalling 10.0KiB
08:12:37.841 [info] 4 Chunks of size 1024 totalling 4.0KiB
08:12:37.841 [info] 8 Chunks of size 2048 totalling 16.0KiB
08:12:37.841 [info] 8 Chunks of size 3584 totalling 28.0KiB
08:12:37.841 [info] 4 Chunks of size 4096 totalling 16.0KiB
08:12:37.841 [info] 6 Chunks of size 73728 totalling 432.0KiB
08:12:37.841 [info] 1 Chunks of size 81408 totalling 79.5KiB
08:12:37.842 [info] 1 Chunks of size 115712 totalling 113.0KiB
08:12:37.842 [info] 6 Chunks of size 147456 totalling 864.0KiB
08:12:37.842 [info] 1 Chunks of size 148736 totalling 145.2KiB
08:12:37.842 [info] 1 Chunks of size 228864 totalling 223.5KiB
08:12:37.842 [info] 4 Chunks of size 294912 totalling 1.12MiB
08:12:37.842 [info] 1 Chunks of size 2618880 totalling 2.50MiB
08:12:37.842 [info] 1 Chunks of size 6291456 totalling 6.00MiB
08:12:37.842 [info] 4 Chunks of size 34865152 totalling 133.00MiB
08:12:37.842 [info] 4 Chunks of size 157286400 totalling 600.00MiB
08:12:37.842 [info] Sum Total of in-use chunks: 744.53MiB
08:12:37.843 [info] Total bytes in pool: 1880004864 memory_limit_: 1880005017 available bytes: 153 curr_region_allocation_bytes_: 3760010240
08:12:37.843 [info] Stats:
Limit: 1880005017
InUse: 780699904
MaxInUse: 1871703296
NumAllocs: 97350
MaxAllocSize: 1152347648
Reserved: 0
PeakReserved: 0
LargestFreeBlock: 0
08:12:37.843 [warning] **________________*_______***********************************____________*********__________________
08:12:37.843 [error] Execution of replica 0 failed: RESOURCE_EXHAUSTED: Out of memory while trying to allocate 503840768 bytes.
BufferAssignment OOM Debugging.
BufferAssignment stats:
parameter allocation: 0B
constant allocation: 273B
maybe_live_out allocation: 1.88GiB
preallocated temp allocation: 7.5KiB
preallocated temp fragmentation: 1.2KiB (16.09%)
total allocation: 1.88GiB
total fragmentation: 7.8KiB (0.00%)
Peak buffers:
Buffer 1:
Size: 480.50MiB
XLA Label: fusion
Shape: f32[492032,256]
==========================
Buffer 2:
Size: 480.50MiB
XLA Label: fusion
Shape: f32[492032,256]
==========================
Buffer 3:
Size: 480.50MiB
XLA Label: fusion
Shape: f32[125960192]
==========================
Buffer 4:
Size: 480.50MiB
XLA Label: fusion
Shape: f32[492032,256]
==========================
Buffer 5:
Size: 288.0KiB
XLA Label: fusion
Shape: f32[3,3,64,128]
==========================
Buffer 6:
Size: 288.0KiB
XLA Label: fusion
Shape: f32[3,3,64,128]
==========================
Buffer 7:
Size: 288.0KiB
XLA Label: fusion
Shape: f32[73728]
==========================
Buffer 8:
Size: 288.0KiB
XLA Label: fusion
Shape: f32[3,3,64,128]
==========================
Buffer 9:
Size: 6.8KiB
XLA Label: fusion
Shape: f32[3,3,3,64]
==========================
Buffer 10:
Size: 6.8KiB
XLA Label: fusion
Shape: f32[3,3,3,64]
==========================
Buffer 11:
Size: 6.8KiB
XLA Label: fusion
Shape: f32[1728]
==========================
Buffer 12:
Size: 6.8KiB
XLA Label: fusion
Shape: f32[3,3,3,64]
==========================
Buffer 13:
Size: 2.0KiB
XLA Label: fusion
Shape: f32[256,2]
==========================
Buffer 14:
Size: 2.0KiB
XLA Label: fusion
Shape: f32[512]
==========================
Buffer 15:
Size: 2.0KiB
XLA Label: fusion
Shape: f32[256,2]
==========================
```
## Testing
```elixir
test_directory = "/home/le-moski/Documents/FEFU/7S/AI/lab1-dirtyplates/platesv2/plates/test/*.jpg"
test_filenames =
Path.wildcard(test_directory)
|> Stream.chunk_every(batch_size, batch_size)
test_data_raw =
test_filenames
|> Task.async_stream(fn batch ->
batch
|> Enum.map(fn filename ->
{:ok, img} = StbImage.read_file(filename, channels: image_channels)
StbImage.resize(img, image_h, image_w) |> StbImage.to_nx()
end)
|> Nx.stack()
end)
test_data =
test_data_raw
|> Stream.map(fn {:ok, batch} -> batch |> Nx.divide(channel_value_max) end)
```
<!-- livebook:{"output":true} -->
```
#Stream<[
enum: #Function<3.112894672/2 in Task.build_stream/3>,
funs: [#Function<50.38948127/1 in Stream.map/2>]
]>
```
```elixir
predictions =
test_data
|> Stream.map(fn batch ->
Axon.predict(model, model_state, batch)
end)
prediction_labels =
predictions
|> Stream.map(fn batch ->
batch
|> Nx.to_list()
|> Enum.map(
&if &1 |> Enum.at(0) >= &1 |> Enum.at(1) do
"Cleaned"
else
"Dirty"
end
)
end)
```
<!-- livebook:{"output":true} -->
```
#Stream<[
enum: #Function<3.112894672/2 in Task.build_stream/3>,
funs: [#Function<50.38948127/1 in Stream.map/2>, #Function<50.38948127/1 in Stream.map/2>,
#Function<50.38948127/1 in Stream.map/2>]
]>
```
```elixir
predictions |> Enum.to_list()
```
<!-- livebook:{"output":true} -->
```
[
#Nx.Tensor<
f32[20][2]
EXLA.Backend<cuda:0, 0.691480651.217186328.98827>
[
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN]
]
>,
#Nx.Tensor<
f32[20][2]
EXLA.Backend<cuda:0, 0.691480651.217186328.98830>
[
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN]
]
>,
#Nx.Tensor<
f32[20][2]
EXLA.Backend<cuda:0, 0.691480651.217186328.98833>
[
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN]
]
>,
#Nx.Tensor<
f32[20][2]
EXLA.Backend<cuda:0, 0.691480651.217186328.98836>
[
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN]
]
>,
#Nx.Tensor<
f32[20][2]
EXLA.Backend<cuda:0, 0.691480651.217186325.94801>
[
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN]
]
>,
#Nx.Tensor<
f32[20][2]
EXLA.Backend<cuda:0, 0.691480651.217186325.94804>
[
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN]
]
>,
#Nx.Tensor<
f32[20][2]
EXLA.Backend<cuda:0, 0.691480651.217186325.94807>
[
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN]
]
>,
#Nx.Tensor<
f32[20][2]
EXLA.Backend<cuda:0, 0.691480651.217186325.94810>
[
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN]
]
>,
#Nx.Tensor<
f32[20][2]
EXLA.Backend<cuda:0, 0.691480651.217186325.94813>
[
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN]
]
>,
#Nx.Tensor<
f32[20][2]
EXLA.Backend<cuda:0, 0.691480651.217186328.98846>
[
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN]
]
>,
#Nx.Tensor<
f32[20][2]
EXLA.Backend<cuda:0, 0.691480651.217186321.95355>
[
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, ...]
]
>,
#Nx.Tensor<
f32[20][2]
EXLA.Backend<cuda:0, 0.691480651.217186321.95357>
[
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
...
]
>,
#Nx.Tensor<
f32[20][2]
EXLA.Backend<cuda:0, 0.691480651.217186322.99151>
[
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, ...],
...
]
>,
#Nx.Tensor<
f32[20][2]
EXLA.Backend<cuda:0, 0.691480651.217186328.98858>
[
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
...
]
>,
#Nx.Tensor<
f32[20][2]
EXLA.Backend<cuda:0, 0.691480651.217186325.94881>
[
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, ...],
...
]
>,
#Nx.Tensor<
f32[20][2]
EXLA.Backend<cuda:0, 0.691480651.217186328.98903>
[
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
...
]
>,
#Nx.Tensor<
f32[20][2]
EXLA.Backend<cuda:0, 0.691480651.217186326.102539>
[
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, ...],
...
]
>,
#Nx.Tensor<
f32[20][2]
EXLA.Backend<cuda:0, 0.691480651.217186328.98921>
[
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
...
]
>,
#Nx.Tensor<
f32[20][2]
EXLA.Backend<cuda:0, 0.691480651.217186329.96026>
[
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, ...],
...
]
>,
#Nx.Tensor<
f32[20][2]
EXLA.Backend<cuda:0, 0.691480651.217186325.94929>
[
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
...
]
>,
#Nx.Tensor<
f32[20][2]
EXLA.Backend<cuda:0, 0.691480651.217186326.102571>
[
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, ...],
...
]
>,
#Nx.Tensor<
f32[20][2]
EXLA.Backend<cuda:0, 0.691480651.217186330.95297>
[
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
...
]
>,
#Nx.Tensor<
f32[20][2]
EXLA.Backend<cuda:0, 0.691480651.217186321.95421>
[
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, ...],
...
]
>,
#Nx.Tensor<
f32[20][2]
EXLA.Backend<cuda:0, 0.691480651.217186321.95441>
[
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
...
]
>,
#Nx.Tensor<
f32[20][2]
EXLA.Backend<cuda:0, 0.691480651.217186326.102666>
[
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, ...],
...
]
>,
#Nx.Tensor<
f32[20][2]
EXLA.Backend<cuda:0, 0.691480651.217186326.102702>
[
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
...
]
>,
#Nx.Tensor<
f32[20][2]
EXLA.Backend<cuda:0, 0.691480651.217186329.96108>
[
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, ...],
...
]
>,
#Nx.Tensor<
f32[20][2]
EXLA.Backend<cuda:0, 0.691480651.217186329.96120>
[
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
...
]
>,
#Nx.Tensor<
f32[20][2]
EXLA.Backend<cuda:0, 0.691480651.217186329.96125>
[
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, ...],
...
]
>,
#Nx.Tensor<
f32[20][2]
EXLA.Backend<cuda:0, 0.691480651.217186321.95471>
[
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
...
]
>,
#Nx.Tensor<
f32[20][2]
EXLA.Backend<cuda:0, 0.691480651.217186326.102744>
[
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, ...],
...
]
>,
#Nx.Tensor<
f32[20][2]
EXLA.Backend<cuda:0, 0.691480651.217186328.99042>
[
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
...
]
>,
#Nx.Tensor<
f32[20][2]
EXLA.Backend<cuda:0, 0.691480651.217186330.95355>
[
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, ...],
...
]
>,
#Nx.Tensor<
f32[20][2]
EXLA.Backend<cuda:0, 0.691480651.217186330.95367>
[
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
...
]
>,
#Nx.Tensor<
f32[20][2]
EXLA.Backend<cuda:0, 0.691480651.217186325.95024>
[
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, ...],
...
]
>,
#Nx.Tensor<
f32[20][2]
EXLA.Backend<cuda:0, 0.691480651.217186330.95386>
[
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
...
]
>,
#Nx.Tensor<
f32[20][2]
EXLA.Backend<cuda:0, 0.691480651.217186330.95409>
[
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, ...],
...
]
>,
#Nx.Tensor<
f32[4][2]
EXLA.Backend<cuda:0, 0.691480651.217186330.95412>
[
[NaN, NaN],
[NaN, NaN],
[NaN, NaN],
[NaN, NaN]
]
>
]
```
```elixir
results = Stream.zip([test_filenames, test_data_raw, prediction_labels])
```
<!-- livebook:{"output":true} -->
```
#Function<76.38948127/2 in Stream.zip_with/2>
```
```elixir
csv =
results
|> Stream.flat_map(fn batch ->
{filenames_batch, _, labels_batch} = batch
Enum.zip([filenames_batch, labels_batch])
|> Enum.map(fn {filename, label} ->
%{id: Path.basename(filename, ".jpg"), label: String.downcase(label)}
end)
end)
|> CSV.encode(headers: [:id, :label])
|> Enum.join()
File.write!("/home/le-moski/Documents/FEFU/7S/AI/lab1-dirtyplates/results.csv", csv)
```
<!-- livebook:{"output":true} -->
```
:ok
```
```elixir
visualization =
results
|> Stream.map(fn batch ->
{filenames_batch, {:ok, raw_batch}, labels_batch} = batch
filenames_batch
|> Stream.with_index(fn filename, index ->
Kino.Layout.grid(
[
Kino.Markdown.new("# " <> Path.basename(filename)),
raw_batch |> Nx.to_list() |> Enum.at(index) |> Nx.tensor(type: :u8) |> Kino.Image.new(),
labels_batch |> Enum.at(index) |> Kino.Markdown.new()
],
boxed: true
)
end)
|> Enum.to_list()
|> Kino.Layout.grid()
end)
```
<!-- livebook:{"output":true} -->
```
#Stream<[
enum: #Function<76.38948127/2 in Stream.zip_with/2>,
funs: [#Function<50.38948127/1 in Stream.map/2>]
]>
```
```elixir
visualization |> Enum.at(0)
```
```elixir
visualization |> Enum.at(1)
```
|