Moving around the testing notebooks. Autocropping is about done with exception to any new versions or converting the stuff to C code. Signed-off-by: Ethan Wellenreiter <ewellenreiter@gmail.com>
646 lines
23 KiB
Plaintext
646 lines
23 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"version=2.0\n",
|
|
"cachepath=\"../.cache/\"\n",
|
|
"savepath=\"./savespot/\""
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 2,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"/usr/local/lib/python3.10/dist-packages/torchvision/datapoints/__init__.py:12: UserWarning: The torchvision.datapoints and torchvision.transforms.v2 namespaces are still Beta. While we do not expect major breaking changes, some APIs may still change according to user feedback. Please submit any feedback you may have in this issue: https://github.com/pytorch/vision/issues/6753, and you can also check out https://github.com/pytorch/vision/issues/7319 to learn more about the APIs that we suspect might involve future changes. You can silence this warning by calling torchvision.disable_beta_transforms_warning().\n",
|
|
" warnings.warn(_BETA_TRANSFORMS_WARNING)\n",
|
|
"/usr/local/lib/python3.10/dist-packages/torchvision/transforms/v2/__init__.py:54: UserWarning: The torchvision.datapoints and torchvision.transforms.v2 namespaces are still Beta. While we do not expect major breaking changes, some APIs may still change according to user feedback. Please submit any feedback you may have in this issue: https://github.com/pytorch/vision/issues/6753, and you can also check out https://github.com/pytorch/vision/issues/7319 to learn more about the APIs that we suspect might involve future changes. You can silence this warning by calling torchvision.disable_beta_transforms_warning().\n",
|
|
" warnings.warn(_BETA_TRANSFORMS_WARNING)\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import torch\n",
|
|
"from torch.utils.data import DataLoader\n",
|
|
"import torch.nn as nn\n",
|
|
"import torch.nn.functional as fn\n",
|
|
"import torch.optim as optim\n",
|
|
"import torchvision.transforms.functional as tvf\n",
|
|
"import torchvision.transforms.v2 as v2\n",
|
|
"import torchvision.models as models\n",
|
|
"\n",
|
|
"\n",
|
|
"from PIL import Image\n",
|
|
"\n",
|
|
"import datasets as ds\n",
|
|
"from tqdm.autonotebook import tqdm\n",
|
|
"\n",
|
|
"import random\n",
|
|
"\n",
|
|
"import matplotlib.pyplot as plt\n",
|
|
"\n",
|
|
"import numpy as np\n",
|
|
"\n",
|
|
"import os"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 3,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# models.list_models()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 4,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"torch.cuda.empty_cache()\n",
|
|
"working_dataset = ds.load_from_disk(cachepath + \"datasets/customrotation/\")\n",
|
|
"prepimage = v2.Compose([v2.Grayscale(num_output_channels=3),v2.Resize(512), v2.CenterCrop(512),v2.ToImageTensor(), v2.ConvertImageDtype()])\n",
|
|
"working_dataset.set_transform(prepimage)\n",
|
|
"testsample = working_dataset['train'][10]\n",
|
|
"testimage = testsample['image']\n",
|
|
"torch.cuda.empty_cache()"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 5,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# print(models.resnet18(pretrained=True))\n",
|
|
"# temp = models.resnet18(pretrained=True)\n",
|
|
"# print(temp(testimage.unsqueeze(0)).shape)\n",
|
|
"# device = torch.device(\"cpu\")\n",
|
|
"# if torch.cuda.is_available:\n",
|
|
"# device = torch.device(\"cuda:0\")\n",
|
|
"# temp = temp.to(device)\n",
|
|
"\n",
|
|
"#to be deleted"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 6,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# print(temp(testimage).shape)\n",
|
|
"#to be deleted"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 7,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"class RotationDeterminer(nn.Module):\n",
|
|
" def __init__(self, new=False):\n",
|
|
" super(RotationDeterminer,self).__init__()\n",
|
|
" \n",
|
|
" torch.cuda.empty_cache()\n",
|
|
" \n",
|
|
" self.device = torch.device(\"cpu\")\n",
|
|
" if torch.cuda.is_available:\n",
|
|
" self.device = torch.device(\"cuda:0\")\n",
|
|
" \n",
|
|
" \n",
|
|
" self.appliers = [v2.RandomApply(transforms=[v2.RandomPosterize(bits=1)], p=0.25),\n",
|
|
" v2.RandomApply(transforms=[v2.ElasticTransform(alpha=25.0)], p=0.25), # maybe add fill=appliedFill\n",
|
|
" v2.RandomApply(transforms=[v2.GaussianBlur(kernel_size=(5,9), sigma=(0.1,2.))],p=0.25),\n",
|
|
" v2.RandomApply(transforms=[v2.RandomEqualize()],p=0.25)]\n",
|
|
" \n",
|
|
" \n",
|
|
" # self.conv = nn.Sequential(nn.Conv2d(3, 9, kernel_size=11,stride=3), # 1100 x 1100 => 201 x 201\n",
|
|
" # nn.ReLU(inplace=True),\n",
|
|
" # nn.Conv2d(9, 18, kernel_size=5,stride=1),\n",
|
|
" # nn.ReLU(inplace=True),\n",
|
|
" # nn.MaxPool2d(kernel_size=4, stride=2),\n",
|
|
" # nn.Conv2d(18, 36, kernel_size=3,stride=2),\n",
|
|
" # nn.BatchNorm2d(36),\n",
|
|
" # nn.ReLU(inplace=True),\n",
|
|
" # nn.Conv2d(36, 72, kernel_size=3,stride=2),\n",
|
|
" # nn.ReLU(inplace=True),\n",
|
|
" # nn.AvgPool2d(kernel_size=5, stride=3),\n",
|
|
" # nn.Conv2d(72, 144, kernel_size=3,stride=1),\n",
|
|
" # nn.ReLU(inplace=True),\n",
|
|
" # nn.Conv2d(144, 288, kernel_size=5,stride=1),\n",
|
|
" # nn.ReLU(inplace=True),\n",
|
|
" # nn.MaxPool2d(kernel_size=4, stride=1),\n",
|
|
" # nn.Conv2d(288, 192, kernel_size=3,stride=1),\n",
|
|
" # nn.ReLU(inplace=True),\n",
|
|
" # nn.Conv2d(192, 192, kernel_size=3,stride=1), # => 1\n",
|
|
" # nn.ReLU(inplace=True))\n",
|
|
" # print(\"hi\")\n",
|
|
" self.conv = models.resnet18(pretrained=new)\n",
|
|
" \n",
|
|
" self.classifier = nn.Sequential(nn.Linear(1000, 4096),\n",
|
|
" nn.ReLU(inplace=True),\n",
|
|
" nn.Linear(4096,1))\n",
|
|
" \n",
|
|
" self.lossfunc = nn.MSELoss()\n",
|
|
" \n",
|
|
" self.imageprep = v2.Compose([self.SquarePad(),v2.Resize(512),v2.Grayscale(num_output_channels=3),v2.CenterCrop(512),v2.ToImageTensor(), v2.ConvertImageDtype()])\n",
|
|
" \n",
|
|
" \n",
|
|
" class SquarePad:\n",
|
|
" def __call__(self, image):\n",
|
|
" # print(\"hi type:\", type(image))\n",
|
|
" temp = image.size()\n",
|
|
" w = temp[-2]\n",
|
|
" h = temp[-1]\n",
|
|
" max_wh = max([w, h])\n",
|
|
" hp = int((max_wh - w) / 2)\n",
|
|
" vp = int((max_wh - h) / 2)\n",
|
|
" padding = (hp, vp, hp, vp)\n",
|
|
" return tvf.pad(image, padding, 0, 'edge')\n",
|
|
"\n",
|
|
"\n",
|
|
" \n",
|
|
"\n",
|
|
" \n",
|
|
" def forward(self, image):\n",
|
|
"\n",
|
|
" transformedimage = self.imageprep(image)\n",
|
|
" transformedimage = transformedimage.to(self.device)\n",
|
|
"\n",
|
|
" if (len(transformedimage.shape) != 4 and len(transformedimage.shape) != 3):\n",
|
|
" raise Exception(\"Sorry, Dimension of image is incorrect (\", len(transformedimage.shape),\"). Expected a 3D (single image) or 4D (batch of images) tensor\")\n",
|
|
"\n",
|
|
" if (len(transformedimage.shape) == 3):\n",
|
|
" x = transformedimage.unsqueeze(0)\n",
|
|
" else:\n",
|
|
" x = transformedimage\n",
|
|
" \n",
|
|
" x = self.conv(x)\n",
|
|
" # print(x.shape)\n",
|
|
" # x = nn.Flatten(start_dim=-1)(x)\n",
|
|
" # print(x.shape)\n",
|
|
" x = self.classifier(x)\n",
|
|
" # print(x.shape)\n",
|
|
" guessRotation = nn.Flatten(start_dim=0)(x)\n",
|
|
" \n",
|
|
" return guessRotation\n",
|
|
" \n",
|
|
" def loss(self, guess, trueAnswer):\n",
|
|
" return self.lossfunc(guess, trueAnswer)\n",
|
|
" \n",
|
|
" "
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 8,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"def train(model, dataset, batchsize, num_epochs, stepsize, totalnumiters = -1):\n",
|
|
" device = torch.device(\"cpu\")\n",
|
|
" if torch.cuda.is_available:\n",
|
|
" device = torch.device(\"cuda:0\")\n",
|
|
" model = model.cuda()\n",
|
|
" optimizer = optim.Adam(model.parameters(), lr=stepsize)\n",
|
|
" \n",
|
|
" counter = totalnumiters\n",
|
|
" model = model.train()\n",
|
|
" \n",
|
|
" breakearly = True\n",
|
|
" if totalnumiters == -1:\n",
|
|
" print(\"hi\")\n",
|
|
" breakearly = False\n",
|
|
" totalnumiters = len(dataset) + 1\n",
|
|
" \n",
|
|
" for e in range(num_epochs):\n",
|
|
" \n",
|
|
" train_dataloader = DataLoader(dataset, batch_size=batchsize, shuffle=True)\n",
|
|
" \n",
|
|
" pbar = tqdm(train_dataloader)\n",
|
|
" \n",
|
|
" for i, batch in enumerate(pbar):\n",
|
|
" torch.cuda.empty_cache()\n",
|
|
" images, truerotations = batch['image'], batch['rotation']\n",
|
|
" images = images.to(device)\n",
|
|
" truerotations = truerotations.to(device)\n",
|
|
"\n",
|
|
" optimizer.zero_grad()\n",
|
|
" \n",
|
|
" guessRotation = model(images)\n",
|
|
" \n",
|
|
" truerotations = truerotations.float()\n",
|
|
" \n",
|
|
" loss = model.loss(guessRotation, truerotations)\n",
|
|
" \n",
|
|
" loss.backward()\n",
|
|
" \n",
|
|
" optimizer.step()\n",
|
|
" counter = counter - batchsize\n",
|
|
" if counter <= 0 and breakearly:\n",
|
|
" print(\"endearly\")\n",
|
|
" return\n",
|
|
"\n",
|
|
" "
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 9,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"def measure(model, dataset):\n",
|
|
" total=0\n",
|
|
" within30=0\n",
|
|
" within15=0\n",
|
|
" within10=0\n",
|
|
" within5=0\n",
|
|
" within1=0\n",
|
|
" withintenth=0\n",
|
|
" model = model.eval()\n",
|
|
" pbar = tqdm(dataset)\n",
|
|
" for i, sample in enumerate(pbar):\n",
|
|
" if (i % 100 == 0):\n",
|
|
" torch.cuda.empty_cache()\n",
|
|
" images, truerotations = sample['image'], sample['rotation']\n",
|
|
" output = model(images)\n",
|
|
" outputvalue = output.item()\n",
|
|
" total = total + 1\n",
|
|
" if (abs(outputvalue - truerotations) < 0.1):\n",
|
|
" withintenth = withintenth + 1\n",
|
|
" within1 = within1 + 1\n",
|
|
" within5 = within5 + 1\n",
|
|
" within10 = within10 + 1\n",
|
|
" within15 = within15 + 1\n",
|
|
" within30 = within30 + 1\n",
|
|
" elif (abs(outputvalue - truerotations) < 1):\n",
|
|
" within1 = within1 + 1\n",
|
|
" within5 = within5 + 1\n",
|
|
" within10 = within10 + 1\n",
|
|
" within15 = within15 + 1\n",
|
|
" within30 = within30 + 1\n",
|
|
" elif (abs(outputvalue - truerotations) < 5):\n",
|
|
" within5 = within5 + 1\n",
|
|
" within10 = within10 + 1\n",
|
|
" within15 = within15 + 1\n",
|
|
" within30 = within30 + 1\n",
|
|
" elif (abs(outputvalue - truerotations) < 10):\n",
|
|
" within10 = within10 + 1\n",
|
|
" within15 = within15 + 1\n",
|
|
" within30 = within30 + 1\n",
|
|
" elif (abs(outputvalue - truerotations) < 15):\n",
|
|
" within15 = within15 + 1\n",
|
|
" within30 = within30 + 1\n",
|
|
" elif (abs(outputvalue - truerotations) < 30):\n",
|
|
" within30 = within30 + 1\n",
|
|
" # print(\"Hi\")\n",
|
|
" return {\"Within 30 Degrees\": within30/total, \"Within 15 Degrees\": within15/total, \"Within 10 Degrees\": within10/total, \"Within 5 Degrees\": within5/total, \"Within 1 Degree\": within1/total, \"Within 0.1 Degree\": withintenth/total}"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 10,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"/usr/local/lib/python3.10/dist-packages/torchvision/models/_utils.py:208: UserWarning: The parameter 'pretrained' is deprecated since 0.13 and may be removed in the future, please use 'weights' instead.\n",
|
|
" warnings.warn(\n",
|
|
"/usr/local/lib/python3.10/dist-packages/torchvision/models/_utils.py:223: UserWarning: Arguments other than a weight enum or `None` for 'weights' are deprecated since 0.13 and may be removed in the future. The current behavior is equivalent to passing `weights=ResNet18_Weights.IMAGENET1K_V1`. You can also use `weights=ResNet18_Weights.DEFAULT` to get the most up-to-date weights.\n",
|
|
" warnings.warn(msg)\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"model = RotationDeterminer(new=True)\n",
|
|
"device = torch.device(\"cpu\")\n",
|
|
"if torch.cuda.is_available:\n",
|
|
" device = torch.device(\"cuda:0\")\n",
|
|
" model = model.to(device)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 11,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# # used when starting a new model training\n",
|
|
"# counter = 0\n",
|
|
"# outputarray = np.array([])\n",
|
|
"# tempdict = {\"Epochs Done\": counter}\n",
|
|
"# tempdict.update(measure(model, working_dataset['validation']))\n",
|
|
"# outputarray = np.append(outputarray, tempdict)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 12,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# load values\n",
|
|
"counter = np.load(savepath + \"/v\"+str(version)+\"/counter.npy\")\n",
|
|
"model.load_state_dict(torch.load(savepath + \"/v\"+str(version)+\"/modelsave\" + str(counter) +\"epochs\"))\n",
|
|
"outputarray = np.load(savepath + \"/v\"+str(version)+\"/outputarray.npy\", allow_pickle=True)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 13,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# # used to rollback the model one training loop\n",
|
|
"# counter = 6\n",
|
|
"# outputarray = #removed the 7th element, will go from the 6th epoch"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 14,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"hi\n"
|
|
]
|
|
},
|
|
{
|
|
"data": {
|
|
"application/vnd.jupyter.widget-view+json": {
|
|
"model_id": "3048e1546e12444193f99b15781768d9",
|
|
"version_major": 2,
|
|
"version_minor": 0
|
|
},
|
|
"text/plain": [
|
|
" 0%| | 0/12800 [00:00<?, ?it/s]"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
},
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"/usr/local/lib/python3.10/dist-packages/torchvision/transforms/functional.py:1603: UserWarning: The default value of the antialias parameter of all the resizing transforms (Resize(), RandomResizedCrop(), etc.) will change from None to True in v0.17, in order to be consistent across the PIL and Tensor backends. To suppress this warning, directly pass antialias=True (recommended, future default), antialias=None (current default, which means False for Tensors and True for PIL), or antialias=False (only works on Tensors - PIL will still use antialiasing). This also applies if you are using the inference transforms from the models weights: update the call to weights.transforms(antialias=True).\n",
|
|
" warnings.warn(\n"
|
|
]
|
|
},
|
|
{
|
|
"data": {
|
|
"application/vnd.jupyter.widget-view+json": {
|
|
"model_id": "1a36a12b123e4b24bf00a8eeec2e396a",
|
|
"version_major": 2,
|
|
"version_minor": 0
|
|
},
|
|
"text/plain": [
|
|
" 0%| | 0/12800 [00:00<?, ?it/s]"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
}
|
|
],
|
|
"source": [
|
|
"# train\n",
|
|
"numepochs = 2\n",
|
|
"batchsize = 25\n",
|
|
"stepsize = 1e-3\n",
|
|
"train(model, working_dataset['train'], batchsize, numepochs, stepsize)\n",
|
|
"# model = model.eval()\n",
|
|
"# output = model(testimage)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 15,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# print(output)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 16,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"application/vnd.jupyter.widget-view+json": {
|
|
"model_id": "6b99a98f480745c4a375bf1e713708ed",
|
|
"version_major": 2,
|
|
"version_minor": 0
|
|
},
|
|
"text/plain": [
|
|
" 0%| | 0/40000 [00:00<?, ?it/s]"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
}
|
|
],
|
|
"source": [
|
|
"# outputarray = np.append(outputarray, output.detach().cpu().numpy())\n",
|
|
"counter = numepochs + counter\n",
|
|
"tempdict = {\"Epochs Done\": counter}\n",
|
|
"tempdict.update(measure(model, working_dataset['validation']))\n",
|
|
"outputarray = np.append(outputarray, tempdict)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 17,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# save values\n",
|
|
"torch.save(model.state_dict(), savepath + \"/v\"+str(version)+\"/modelsave\" + str(counter) +\"epochs\")\n",
|
|
"np.save(savepath + \"/v\"+str(version)+\"/outputarray\", outputarray)\n",
|
|
"np.save(savepath + \"/v\"+str(version)+\"/counter\", counter)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 18,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"[{'Epochs Done': 0, 'Within 30 Degrees': 0.162575, 'Within 15 Degrees': 0.080575, 'Within 10 Degrees': 0.053725, 'Within 5 Degrees': 0.027125, 'Within 1 Degree': 0.00545, 'Within 0.1 Degree': 0.00075}\n",
|
|
" {'Epochs Done': 1, 'Within 30 Degrees': 0.7764, 'Within 15 Degrees': 0.65105, 'Within 10 Degrees': 0.538875, 'Within 5 Degrees': 0.322625, 'Within 1 Degree': 0.070375, 'Within 0.1 Degree': 0.00805}\n",
|
|
" {'Epochs Done': 5, 'Within 30 Degrees': 0.891675, 'Within 15 Degrees': 0.8042, 'Within 10 Degrees': 0.673275, 'Within 5 Degrees': 0.415725, 'Within 1 Degree': 0.092375, 'Within 0.1 Degree': 0.009275}\n",
|
|
" {'Epochs Done': 8, 'Within 30 Degrees': 0.928125, 'Within 15 Degrees': 0.881625, 'Within 10 Degrees': 0.7686, 'Within 5 Degrees': 0.4791, 'Within 1 Degree': 0.102925, 'Within 0.1 Degree': 0.009975}\n",
|
|
" {'Epochs Done': 11, 'Within 30 Degrees': 0.9417, 'Within 15 Degrees': 0.91265, 'Within 10 Degrees': 0.86655, 'Within 5 Degrees': 0.633125, 'Within 1 Degree': 0.14265, 'Within 0.1 Degree': 0.01495}\n",
|
|
" {'Epochs Done': 13, 'Within 30 Degrees': 0.941575, 'Within 15 Degrees': 0.917375, 'Within 10 Degrees': 0.889125, 'Within 5 Degrees': 0.735525, 'Within 1 Degree': 0.1992, 'Within 0.1 Degree': 0.019875}]\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"print(outputarray)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 26,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"application/vnd.jupyter.widget-view+json": {
|
|
"model_id": "d339e6a22ccf4812bdad90dd3d546c68",
|
|
"version_major": 2,
|
|
"version_minor": 0
|
|
},
|
|
"text/plain": [
|
|
" 0%| | 0/39999 [00:00<?, ?it/s]"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
},
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"/usr/local/lib/python3.10/dist-packages/torchvision/transforms/functional.py:1603: UserWarning: The default value of the antialias parameter of all the resizing transforms (Resize(), RandomResizedCrop(), etc.) will change from None to True in v0.17, in order to be consistent across the PIL and Tensor backends. To suppress this warning, directly pass antialias=True (recommended, future default), antialias=None (current default, which means False for Tensors and True for PIL), or antialias=False (only works on Tensors - PIL will still use antialiasing). This also applies if you are using the inference transforms from the models weights: update the call to weights.transforms(antialias=True).\n",
|
|
" warnings.warn(\n"
|
|
]
|
|
},
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"{'Within 30 Degrees': 0.9433985849646241,\n",
|
|
" 'Within 15 Degrees': 0.9174979374484362,\n",
|
|
" 'Within 10 Degrees': 0.889422235555889,\n",
|
|
" 'Within 5 Degrees': 0.737118427960699,\n",
|
|
" 'Within 1 Degree': 0.1995799894997375,\n",
|
|
" 'Within 0.1 Degree': 0.020050501262531564}"
|
|
]
|
|
},
|
|
"execution_count": 26,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"measure(model, working_dataset['test'])"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 20,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# first epoch 25 batchsize, 1e-3 stepsize # GOOD PROGRESS SO FAR\n",
|
|
"# epoch 2-11 25 batchsize, 1e-3 stepsize"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 21,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# model1 = RotationDeterminer(new=False)\n",
|
|
"# device = torch.device(\"cpu\")\n",
|
|
"# if torch.cuda.is_available:\n",
|
|
"# device = torch.device(\"cuda:0\")\n",
|
|
"# model1 = model1.to(device)\n",
|
|
"# measurementarray=np.array([])\n",
|
|
"# for i in range(counter+1):\n",
|
|
"# print(i)\n",
|
|
"# if (i == 0 or i == 1 or i == 5 or i == 8 or i == 11):\n",
|
|
"# tempdict = {\"Epochs Done\": i}\n",
|
|
"# model1.load_state_dict(torch.load(savepath + \"/v\"+str(version)+\"/modelsave\" + str(i) +\"epochs\"))\n",
|
|
"# tempdict.update(measure(model1, working_dataset['validation']))\n",
|
|
"# measurementarray = np.append(measurementarray, tempdict)\n",
|
|
" \n",
|
|
"# print(\"hi\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 22,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# print(measurementarray)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 23,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# np.save(savepath + \"/v\"+str(version)+\"/outputarray\", measurementarray)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 24,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# measurementarraycopy = measurementarray\n",
|
|
"# tempdict = {\"Epochs Done\": 1}\n",
|
|
"# tempdict.update(measurementarraycopy[0])"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 25,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# print(tempdict)"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3 (ipykernel)",
|
|
"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.10.12"
|
|
},
|
|
"orig_nbformat": 4
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|