- fixed notebook

- added .gitignore
This commit is contained in:
2025-12-19 10:28:29 +01:00
parent ccad4e85a9
commit 10153f2634
2 changed files with 39 additions and 134 deletions
+2
View File
@@ -0,0 +1,2 @@
.ipynb_checkpoints/
data
+37 -134
View File
@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 1,
"id": "2e9496e9-ec07-445f-b29d-fc44aabb377d",
"metadata": {},
"outputs": [],
@@ -19,29 +19,31 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 2,
"id": "9b17757b-76c5-4562-a2be-e3a50201c9ee",
"metadata": {},
"outputs": [],
"source": [
"transform = transforms.Compose([transforms.ToTensor(), import numpy as np\n",
"from PIL import Image\n",
"import torch\n",
"import torch.nn as nn\n",
"import torch.nn.functional as F\n",
"import torch.optim as opim\n",
"import torchvision\n",
"import torchvision.transform as transform\n",
"\n",
"transform = transforms.Compose([\n",
" transforms.ToTensor(),\n",
" transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5)) \n",
"]) "
]
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": null,
"id": "5b898116-e9a8-429d-8491-67db5a65d358",
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"51.0%"
]
}
],
"source": [
"train_data = torchvision.datasets.CIFAR10(root='./data', train=True, transform=transform, download=True)\n",
"test_data = torchvision.datasets.CIFAR10(root='./data', train=False, transform=transform, download=True)\n",
@@ -52,7 +54,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": null,
"id": "49712fae-dfe6-4b6f-92ea-2e97a965c15c",
"metadata": {},
"outputs": [],
@@ -62,28 +64,17 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": null,
"id": "d783e1a5-3410-4992-88a6-230dd2ec85dd",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"torch.Size([3, 32, 32])"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"image.size()"
]
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": null,
"id": "8ef21399-f2f2-46f4-8268-f60f36bbb533",
"metadata": {},
"outputs": [],
@@ -120,7 +111,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": null,
"id": "f48dd819-9196-4aa5-92c4-ddcc644c6aa9",
"metadata": {},
"outputs": [],
@@ -132,77 +123,10 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": null,
"id": "3a91ce0c-e71d-4bfb-b945-47edfc8ca8d6",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Training epoch 0...\n",
"Loss: 2.1758\n",
"Training epoch 1...\n",
"Loss: 1.7324\n",
"Training epoch 2...\n",
"Loss: 1.5096\n",
"Training epoch 3...\n",
"Loss: 1.3996\n",
"Training epoch 4...\n",
"Loss: 1.3065\n",
"Training epoch 5...\n",
"Loss: 1.2286\n",
"Training epoch 6...\n",
"Loss: 1.1649\n",
"Training epoch 7...\n",
"Loss: 1.1101\n",
"Training epoch 8...\n",
"Loss: 1.0568\n",
"Training epoch 9...\n",
"Loss: 1.0140\n",
"Training epoch 10...\n",
"Loss: 0.9719\n",
"Training epoch 11...\n",
"Loss: 0.9321\n",
"Training epoch 12...\n",
"Loss: 0.8969\n",
"Training epoch 13...\n",
"Loss: 0.8649\n",
"Training epoch 14...\n",
"Loss: 0.8326\n",
"Training epoch 15...\n",
"Loss: 0.8014\n",
"Training epoch 16...\n",
"Loss: 0.7764\n",
"Training epoch 17...\n",
"Loss: 0.7449\n",
"Training epoch 18...\n",
"Loss: 0.7199\n",
"Training epoch 19...\n",
"Loss: 0.6991\n",
"Training epoch 20...\n",
"Loss: 0.6700\n",
"Training epoch 21...\n",
"Loss: 0.6438\n",
"Training epoch 22...\n",
"Loss: 0.6243\n",
"Training epoch 23...\n",
"Loss: 0.6051\n",
"Training epoch 24...\n",
"Loss: 0.5802\n",
"Training epoch 25...\n",
"Loss: 0.5609\n",
"Training epoch 26...\n",
"Loss: 0.5381\n",
"Training epoch 27...\n",
"Loss: 0.5162\n",
"Training epoch 28...\n",
"Loss: 0.4949\n",
"Training epoch 29...\n",
"Loss: 0.4752\n"
]
}
],
"outputs": [],
"source": [
"for epoch in range(30):\n",
" print(f'Training epoch {epoch}...')\n",
@@ -224,7 +148,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": null,
"id": "aa5b2497-90a7-44a9-9985-427b920945eb",
"metadata": {},
"outputs": [],
@@ -234,21 +158,10 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": null,
"id": "ff62419f-ead5-4244-9a5e-a21d568bdca8",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<All keys matched successfully>"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"net = NeuralNet()\n",
"net.load_state_dict(torch.load('trained_net.pth'))"
@@ -256,18 +169,10 @@
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": null,
"id": "eb1d4385-d4da-454f-9d8c-d844aa7b24df",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Accuracy: 68.23%\n"
]
}
],
"outputs": [],
"source": [
"correct = 0\n",
"total = 0\n",
@@ -286,20 +191,10 @@
},
{
"cell_type": "code",
"execution_count": 32,
"execution_count": null,
"id": "1a4f098f-b1ea-46b7-a7d6-769f80292f5f",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Prediction: cat\n",
"Prediction: deer\n",
"Prediction: plane\n"
]
}
],
"outputs": [],
"source": [
"new_transform = transforms.Compose([\n",
" transforms.Resize((32, 32)), \n",
@@ -323,6 +218,14 @@
" _, predicted = torch.max(output, 1)\n",
" print(f'Prediction: {class_names[predicted.item()]}')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "eed01777-2e7a-476c-8861-388d68f2f9c6",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {