- fixed notebook
- added .gitignore
This commit is contained in:
@@ -0,0 +1,2 @@
|
|||||||
|
.ipynb_checkpoints/
|
||||||
|
data
|
||||||
+37
-134
@@ -2,7 +2,7 @@
|
|||||||
"cells": [
|
"cells": [
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 17,
|
"execution_count": 1,
|
||||||
"id": "2e9496e9-ec07-445f-b29d-fc44aabb377d",
|
"id": "2e9496e9-ec07-445f-b29d-fc44aabb377d",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
@@ -19,29 +19,31 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 6,
|
"execution_count": 2,
|
||||||
"id": "9b17757b-76c5-4562-a2be-e3a50201c9ee",
|
"id": "9b17757b-76c5-4562-a2be-e3a50201c9ee",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"transform = transforms.Compose([transforms.ToTensor(), import numpy as np\n",
|
"transform = transforms.Compose([\n",
|
||||||
"from PIL import Image\n",
|
" transforms.ToTensor(),\n",
|
||||||
"import torch\n",
|
" transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5)) \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",
|
|
||||||
"]) "
|
"]) "
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 9,
|
"execution_count": null,
|
||||||
"id": "5b898116-e9a8-429d-8491-67db5a65d358",
|
"id": "5b898116-e9a8-429d-8491-67db5a65d358",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stderr",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"51.0%"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"train_data = torchvision.datasets.CIFAR10(root='./data', train=True, transform=transform, download=True)\n",
|
"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",
|
"test_data = torchvision.datasets.CIFAR10(root='./data', train=False, transform=transform, download=True)\n",
|
||||||
@@ -52,7 +54,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 10,
|
"execution_count": null,
|
||||||
"id": "49712fae-dfe6-4b6f-92ea-2e97a965c15c",
|
"id": "49712fae-dfe6-4b6f-92ea-2e97a965c15c",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
@@ -62,28 +64,17 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 11,
|
"execution_count": null,
|
||||||
"id": "d783e1a5-3410-4992-88a6-230dd2ec85dd",
|
"id": "d783e1a5-3410-4992-88a6-230dd2ec85dd",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [],
|
||||||
{
|
|
||||||
"data": {
|
|
||||||
"text/plain": [
|
|
||||||
"torch.Size([3, 32, 32])"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"execution_count": 11,
|
|
||||||
"metadata": {},
|
|
||||||
"output_type": "execute_result"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"source": [
|
"source": [
|
||||||
"image.size()"
|
"image.size()"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 12,
|
"execution_count": null,
|
||||||
"id": "8ef21399-f2f2-46f4-8268-f60f36bbb533",
|
"id": "8ef21399-f2f2-46f4-8268-f60f36bbb533",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
@@ -120,7 +111,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 18,
|
"execution_count": null,
|
||||||
"id": "f48dd819-9196-4aa5-92c4-ddcc644c6aa9",
|
"id": "f48dd819-9196-4aa5-92c4-ddcc644c6aa9",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
@@ -132,77 +123,10 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 19,
|
"execution_count": null,
|
||||||
"id": "3a91ce0c-e71d-4bfb-b945-47edfc8ca8d6",
|
"id": "3a91ce0c-e71d-4bfb-b945-47edfc8ca8d6",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"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"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"source": [
|
"source": [
|
||||||
"for epoch in range(30):\n",
|
"for epoch in range(30):\n",
|
||||||
" print(f'Training epoch {epoch}...')\n",
|
" print(f'Training epoch {epoch}...')\n",
|
||||||
@@ -224,7 +148,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 20,
|
"execution_count": null,
|
||||||
"id": "aa5b2497-90a7-44a9-9985-427b920945eb",
|
"id": "aa5b2497-90a7-44a9-9985-427b920945eb",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
@@ -234,21 +158,10 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 23,
|
"execution_count": null,
|
||||||
"id": "ff62419f-ead5-4244-9a5e-a21d568bdca8",
|
"id": "ff62419f-ead5-4244-9a5e-a21d568bdca8",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [],
|
||||||
{
|
|
||||||
"data": {
|
|
||||||
"text/plain": [
|
|
||||||
"<All keys matched successfully>"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"execution_count": 23,
|
|
||||||
"metadata": {},
|
|
||||||
"output_type": "execute_result"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"source": [
|
"source": [
|
||||||
"net = NeuralNet()\n",
|
"net = NeuralNet()\n",
|
||||||
"net.load_state_dict(torch.load('trained_net.pth'))"
|
"net.load_state_dict(torch.load('trained_net.pth'))"
|
||||||
@@ -256,18 +169,10 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 24,
|
"execution_count": null,
|
||||||
"id": "eb1d4385-d4da-454f-9d8c-d844aa7b24df",
|
"id": "eb1d4385-d4da-454f-9d8c-d844aa7b24df",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [],
|
||||||
{
|
|
||||||
"name": "stdout",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"Accuracy: 68.23%\n"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"source": [
|
"source": [
|
||||||
"correct = 0\n",
|
"correct = 0\n",
|
||||||
"total = 0\n",
|
"total = 0\n",
|
||||||
@@ -286,20 +191,10 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cell_type": "code",
|
"cell_type": "code",
|
||||||
"execution_count": 32,
|
"execution_count": null,
|
||||||
"id": "1a4f098f-b1ea-46b7-a7d6-769f80292f5f",
|
"id": "1a4f098f-b1ea-46b7-a7d6-769f80292f5f",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [
|
"outputs": [],
|
||||||
{
|
|
||||||
"name": "stdout",
|
|
||||||
"output_type": "stream",
|
|
||||||
"text": [
|
|
||||||
"Prediction: cat\n",
|
|
||||||
"Prediction: deer\n",
|
|
||||||
"Prediction: plane\n"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"source": [
|
"source": [
|
||||||
"new_transform = transforms.Compose([\n",
|
"new_transform = transforms.Compose([\n",
|
||||||
" transforms.Resize((32, 32)), \n",
|
" transforms.Resize((32, 32)), \n",
|
||||||
@@ -323,6 +218,14 @@
|
|||||||
" _, predicted = torch.max(output, 1)\n",
|
" _, predicted = torch.max(output, 1)\n",
|
||||||
" print(f'Prediction: {class_names[predicted.item()]}')"
|
" print(f'Prediction: {class_names[predicted.item()]}')"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"id": "eed01777-2e7a-476c-8861-388d68f2f9c6",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": []
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"metadata": {
|
"metadata": {
|
||||||
|
|||||||
Reference in New Issue
Block a user