Spaces:
Sleeping
Sleeping
Commit ·
f3b3e3a
1
Parent(s): 4fffb5f
Fixed BGR read to RGB and Loaded data using Numpy Array with matrix and visual representation
Browse files7 unmodified lines8910111112131415161718192021222316171819202122232425262728291 unmodified line31323331323334353637383940414243444546474834353637383940414243444546474849505152535455565758596061626364656653676869709 unmodified lines808182698384858617 unmodified lines10410510693107108109110111112113989910010110210310410510610710810911011111211311411511611711811912011411511611722 unmodified lines14014114214914314414514618 unmodified lines1651661671741681691701715 unmodified lines1771781791861801811821831841911851861871884 unmodified lines1931941952021961971981996 unmodified lines2062072082092102112122132142152168 unmodified lines22522622722922822923023123223323523423523623723824023924024124324224324424524624724925024824925025125225339 unmodified lines2932942952962962972982997 unmodified lines }, { "cell_type": "code", "execution_count": 68, "execution_count": 5, "id": "51e70576", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "GPU is available\n", "Converting Arrays to Tensors . . . .\n", "torch.Size([11197, 150, 150, 3]) cpu\n", "torch.Size([11197]) cpu\n", "Tensors Created!\n" "ename": "AttributeError", "evalue": "module 'torch' has no attribute 'cuda'", "output_type": "error", "traceback": [ "\u001b[31m---------------------------------------------------------------------------\u001b[39m", "\u001b[31mAttributeError\u001b[39m Traceback (most recent call last)", "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[5]\u001b[39m\u001b[32m, line 3\u001b[39m\n\u001b[32m 1\u001b[39m \u001b[33m\"\"\"1.This cell contains the code loading,checking and reshaping the dataset for further processing\"\"\"\u001b[39m\n\u001b[32m 2\u001b[39m \n\u001b[32m----> \u001b[39m\u001b[32m3\u001b[39m \u001b[38;5;28;01mimport\u001b[39;00m torch\n\u001b[32m 4\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m torchvision \u001b[38;5;28;01mimport\u001b[39;00m transforms,datasets\n\u001b[32m 5\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m torch.utils.data \u001b[38;5;28;01mimport\u001b[39;00m DataLoader\n\u001b[32m 6\u001b[39m \n", "\u001b[36mFile \u001b[39m\u001b[32m~\\AppData\\Local\\Python\\pythoncore-3.14-64\\Lib\\site-packages\\torch\\__init__.py:2694\u001b[39m\n\u001b[32m 2678\u001b[39m \u001b[38;5;66;03m################################################################################\u001b[39;00m\n\u001b[32m 2679\u001b[39m \u001b[38;5;66;03m# Import most common subpackages\u001b[39;00m\n\u001b[32m 2680\u001b[39m \u001b[38;5;66;03m################################################################################\u001b[39;00m\n\u001b[32m (...)\u001b[39m\u001b[32m 2685\u001b[39m \n\u001b[32m 2686\u001b[39m \u001b[38;5;66;03m# needs to be before import torch.nn as nn to avoid circular dependencies\u001b[39;00m\n\u001b[32m 2687\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mtorch\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01mautograd\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m ( \u001b[38;5;66;03m# usort: skip\u001b[39;00m\n\u001b[32m 2688\u001b[39m enable_grad \u001b[38;5;28;01mas\u001b[39;00m enable_grad,\n\u001b[32m 2689\u001b[39m inference_mode \u001b[38;5;28;01mas\u001b[39;00m inference_mode,\n\u001b[32m 2690\u001b[39m no_grad \u001b[38;5;28;01mas\u001b[39;00m no_grad,\n\u001b[32m 2691\u001b[39m set_grad_enabled \u001b[38;5;28;01mas\u001b[39;00m set_grad_enabled,\n\u001b[32m 2692\u001b[39m )\n\u001b[32m-> \u001b[39m\u001b[32m2694\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mtorch\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m (\n\u001b[32m 2695\u001b[39m __config__ \u001b[38;5;28;01mas\u001b[39;00m __config__,\n\u001b[32m 2696\u001b[39m __future__ \u001b[38;5;28;01mas\u001b[39;00m __future__,\n\u001b[32m 2697\u001b[39m _awaits \u001b[38;5;28;01mas\u001b[39;00m _awaits,\n\u001b[32m 2698\u001b[39m accelerator \u001b[38;5;28;01mas\u001b[39;00m accelerator,\n\u001b[32m 2699\u001b[39m autograd \u001b[38;5;28;01mas\u001b[39;00m autograd,\n\u001b[32m 2700\u001b[39m backends \u001b[38;5;28;01mas\u001b[39;00m backends,\n\u001b[32m 2701\u001b[39m cpu \u001b[38;5;28;01mas\u001b[39;00m cpu,\n\u001b[32m 2702\u001b[39m cuda \u001b[38;5;28;01mas\u001b[39;00m cuda,\n\u001b[32m 2703\u001b[39m distributed \u001b[38;5;28;01mas\u001b[39;00m distributed,\n\u001b[32m 2704\u001b[39m distributions \u001b[38;5;28;01mas\u001b[39;00m distributions,\n\u001b[32m 2705\u001b[39m fft \u001b[38;5;28;01mas\u001b[39;00m fft,\n\u001b[32m 2706\u001b[39m futures \u001b[38;5;28;01mas\u001b[39;00m futures,\n\u001b[32m 2707\u001b[39m hub \u001b[38;5;28;01mas\u001b[39;00m hub,\n\u001b[32m 2708\u001b[39m jit \u001b[38;5;28;01mas\u001b[39;00m jit,\n\u001b[32m 2709\u001b[39m linalg \u001b[38;5;28;01mas\u001b[39;00m linalg,\n\u001b[32m 2710\u001b[39m mps \u001b[38;5;28;01mas\u001b[39;00m mps,\n\u001b[32m 2711\u001b[39m mtia \u001b[38;5;28;01mas\u001b[39;00m mtia,\n\u001b[32m 2712\u001b[39m multiprocessing \u001b[38;5;28;01mas\u001b[39;00m multiprocessing,\n\u001b[32m 2713\u001b[39m nested \u001b[38;5;28;01mas\u001b[39;00m nested,\n\u001b[32m 2714\u001b[39m nn \u001b[38;5;28;01mas\u001b[39;00m nn,\n\u001b[32m 2715\u001b[39m optim \u001b[38;5;28;01mas\u001b[39;00m optim,\n\u001b[32m 2716\u001b[39m overrides \u001b[38;5;28;01mas\u001b[39;00m overrides,\n\u001b[32m 2717\u001b[39m profiler \u001b[38;5;28;01mas\u001b[39;00m profiler,\n\u001b[32m 2718\u001b[39m sparse \u001b[38;5;28;01mas\u001b[39;00m sparse,\n\u001b[32m 2719\u001b[39m special \u001b[38;5;28;01mas\u001b[39;00m special,\n\u001b[32m 2720\u001b[39m testing \u001b[38;5;28;01mas\u001b[39;00m testing,\n\u001b[32m 2721\u001b[39m types \u001b[38;5;28;01mas\u001b[39;00m types,\n\u001b[32m 2722\u001b[39m utils \u001b[38;5;28;01mas\u001b[39;00m utils,\n\u001b[32m 2723\u001b[39m version \u001b[38;5;28;01mas\u001b[39;00m version,\n\u001b[32m 2724\u001b[39m xpu \u001b[38;5;28;01mas\u001b[39;00m xpu,\n\u001b[32m 2725\u001b[39m )\n\u001b[32m 2726\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mtorch\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01msignal\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m windows \u001b[38;5;28;01mas\u001b[39;00m windows\n\u001b[32m 2729\u001b[39m \u001b[38;5;66;03m# Quantized, sparse, AO, etc. should be last to get imported, as nothing\u001b[39;00m\n\u001b[32m 2730\u001b[39m \u001b[38;5;66;03m# is expected to depend on them.\u001b[39;00m\n", "\u001b[36mFile \u001b[39m\u001b[32m~\\AppData\\Local\\Python\\pythoncore-3.14-64\\Lib\\site-packages\\torch\\multiprocessing\\__init__.py:105\u001b[39m\n\u001b[32m 97\u001b[39m \u001b[38;5;250m \u001b[39m\u001b[33;03m\"\"\"Get the name of the current thread.\u001b[39;00m\n\u001b[32m 98\u001b[39m \n\u001b[32m 99\u001b[39m \u001b[33;03m Returns:\u001b[39;00m\n\u001b[32m 100\u001b[39m \u001b[33;03m str: Name of the current thread.\u001b[39;00m\n\u001b[32m 101\u001b[39m \u001b[33;03m \"\"\"\u001b[39;00m\n\u001b[32m 102\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m torch._C._get_thread_name()\n\u001b[32m--> \u001b[39m\u001b[32m105\u001b[39m \u001b[30;43minit_reductions\u001b[39;49m\u001b[30;43m(\u001b[39;49m\u001b[30;43m)\u001b[39;49m\n\u001b[32m 107\u001b[39m \u001b[38;5;66;03m# Leak ResourceTracker at exit for Python-3.12 on MacOS\u001b[39;00m\n\u001b[32m 108\u001b[39m \u001b[38;5;66;03m# See https://github.com/pytorch/pytorch/issues/153050 and\u001b[39;00m\n\u001b[32m 109\u001b[39m \u001b[38;5;66;03m# https://github.com/python/cpython/issues/88887 for more details\u001b[39;00m\n\u001b[32m 110\u001b[39m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mmultiprocessing\u001b[39;00m\u001b[34;01m.\u001b[39;00m\u001b[34;01mresource_tracker\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m ResourceTracker \u001b[38;5;28;01mas\u001b[39;00m _RT\n", "\u001b[36mFile \u001b[39m\u001b[32m~\\AppData\\Local\\Python\\pythoncore-3.14-64\\Lib\\site-packages\\torch\\multiprocessing\\reductions.py:624\u001b[39m, in \u001b[36minit_reductions\u001b[39m\u001b[34m()\u001b[39m\n\u001b[32m 623\u001b[39m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34minit_reductions\u001b[39m():\n\u001b[32m--> \u001b[39m\u001b[32m624\u001b[39m reduction.register(\u001b[30;43mtorch\u001b[39;49m\u001b[30;43m.\u001b[39;49m\u001b[30;43mcuda\u001b[39;49m.Event, reduce_event)\n\u001b[32m 626\u001b[39m \u001b[38;5;28;01mfor\u001b[39;00m t \u001b[38;5;129;01min\u001b[39;00m torch._storage_classes:\n\u001b[32m 627\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m t.\u001b[34m__name__\u001b[39m == \u001b[33m\"\u001b[39m\u001b[33mUntypedStorage\u001b[39m\u001b[33m\"\u001b[39m:\n", "\u001b[31mAttributeError\u001b[39m: module 'torch' has no attribute 'cuda'" ] } ],1 unmodified line "\"\"\"1.This cell contains the code loading,checking and reshaping the dataset for further processing\"\"\" \n", "\n", "import torch \n", "import numpy as np\n", "\n", "\n", "#Loading Nmpy Arrays from the dataset\n", "raw = np.load(\"flowers_data.npy\")\n", "device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\") #Fallback to CPU if GPU is not available\n", "if(device.type == \"cuda\"):\n", " print(\"GPU is available\")\n", " print(\"Converting Arrays to Tensors . . . .\")\n", " #Converting the numpy arrays to torch tensors for faster computing\n", "converted_x_label = torch.from_numpy(raw['X']).float() #W have converted to float because its necessary for further calculation accuracy\n", "converted_y_label = torch.from_numpy(raw['Y']).float()\n", "print(converted_x_label.shape,converted_x_label.device)\n", "print(converted_y_label.shape,converted_y_label.device)\n", "print(\"Tensors Created!\")\n", "\n", "#So the shape becomes (N, H, W, C) where N is the number of samples, H is the height of the image, W is the width of the image and C is the number of channels. But the model we are using expects the input shape to be (N, C, H, W). So we need to permute the dimensions of the tensor to match the input shape of the model.\n", "permuted = torch.permute(converted_x_label, (0, 3, 1, 2)) #Permuting the dimensions of the tensor to match the input shape of the model\n" "from torchvision import transforms,datasets\n", "from torch.utils.data import DataLoader\n", "\n", "\n", "print(torch.__version__)\n", "print(torch.cuda.is_available())\n", "\n", "# device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\") #Fallback to CPU if GPU is not available\n", "# if(device.type == \"cuda\"):\n", "# print(\"GPU is available\")\n", "# print(\"Converting Arrays to Tensors . . . .\")\n", "\n", "\n", "# dataset = datasets.ImageFolder(root=\"ScratchNet/flowers\", transform = transform)\n", "\n", "\n", "# transform = transforms.Compose([transforms.ToTensor()]) #Converting images to tensors\n", "\n", "\n", "# #Spliting the dataset into training and testing datasets\n", "# train_dataset = int(0.8*len(dataset)) #80% of the dataset will be used for training\n", "# test_dataset = len(dataset) - train_dataset #20% of the dataset will be used for\n", "\n", "\n", "# train_dataloader = DataLoader(train_dataset, batch_size=64, shuffle=True) #Creating a dataloader to load the dataset to GPU in batches\n", "\n", "# test_dataloader = DataLoader(test_dataset, batch_size=64, shuffle=True) #Creating a dataloader to load the dataset in batches\n", "\n", "\n" ] }, { "cell_type": "code", "execution_count": 69, "execution_count": 93, "id": "6723a3ca", "metadata": {}, "outputs": [],9 unmodified lines }, { "cell_type": "code", "execution_count": 70, "execution_count": 94, "id": "7c295080", "metadata": {}, "outputs": [17 unmodified lines "\n", "# Turns (11197, 150, 150, 3) -> (11197, 3, 150, 150)\n", "X_train = X_train.permute(0, 3, 1, 2).float()\n", "X_test = X_test.permute(0, 3, 1, 2).float()" "X_test = X_test.permute(0, 3, 1, 2).float()\n", "Y_train = Y_train.long()\n", "Y_test = Y_test.long()" ] }, { "cell_type": "code", "execution_count": 71, "id": "d9535811", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Batches created for Train Data:140 and Test Data: 35\n" ] } ], "source": [ "from torch.utils.data import DataLoader,TensorDataset\n", "batch__size = 64\n", "train_loader = DataLoader(TensorDataset(X_train, Y_train), batch_size=batch__size, shuffle=True)\n", "test_loader = DataLoader(TensorDataset(X_test, Y_test), batch_size=batch__size, shuffle=False)\n", "print(f\"Batches created for Train Data:{len(train_loader)} and Test Data: {len(test_loader)}\")\n" ] }, { "cell_type": "code", "execution_count": null, "execution_count": 96, "id": "41cfdb24", "metadata": {}, "outputs": [22 unmodified lines " )\n", " (flatten): Flatten(start_dim=1, end_dim=-1)\n", " (layer_1): Sequential(\n", " (0): Linear(in_features=67500, out_features=128, bias=True)\n", " (0): Linear(in_features=9072, out_features=128, bias=True)\n", " (1): ReLU()\n", " )\n", " (layer_2): Sequential(\n",18 unmodified lines " super().__init__()\n", "\n", " #Convolutional Layer1 forward pass\n", " self.cnn_layer = nn.Sequential(nn.Conv2d(in_channels=3, out_channels =32,kernel_size=2,padding=1,stride = 2,bias = True) ,\n", " self.cnn_layer = nn.Sequential(nn.Conv2d(in_channels=3, out_channels =32,kernel_size=3,padding=1,stride = 1,bias = True) ,\n", " nn.BatchNorm2d(32),\n", " #Activation Layer\n", " nn.ReLU(),\n",5 unmodified lines "\n", "\n", "\n", " self.cnn_layer_2 = nn.Sequential(nn.Conv2d(in_channels=32, out_channels =64,kernel_size=2,padding=1,stride = 2,bias = True),\n", " self.cnn_layer_2 = nn.Sequential(nn.Conv2d(in_channels=32, out_channels =64,kernel_size=3,padding=1,stride = 1,bias = True),\n", " nn.BatchNorm2d(64),\n", " nn.ReLU(),\n", " nn.MaxPool2d(kernel_size=3,stride =1,padding=1))\n", "\n", " self.cnn_layer_3 = nn.Sequential(nn.Conv2d(in_channels=64, out_channels =128,kernel_size=2,padding=1,stride = 2,bias = True),\n", " self.cnn_layer_3 = nn.Sequential(nn.Conv2d(in_channels=64, out_channels =128,kernel_size=3,padding=1,stride = 1,bias = True),\n", " nn.BatchNorm2d(128),\n", " nn.ReLU(),\n", " nn.MaxPool2d(kernel_size=3,stride =1,padding=1))\n",4 unmodified lines " self.flatten = nn.Flatten()\n", "\n", "\n", " self.layer_1 = nn.Sequential(nn.Linear(in_features = 67500,out_features =128,bias=True),\n", " self.layer_1 = nn.Sequential(nn.Linear(in_features = 28*18*18,out_features =128,bias=True),\n", " nn.ReLU())\n", " self.layer_2 = nn.Sequential(nn.Linear(in_features = 128,out_features =64,bias=True),\n", " nn.ReLU())\n",6 unmodified lines " \n", "\n", " def forward(self,x):\n", "\n", " x = self.cnn_layer(x)\n", " x = self.cnn_layer_2(x)\n", " x = self.cnn_layer_3(x)\n", "\n", " x = (self.layer_1(x))\n", " x = (self.layer_2(x))\n", " x = (self.layer_3(x))\n",8 unmodified lines }, { "cell_type": "code", "execution_count": 75, "execution_count": null, "id": "40d53a08", "metadata": {}, "outputs": [ { "ename": "RuntimeError", "evalue": "mat1 and mat2 shapes cannot be multiplied (28800x150 and 67500x128)", "evalue": "Given groups=1, weight of size [32, 3, 3, 3], expected input[64, 150, 3, 150] to have 3 channels, but got 150 channels instead", "output_type": "error", "traceback": [ "\u001b[31m---------------------------------------------------------------------------\u001b[39m", "\u001b[31mRuntimeError\u001b[39m Traceback (most recent call last)", "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[75]\u001b[39m\u001b[32m, line 17\u001b[39m\n\u001b[32m 13\u001b[39m images = images.to(device)\n\u001b[32m 14\u001b[39m labels = labels.to(device)\n\u001b[32m 15\u001b[39m \n\u001b[32m 16\u001b[39m \u001b[38;5;66;03m# Forward pass & loss\u001b[39;00m\n\u001b[32m---> \u001b[39m\u001b[32m17\u001b[39m output = model(images)\n\u001b[32m 18\u001b[39m loss = loss_function(output, labels)\n\u001b[32m 19\u001b[39m \n\u001b[32m 20\u001b[39m \u001b[38;5;66;03m# Optimization\u001b[39;00m\n", "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[97]\u001b[39m\u001b[32m, line 17\u001b[39m\n\u001b[32m 13\u001b[39m images = images.to(device)\n\u001b[32m 14\u001b[39m labels = labels.to(device)\n\u001b[32m 15\u001b[39m \n\u001b[32m 16\u001b[39m \u001b[38;5;66;03m# Forward pass & loss\u001b[39;00m\n\u001b[32m---> \u001b[39m\u001b[32m17\u001b[39m output = model(images)\n\u001b[32m 18\u001b[39m loss = loss_function(output, labels)\n\u001b[32m 19\u001b[39m \n\u001b[32m 20\u001b[39m \u001b[38;5;66;03m# Optimization\u001b[39;00m\n", "\u001b[36mFile \u001b[39m\u001b[32m~\\AppData\\Local\\Python\\pythoncore-3.14-64\\Lib\\site-packages\\torch\\nn\\modules\\module.py:1783\u001b[39m, in \u001b[36mModule._wrapped_call_impl\u001b[39m\u001b[34m(self, *args, **kwargs)\u001b[39m\n\u001b[32m 1781\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m._compiled_call_impl(*args, **kwargs) \u001b[38;5;66;03m# type: ignore[misc]\u001b[39;00m\n\u001b[32m 1782\u001b[39m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[32m-> \u001b[39m\u001b[32m1783\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[30;43mself\u001b[39;49m\u001b[30;43m.\u001b[39;49m\u001b[30;43m_call_impl\u001b[39;49m\u001b[30;43m(\u001b[39;49m\u001b[30;43m*\u001b[39;49m\u001b[30;43margs\u001b[39;49m\u001b[30;43m,\u001b[39;49m\u001b[30;43m \u001b[39;49m\u001b[30;43m*\u001b[39;49m\u001b[30;43m*\u001b[39;49m\u001b[30;43mkwargs\u001b[39;49m\u001b[30;43m)\u001b[39;49m\n", "\u001b[36mFile \u001b[39m\u001b[32m~\\AppData\\Local\\Python\\pythoncore-3.14-64\\Lib\\site-packages\\torch\\nn\\modules\\module.py:1794\u001b[39m, in \u001b[36mModule._call_impl\u001b[39m\u001b[34m(self, *args, **kwargs)\u001b[39m\n\u001b[32m 1789\u001b[39m \u001b[38;5;66;03m# If we don't have any hooks, we want to skip the rest of the logic in\u001b[39;00m\n\u001b[32m 1790\u001b[39m \u001b[38;5;66;03m# this function, and just call forward.\u001b[39;00m\n\u001b[32m 1791\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m (\u001b[38;5;28mself\u001b[39m._backward_hooks \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;28mself\u001b[39m._backward_pre_hooks \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;28mself\u001b[39m._forward_hooks \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;28mself\u001b[39m._forward_pre_hooks\n\u001b[32m 1792\u001b[39m \u001b[38;5;129;01mor\u001b[39;00m _global_backward_pre_hooks \u001b[38;5;129;01mor\u001b[39;00m _global_backward_hooks\n\u001b[32m 1793\u001b[39m \u001b[38;5;129;01mor\u001b[39;00m _global_forward_hooks \u001b[38;5;129;01mor\u001b[39;00m _global_forward_pre_hooks):\n\u001b[32m-> \u001b[39m\u001b[32m1794\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[30;43mforward_call\u001b[39;49m\u001b[30;43m(\u001b[39;49m\u001b[30;43m*\u001b[39;49m\u001b[30;43margs\u001b[39;49m\u001b[30;43m,\u001b[39;49m\u001b[30;43m \u001b[39;49m\u001b[30;43m*\u001b[39;49m\u001b[30;43m*\u001b[39;49m\u001b[30;43mkwargs\u001b[39;49m\u001b[30;43m)\u001b[39;49m\n\u001b[32m 1796\u001b[39m result = \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[32m 1797\u001b[39m called_always_called_hooks = \u001b[38;5;28mset\u001b[39m()\n", "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[74]\u001b[39m\u001b[32m, line 50\u001b[39m, in \u001b[36mFlowerClassifier.forward\u001b[39m\u001b[34m(self, x)\u001b[39m\n\u001b[32m 49\u001b[39m \u001b[38;5;28;01mdef\u001b[39;00m forward(self,x):\n\u001b[32m---> \u001b[39m\u001b[32m50\u001b[39m x = self.layer_1(x)\n\u001b[32m 51\u001b[39m x = self.layer_2(x)\n\u001b[32m 52\u001b[39m x = self.layer_3(x)\n\u001b[32m 53\u001b[39m x = self.out(x)\n", "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[96]\u001b[39m\u001b[32m, line 51\u001b[39m, in \u001b[36mFlowerClassifier.forward\u001b[39m\u001b[34m(self, x)\u001b[39m\n\u001b[32m 49\u001b[39m \u001b[38;5;28;01mdef\u001b[39;00m forward(self,x):\n\u001b[32m 50\u001b[39m \n\u001b[32m---> \u001b[39m\u001b[32m51\u001b[39m x = self.cnn_layer(x)\n\u001b[32m 52\u001b[39m x = self.cnn_layer_2(x)\n\u001b[32m 53\u001b[39m x = self.cnn_layer_3(x)\n\u001b[32m 54\u001b[39m \n", "\u001b[36mFile \u001b[39m\u001b[32m~\\AppData\\Local\\Python\\pythoncore-3.14-64\\Lib\\site-packages\\torch\\nn\\modules\\module.py:1783\u001b[39m, in \u001b[36mModule._wrapped_call_impl\u001b[39m\u001b[34m(self, *args, **kwargs)\u001b[39m\n\u001b[32m 1781\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m._compiled_call_impl(*args, **kwargs) \u001b[38;5;66;03m# type: ignore[misc]\u001b[39;00m\n\u001b[32m 1782\u001b[39m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[32m-> \u001b[39m\u001b[32m1783\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[30;43mself\u001b[39;49m\u001b[30;43m.\u001b[39;49m\u001b[30;43m_call_impl\u001b[39;49m\u001b[30;43m(\u001b[39;49m\u001b[30;43m*\u001b[39;49m\u001b[30;43margs\u001b[39;49m\u001b[30;43m,\u001b[39;49m\u001b[30;43m \u001b[39;49m\u001b[30;43m*\u001b[39;49m\u001b[30;43m*\u001b[39;49m\u001b[30;43mkwargs\u001b[39;49m\u001b[30;43m)\u001b[39;49m\n", "\u001b[36mFile \u001b[39m\u001b[32m~\\AppData\\Local\\Python\\pythoncore-3.14-64\\Lib\\site-packages\\torch\\nn\\modules\\module.py:1794\u001b[39m, in \u001b[36mModule._call_impl\u001b[39m\u001b[34m(self, *args, **kwargs)\u001b[39m\n\u001b[32m 1789\u001b[39m \u001b[38;5;66;03m# If we don't have any hooks, we want to skip the rest of the logic in\u001b[39;00m\n\u001b[32m 1790\u001b[39m \u001b[38;5;66;03m# this function, and just call forward.\u001b[39;00m\n\u001b[32m 1791\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m (\u001b[38;5;28mself\u001b[39m._backward_hooks \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;28mself\u001b[39m._backward_pre_hooks \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;28mself\u001b[39m._forward_hooks \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;28mself\u001b[39m._forward_pre_hooks\n\u001b[32m 1792\u001b[39m \u001b[38;5;129;01mor\u001b[39;00m _global_backward_pre_hooks \u001b[38;5;129;01mor\u001b[39;00m _global_backward_hooks\n\u001b[32m 1793\u001b[39m \u001b[38;5;129;01mor\u001b[39;00m _global_forward_hooks \u001b[38;5;129;01mor\u001b[39;00m _global_forward_pre_hooks):\n\u001b[32m-> \u001b[39m\u001b[32m1794\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[30;43mforward_call\u001b[39;49m\u001b[30;43m(\u001b[39;49m\u001b[30;43m*\u001b[39;49m\u001b[30;43margs\u001b[39;49m\u001b[30;43m,\u001b[39;49m\u001b[30;43m \u001b[39;49m\u001b[30;43m*\u001b[39;49m\u001b[30;43m*\u001b[39;49m\u001b[30;43mkwargs\u001b[39;49m\u001b[30;43m)\u001b[39;49m\n\u001b[32m 1796\u001b[39m result = \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[32m 1797\u001b[39m called_always_called_hooks = \u001b[38;5;28mset\u001b[39m()\n", "\u001b[36mFile \u001b[39m\u001b[32m~\\AppData\\Local\\Python\\pythoncore-3.14-64\\Lib\\site-packages\\torch\\nn\\modules\\container.py:259\u001b[39m, in \u001b[36mSequential.forward\u001b[39m\u001b[34m(self, input)\u001b[39m\n\u001b[32m 255\u001b[39m \u001b[38;5;250m\u001b[39m\u001b[33;03m\"\"\"\u001b[39;00m\n\u001b[32m 256\u001b[39m \u001b[33;03mRuns the forward pass.\u001b[39;00m\n\u001b[32m 257\u001b[39m \u001b[33;03m\"\"\"\u001b[39;00m\n\u001b[32m 258\u001b[39m \u001b[38;5;28;01mfor\u001b[39;00m module \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m:\n\u001b[32m--> \u001b[39m\u001b[32m259\u001b[39m \u001b[38;5;28minput\u001b[39m = \u001b[30;43mmodule\u001b[39;49m\u001b[30;43m(\u001b[39;49m\u001b[30;43minput\u001b[39;49m\u001b[30;43m)\u001b[39;49m\n\u001b[32m 260\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28minput\u001b[39m\n", "\u001b[36mFile \u001b[39m\u001b[32m~\\AppData\\Local\\Python\\pythoncore-3.14-64\\Lib\\site-packages\\torch\\nn\\modules\\module.py:1783\u001b[39m, in \u001b[36mModule._wrapped_call_impl\u001b[39m\u001b[34m(self, *args, **kwargs)\u001b[39m\n\u001b[32m 1781\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28mself\u001b[39m._compiled_call_impl(*args, **kwargs) \u001b[38;5;66;03m# type: ignore[misc]\u001b[39;00m\n\u001b[32m 1782\u001b[39m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[32m-> \u001b[39m\u001b[32m1783\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[30;43mself\u001b[39;49m\u001b[30;43m.\u001b[39;49m\u001b[30;43m_call_impl\u001b[39;49m\u001b[30;43m(\u001b[39;49m\u001b[30;43m*\u001b[39;49m\u001b[30;43margs\u001b[39;49m\u001b[30;43m,\u001b[39;49m\u001b[30;43m \u001b[39;49m\u001b[30;43m*\u001b[39;49m\u001b[30;43m*\u001b[39;49m\u001b[30;43mkwargs\u001b[39;49m\u001b[30;43m)\u001b[39;49m\n", "\u001b[36mFile \u001b[39m\u001b[32m~\\AppData\\Local\\Python\\pythoncore-3.14-64\\Lib\\site-packages\\torch\\nn\\modules\\module.py:1794\u001b[39m, in \u001b[36mModule._call_impl\u001b[39m\u001b[34m(self, *args, **kwargs)\u001b[39m\n\u001b[32m 1789\u001b[39m \u001b[38;5;66;03m# If we don't have any hooks, we want to skip the rest of the logic in\u001b[39;00m\n\u001b[32m 1790\u001b[39m \u001b[38;5;66;03m# this function, and just call forward.\u001b[39;00m\n\u001b[32m 1791\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m (\u001b[38;5;28mself\u001b[39m._backward_hooks \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;28mself\u001b[39m._backward_pre_hooks \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;28mself\u001b[39m._forward_hooks \u001b[38;5;129;01mor\u001b[39;00m \u001b[38;5;28mself\u001b[39m._forward_pre_hooks\n\u001b[32m 1792\u001b[39m \u001b[38;5;129;01mor\u001b[39;00m _global_backward_pre_hooks \u001b[38;5;129;01mor\u001b[39;00m _global_backward_hooks\n\u001b[32m 1793\u001b[39m \u001b[38;5;129;01mor\u001b[39;00m _global_forward_hooks \u001b[38;5;129;01mor\u001b[39;00m _global_forward_pre_hooks):\n\u001b[32m-> \u001b[39m\u001b[32m1794\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[30;43mforward_call\u001b[39;49m\u001b[30;43m(\u001b[39;49m\u001b[30;43m*\u001b[39;49m\u001b[30;43margs\u001b[39;49m\u001b[30;43m,\u001b[39;49m\u001b[30;43m \u001b[39;49m\u001b[30;43m*\u001b[39;49m\u001b[30;43m*\u001b[39;49m\u001b[30;43mkwargs\u001b[39;49m\u001b[30;43m)\u001b[39;49m\n\u001b[32m 1796\u001b[39m result = \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[32m 1797\u001b[39m called_always_called_hooks = \u001b[38;5;28mset\u001b[39m()\n", "\u001b[36mFile \u001b[39m\u001b[32m~\\AppData\\Local\\Python\\pythoncore-3.14-64\\Lib\\site-packages\\torch\\nn\\modules\\linear.py:134\u001b[39m, in \u001b[36mLinear.forward\u001b[39m\u001b[34m(self, input)\u001b[39m\n\u001b[32m 130\u001b[39m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34mforward\u001b[39m(\u001b[38;5;28mself\u001b[39m, \u001b[38;5;28minput\u001b[39m: Tensor) -> Tensor:\n\u001b[32m 131\u001b[39m \u001b[38;5;250m \u001b[39m\u001b[33;03m\"\"\"\u001b[39;00m\n\u001b[32m 132\u001b[39m \u001b[33;03m Runs the forward pass.\u001b[39;00m\n\u001b[32m 133\u001b[39m \u001b[33;03m \"\"\"\u001b[39;00m\n\u001b[32m--> \u001b[39m\u001b[32m134\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[30;43mF\u001b[39;49m\u001b[30;43m.\u001b[39;49m\u001b[30;43mlinear\u001b[39;49m\u001b[30;43m(\u001b[39;49m\u001b[30;43minput\u001b[39;49m\u001b[30;43m,\u001b[39;49m\u001b[30;43m \u001b[39;49m\u001b[30;43mself\u001b[39;49m\u001b[30;43m.\u001b[39;49m\u001b[30;43mweight\u001b[39;49m\u001b[30;43m,\u001b[39;49m\u001b[30;43m \u001b[39;49m\u001b[30;43mself\u001b[39;49m\u001b[30;43m.\u001b[39;49m\u001b[30;43mbias\u001b[39;49m\u001b[30;43m)\u001b[39;49m\n", "\u001b[31mRuntimeError\u001b[39m: mat1 and mat2 shapes cannot be multiplied (28800x150 and 67500x128)" "\u001b[36mFile \u001b[39m\u001b[32m~\\AppData\\Local\\Python\\pythoncore-3.14-64\\Lib\\site-packages\\torch\\nn\\modules\\conv.py:565\u001b[39m, in \u001b[36mConv2d.forward\u001b[39m\u001b[34m(self, input)\u001b[39m\n\u001b[32m 564\u001b[39m \u001b[38;5;28;01mdef\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34mforward\u001b[39m(\u001b[38;5;28mself\u001b[39m, \u001b[38;5;28minput\u001b[39m: Tensor) -> Tensor:\n\u001b[32m--> \u001b[39m\u001b[32m565\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[30;43mself\u001b[39;49m\u001b[30;43m.\u001b[39;49m\u001b[30;43m_conv_forward\u001b[39;49m\u001b[30;43m(\u001b[39;49m\u001b[30;43minput\u001b[39;49m\u001b[30;43m,\u001b[39;49m\u001b[30;43m \u001b[39;49m\u001b[30;43mself\u001b[39;49m\u001b[30;43m.\u001b[39;49m\u001b[30;43mweight\u001b[39;49m\u001b[30;43m,\u001b[39;49m\u001b[30;43m \u001b[39;49m\u001b[30;43mself\u001b[39;49m\u001b[30;43m.\u001b[39;49m\u001b[30;43mbias\u001b[39;49m\u001b[30;43m)\u001b[39;49m\n", "\u001b[36mFile \u001b[39m\u001b[32m~\\AppData\\Local\\Python\\pythoncore-3.14-64\\Lib\\site-packages\\torch\\nn\\modules\\conv.py:560\u001b[39m, in \u001b[36mConv2d._conv_forward\u001b[39m\u001b[34m(self, input, weight, bias)\u001b[39m\n\u001b[32m 547\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m.padding_mode != \u001b[33m\"\u001b[39m\u001b[33mzeros\u001b[39m\u001b[33m\"\u001b[39m:\n\u001b[32m 548\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m F.conv2d(\n\u001b[32m 549\u001b[39m F.pad(\n\u001b[32m 550\u001b[39m \u001b[38;5;28minput\u001b[39m, \u001b[38;5;28mself\u001b[39m._reversed_padding_repeated_twice, mode=\u001b[38;5;28mself\u001b[39m.padding_mode\n\u001b[32m (...)\u001b[39m\u001b[32m 557\u001b[39m \u001b[38;5;28mself\u001b[39m.groups,\n\u001b[32m 558\u001b[39m )\n\u001b[32m--> \u001b[39m\u001b[32m560\u001b[39m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[30;43mF\u001b[39;49m\u001b[30;43m.\u001b[39;49m\u001b[30;43mconv2d\u001b[39;49m\u001b[30;43m(\u001b[39;49m\n\u001b[32m 561\u001b[39m \u001b[30;43m \u001b[39;49m\u001b[30;43minput\u001b[39;49m\u001b[30;43m,\u001b[39;49m\u001b[30;43m \u001b[39;49m\u001b[30;43mweight\u001b[39;49m\u001b[30;43m,\u001b[39;49m\u001b[30;43m \u001b[39;49m\u001b[30;43mbias\u001b[39;49m\u001b[30;43m,\u001b[39;49m\u001b[30;43m \u001b[39;49m\u001b[30;43mself\u001b[39;49m\u001b[30;43m.\u001b[39;49m\u001b[30;43mstride\u001b[39;49m\u001b[30;43m,\u001b[39;49m\u001b[30;43m \u001b[39;49m\u001b[30;43mself\u001b[39;49m\u001b[30;43m.\u001b[39;49m\u001b[30;43mpadding\u001b[39;49m\u001b[30;43m,\u001b[39;49m\u001b[30;43m \u001b[39;49m\u001b[30;43mself\u001b[39;49m\u001b[30;43m.\u001b[39;49m\u001b[30;43mdilation\u001b[39;49m\u001b[30;43m,\u001b[39;49m\u001b[30;43m \u001b[39;49m\u001b[30;43mself\u001b[39;49m\u001b[30;43m.\u001b[39;49m\u001b[30;43mgroups\u001b[39;49m\n\u001b[32m 562\u001b[39m \u001b[30;43m\u001b[39;49m\u001b[30;43m)\u001b[39;49m\n", "\u001b[31mRuntimeError\u001b[39m: Given groups=1, weight of size [32, 3, 3, 3], expected input[64, 150, 3, 150] to have 3 channels, but got 150 channels instead" ] } ],39 unmodified lines " total_test = 0\n", "\n", " with torch.inference_mode():\n", " for images, labels in test_loader:\n", " for images, labels in datalaoder:\n", " images = images.to(device)\n", " labels = labels.to(device)\n", "\n",PyTorchtrained.ipynb+65-65