{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "e9tLVH2veLrg", "outputId": "d7d0d808-46aa-40db-be05-5d27d2e26bce" }, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Requirement already satisfied: torchvision in /usr/local/lib/python3.10/dist-packages (0.18.0+cu121)\n", "Requirement already satisfied: numpy in /usr/local/lib/python3.10/dist-packages (from torchvision) (1.25.2)\n", "Requirement already satisfied: torch==2.3.0 in /usr/local/lib/python3.10/dist-packages (from torchvision) (2.3.0+cu121)\n", "Requirement already satisfied: pillow!=8.3.*,>=5.3.0 in /usr/local/lib/python3.10/dist-packages (from torchvision) (9.4.0)\n", "Requirement already satisfied: filelock in /usr/local/lib/python3.10/dist-packages (from torch==2.3.0->torchvision) (3.14.0)\n", "Requirement already satisfied: typing-extensions>=4.8.0 in /usr/local/lib/python3.10/dist-packages (from torch==2.3.0->torchvision) (4.12.2)\n", "Requirement already satisfied: sympy in /usr/local/lib/python3.10/dist-packages (from torch==2.3.0->torchvision) (1.12.1)\n", "Requirement already satisfied: networkx in /usr/local/lib/python3.10/dist-packages (from torch==2.3.0->torchvision) (3.3)\n", "Requirement already satisfied: jinja2 in /usr/local/lib/python3.10/dist-packages (from torch==2.3.0->torchvision) (3.1.4)\n", "Requirement already satisfied: fsspec in /usr/local/lib/python3.10/dist-packages (from torch==2.3.0->torchvision) (2023.6.0)\n", "Collecting nvidia-cuda-nvrtc-cu12==12.1.105 (from torch==2.3.0->torchvision)\n", " Using cached nvidia_cuda_nvrtc_cu12-12.1.105-py3-none-manylinux1_x86_64.whl (23.7 MB)\n", "Collecting nvidia-cuda-runtime-cu12==12.1.105 (from torch==2.3.0->torchvision)\n", " Using cached nvidia_cuda_runtime_cu12-12.1.105-py3-none-manylinux1_x86_64.whl (823 kB)\n", "Collecting nvidia-cuda-cupti-cu12==12.1.105 (from torch==2.3.0->torchvision)\n", " Using cached nvidia_cuda_cupti_cu12-12.1.105-py3-none-manylinux1_x86_64.whl (14.1 MB)\n", "Collecting nvidia-cudnn-cu12==8.9.2.26 (from torch==2.3.0->torchvision)\n", " Using cached nvidia_cudnn_cu12-8.9.2.26-py3-none-manylinux1_x86_64.whl (731.7 MB)\n", "Collecting nvidia-cublas-cu12==12.1.3.1 (from torch==2.3.0->torchvision)\n", " Using cached nvidia_cublas_cu12-12.1.3.1-py3-none-manylinux1_x86_64.whl (410.6 MB)\n", "Collecting nvidia-cufft-cu12==11.0.2.54 (from torch==2.3.0->torchvision)\n", " Using cached nvidia_cufft_cu12-11.0.2.54-py3-none-manylinux1_x86_64.whl (121.6 MB)\n", "Collecting nvidia-curand-cu12==10.3.2.106 (from torch==2.3.0->torchvision)\n", " Using cached nvidia_curand_cu12-10.3.2.106-py3-none-manylinux1_x86_64.whl (56.5 MB)\n", "Collecting nvidia-cusolver-cu12==11.4.5.107 (from torch==2.3.0->torchvision)\n", " Using cached nvidia_cusolver_cu12-11.4.5.107-py3-none-manylinux1_x86_64.whl (124.2 MB)\n", "Collecting nvidia-cusparse-cu12==12.1.0.106 (from torch==2.3.0->torchvision)\n", " Using cached nvidia_cusparse_cu12-12.1.0.106-py3-none-manylinux1_x86_64.whl (196.0 MB)\n", "Collecting nvidia-nccl-cu12==2.20.5 (from torch==2.3.0->torchvision)\n", " Using cached nvidia_nccl_cu12-2.20.5-py3-none-manylinux2014_x86_64.whl (176.2 MB)\n", "Collecting nvidia-nvtx-cu12==12.1.105 (from torch==2.3.0->torchvision)\n", " Using cached nvidia_nvtx_cu12-12.1.105-py3-none-manylinux1_x86_64.whl (99 kB)\n", "Requirement already satisfied: triton==2.3.0 in /usr/local/lib/python3.10/dist-packages (from torch==2.3.0->torchvision) (2.3.0)\n", "Collecting nvidia-nvjitlink-cu12 (from nvidia-cusolver-cu12==11.4.5.107->torch==2.3.0->torchvision)\n", " Downloading nvidia_nvjitlink_cu12-12.5.40-py3-none-manylinux2014_x86_64.whl (21.3 MB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m21.3/21.3 MB\u001b[0m \u001b[31m22.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hRequirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.10/dist-packages (from jinja2->torch==2.3.0->torchvision) (2.1.5)\n", "Requirement already satisfied: mpmath<1.4.0,>=1.1.0 in /usr/local/lib/python3.10/dist-packages (from sympy->torch==2.3.0->torchvision) (1.3.0)\n", "Installing collected packages: nvidia-nvtx-cu12, nvidia-nvjitlink-cu12, nvidia-nccl-cu12, nvidia-curand-cu12, nvidia-cufft-cu12, nvidia-cuda-runtime-cu12, nvidia-cuda-nvrtc-cu12, nvidia-cuda-cupti-cu12, nvidia-cublas-cu12, nvidia-cusparse-cu12, nvidia-cudnn-cu12, nvidia-cusolver-cu12\n", "Successfully installed nvidia-cublas-cu12-12.1.3.1 nvidia-cuda-cupti-cu12-12.1.105 nvidia-cuda-nvrtc-cu12-12.1.105 nvidia-cuda-runtime-cu12-12.1.105 nvidia-cudnn-cu12-8.9.2.26 nvidia-cufft-cu12-11.0.2.54 nvidia-curand-cu12-10.3.2.106 nvidia-cusolver-cu12-11.4.5.107 nvidia-cusparse-cu12-12.1.0.106 nvidia-nccl-cu12-2.20.5 nvidia-nvjitlink-cu12-12.5.40 nvidia-nvtx-cu12-12.1.105\n" ] }, { "output_type": "execute_result", "data": { "text/plain": [ "['AlexNet',\n", " 'AlexNet_Weights',\n", " 'ConvNeXt',\n", " 'ConvNeXt_Base_Weights',\n", " 'ConvNeXt_Large_Weights',\n", " 'ConvNeXt_Small_Weights',\n", " 'ConvNeXt_Tiny_Weights',\n", " 'DenseNet',\n", " 'DenseNet121_Weights',\n", " 'DenseNet161_Weights',\n", " 'DenseNet169_Weights',\n", " 'DenseNet201_Weights',\n", " 'EfficientNet',\n", " 'EfficientNet_B0_Weights',\n", " 'EfficientNet_B1_Weights',\n", " 'EfficientNet_B2_Weights',\n", " 'EfficientNet_B3_Weights',\n", " 'EfficientNet_B4_Weights',\n", " 'EfficientNet_B5_Weights',\n", " 'EfficientNet_B6_Weights',\n", " 'EfficientNet_B7_Weights',\n", " 'EfficientNet_V2_L_Weights',\n", " 'EfficientNet_V2_M_Weights',\n", " 'EfficientNet_V2_S_Weights',\n", " 'GoogLeNet',\n", " 'GoogLeNetOutputs',\n", " 'GoogLeNet_Weights',\n", " 'Inception3',\n", " 'InceptionOutputs',\n", " 'Inception_V3_Weights',\n", " 'MNASNet',\n", " 'MNASNet0_5_Weights',\n", " 'MNASNet0_75_Weights',\n", " 'MNASNet1_0_Weights',\n", " 'MNASNet1_3_Weights',\n", " 'MaxVit',\n", " 'MaxVit_T_Weights',\n", " 'MobileNetV2',\n", " 'MobileNetV3',\n", " 'MobileNet_V2_Weights',\n", " 'MobileNet_V3_Large_Weights',\n", " 'MobileNet_V3_Small_Weights',\n", " 'RegNet',\n", " 'RegNet_X_16GF_Weights',\n", " 'RegNet_X_1_6GF_Weights',\n", " 'RegNet_X_32GF_Weights',\n", " 'RegNet_X_3_2GF_Weights',\n", " 'RegNet_X_400MF_Weights',\n", " 'RegNet_X_800MF_Weights',\n", " 'RegNet_X_8GF_Weights',\n", " 'RegNet_Y_128GF_Weights',\n", " 'RegNet_Y_16GF_Weights',\n", " 'RegNet_Y_1_6GF_Weights',\n", " 'RegNet_Y_32GF_Weights',\n", " 'RegNet_Y_3_2GF_Weights',\n", " 'RegNet_Y_400MF_Weights',\n", " 'RegNet_Y_800MF_Weights',\n", " 'RegNet_Y_8GF_Weights',\n", " 'ResNeXt101_32X8D_Weights',\n", " 'ResNeXt101_64X4D_Weights',\n", " 'ResNeXt50_32X4D_Weights',\n", " 'ResNet',\n", " 'ResNet101_Weights',\n", " 'ResNet152_Weights',\n", " 'ResNet18_Weights',\n", " 'ResNet34_Weights',\n", " 'ResNet50_Weights',\n", " 'ShuffleNetV2',\n", " 'ShuffleNet_V2_X0_5_Weights',\n", " 'ShuffleNet_V2_X1_0_Weights',\n", " 'ShuffleNet_V2_X1_5_Weights',\n", " 'ShuffleNet_V2_X2_0_Weights',\n", " 'SqueezeNet',\n", " 'SqueezeNet1_0_Weights',\n", " 'SqueezeNet1_1_Weights',\n", " 'SwinTransformer',\n", " 'Swin_B_Weights',\n", " 'Swin_S_Weights',\n", " 'Swin_T_Weights',\n", " 'Swin_V2_B_Weights',\n", " 'Swin_V2_S_Weights',\n", " 'Swin_V2_T_Weights',\n", " 'VGG',\n", " 'VGG11_BN_Weights',\n", " 'VGG11_Weights',\n", " 'VGG13_BN_Weights',\n", " 'VGG13_Weights',\n", " 'VGG16_BN_Weights',\n", " 'VGG16_Weights',\n", " 'VGG19_BN_Weights',\n", " 'VGG19_Weights',\n", " 'ViT_B_16_Weights',\n", " 'ViT_B_32_Weights',\n", " 'ViT_H_14_Weights',\n", " 'ViT_L_16_Weights',\n", " 'ViT_L_32_Weights',\n", " 'VisionTransformer',\n", " 'Weights',\n", " 'WeightsEnum',\n", " 'Wide_ResNet101_2_Weights',\n", " 'Wide_ResNet50_2_Weights',\n", " '_GoogLeNetOutputs',\n", " '_InceptionOutputs',\n", " '__builtins__',\n", " '__cached__',\n", " '__doc__',\n", " '__file__',\n", " '__loader__',\n", " '__name__',\n", " '__package__',\n", " '__path__',\n", " '__spec__',\n", " '_api',\n", " '_meta',\n", " '_utils',\n", " 'alexnet',\n", " 'convnext',\n", " 'convnext_base',\n", " 'convnext_large',\n", " 'convnext_small',\n", " 'convnext_tiny',\n", " 'densenet',\n", " 'densenet121',\n", " 'densenet161',\n", " 'densenet169',\n", " 'densenet201',\n", " 'detection',\n", " 'efficientnet',\n", " 'efficientnet_b0',\n", " 'efficientnet_b1',\n", " 'efficientnet_b2',\n", " 'efficientnet_b3',\n", " 'efficientnet_b4',\n", " 'efficientnet_b5',\n", " 'efficientnet_b6',\n", " 'efficientnet_b7',\n", " 'efficientnet_v2_l',\n", " 'efficientnet_v2_m',\n", " 'efficientnet_v2_s',\n", " 'get_model',\n", " 'get_model_builder',\n", " 'get_model_weights',\n", " 'get_weight',\n", " 'googlenet',\n", " 'inception',\n", " 'inception_v3',\n", " 'list_models',\n", " 'maxvit',\n", " 'maxvit_t',\n", " 'mnasnet',\n", " 'mnasnet0_5',\n", " 'mnasnet0_75',\n", " 'mnasnet1_0',\n", " 'mnasnet1_3',\n", " 'mobilenet',\n", " 'mobilenet_v2',\n", " 'mobilenet_v3_large',\n", " 'mobilenet_v3_small',\n", " 'mobilenetv2',\n", " 'mobilenetv3',\n", " 'optical_flow',\n", " 'quantization',\n", " 'regnet',\n", " 'regnet_x_16gf',\n", " 'regnet_x_1_6gf',\n", " 'regnet_x_32gf',\n", " 'regnet_x_3_2gf',\n", " 'regnet_x_400mf',\n", " 'regnet_x_800mf',\n", " 'regnet_x_8gf',\n", " 'regnet_y_128gf',\n", " 'regnet_y_16gf',\n", " 'regnet_y_1_6gf',\n", " 'regnet_y_32gf',\n", " 'regnet_y_3_2gf',\n", " 'regnet_y_400mf',\n", " 'regnet_y_800mf',\n", " 'regnet_y_8gf',\n", " 'resnet',\n", " 'resnet101',\n", " 'resnet152',\n", " 'resnet18',\n", " 'resnet34',\n", " 'resnet50',\n", " 'resnext101_32x8d',\n", " 'resnext101_64x4d',\n", " 'resnext50_32x4d',\n", " 'segmentation',\n", " 'shufflenet_v2_x0_5',\n", " 'shufflenet_v2_x1_0',\n", " 'shufflenet_v2_x1_5',\n", " 'shufflenet_v2_x2_0',\n", " 'shufflenetv2',\n", " 'squeezenet',\n", " 'squeezenet1_0',\n", " 'squeezenet1_1',\n", " 'swin_b',\n", " 'swin_s',\n", " 'swin_t',\n", " 'swin_transformer',\n", " 'swin_v2_b',\n", " 'swin_v2_s',\n", " 'swin_v2_t',\n", " 'vgg',\n", " 'vgg11',\n", " 'vgg11_bn',\n", " 'vgg13',\n", " 'vgg13_bn',\n", " 'vgg16',\n", " 'vgg16_bn',\n", " 'vgg19',\n", " 'vgg19_bn',\n", " 'video',\n", " 'vision_transformer',\n", " 'vit_b_16',\n", " 'vit_b_32',\n", " 'vit_h_14',\n", " 'vit_l_16',\n", " 'vit_l_32',\n", " 'wide_resnet101_2',\n", " 'wide_resnet50_2']" ] }, "metadata": {}, "execution_count": 1 } ], "source": [ "#Loading Pre-Trained Network using TorchVision\n", "!pip install torchvision\n", "from torchvision import models\n", "import torch\n", "\n", "dir(models)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "48_BUp-Kfrn-", "colab": { "base_uri": "https://localhost:8080/" }, "outputId": "8c759ed5-ead3-4490-e22b-39c9066aa86a" }, "outputs": [ { "output_type": "stream", "name": "stderr", "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=AlexNet_Weights.IMAGENET1K_V1`. You can also use `weights=AlexNet_Weights.DEFAULT` to get the most up-to-date weights.\n", " warnings.warn(msg)\n", "Downloading: \"https://download.pytorch.org/models/alexnet-owt-7be5be79.pth\" to /root/.cache/torch/hub/checkpoints/alexnet-owt-7be5be79.pth\n", "100%|██████████| 233M/233M [00:01<00:00, 124MB/s]\n" ] } ], "source": [ "# Using AlexNet for Image Classification\n", "# Load the pre-trained model\n", "alexnet = models.alexnet(pretrained=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "M4Lkuk4lgDMJ", "outputId": "190a9c05-9c27-46ec-fac4-602cc6dddce7" }, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "AlexNet(\n", " (features): Sequential(\n", " (0): Conv2d(3, 64, kernel_size=(11, 11), stride=(4, 4), padding=(2, 2))\n", " (1): ReLU(inplace=True)\n", " (2): MaxPool2d(kernel_size=3, stride=2, padding=0, dilation=1, ceil_mode=False)\n", " (3): Conv2d(64, 192, kernel_size=(5, 5), stride=(1, 1), padding=(2, 2))\n", " (4): ReLU(inplace=True)\n", " (5): MaxPool2d(kernel_size=3, stride=2, padding=0, dilation=1, ceil_mode=False)\n", " (6): Conv2d(192, 384, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", " (7): ReLU(inplace=True)\n", " (8): Conv2d(384, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", " (9): ReLU(inplace=True)\n", " (10): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))\n", " (11): ReLU(inplace=True)\n", " (12): MaxPool2d(kernel_size=3, stride=2, padding=0, dilation=1, ceil_mode=False)\n", " )\n", " (avgpool): AdaptiveAvgPool2d(output_size=(6, 6))\n", " (classifier): Sequential(\n", " (0): Dropout(p=0.5, inplace=False)\n", " (1): Linear(in_features=9216, out_features=4096, bias=True)\n", " (2): ReLU(inplace=True)\n", " (3): Dropout(p=0.5, inplace=False)\n", " (4): Linear(in_features=4096, out_features=4096, bias=True)\n", " (5): ReLU(inplace=True)\n", " (6): Linear(in_features=4096, out_features=1000, bias=True)\n", " )\n", ")\n" ] } ], "source": [ "print(alexnet)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "BYGBAm4bgRrG" }, "outputs": [], "source": [ "#make sure that data transforms into the right shape\n", "from torchvision import transforms\n", "transform = transforms.Compose([\n", " transforms.Resize(256),\n", " transforms.CenterCrop(224),\n", " transforms.ToTensor(),\n", " transforms.Normalize(\n", " mean=[0.485, 0.456, 0.406],\n", " std=[0.229, 0.224, 0.225]\n", " )])" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "QjAr0XAw4y8S", "outputId": "523c603e-f6e0-4ee5-a4c4-736f97e5975e" }, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Mounted at /content/gdrive\n" ] } ], "source": [ "#connect colab to google drive\n", "from google.colab import drive\n", "drive.mount('/content/gdrive')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "UrVD0SbACHrd", "outputId": "4ef343c7-2bc2-4d34-ea31-d9c7a11ef3e3" }, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Collecting pixellib==0.5.2\n", " Downloading pixellib-0.5.2-py3-none-any.whl (66 kB)\n", "\u001b[?25l \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m0.0/66.9 kB\u001b[0m \u001b[31m?\u001b[0m eta \u001b[36m-:--:--\u001b[0m\r\u001b[2K \u001b[91m━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[90m╺\u001b[0m\u001b[90m━━━━━━━━━━━━━━━\u001b[0m \u001b[32m41.0/66.9 kB\u001b[0m \u001b[31m1.1 MB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\r\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m66.9/66.9 kB\u001b[0m \u001b[31m1.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hRequirement already satisfied: pillow in /usr/local/lib/python3.10/dist-packages (from pixellib==0.5.2) (9.4.0)\n", "Requirement already satisfied: scikit-image in /usr/local/lib/python3.10/dist-packages (from pixellib==0.5.2) (0.19.3)\n", "Requirement already satisfied: opencv-python in /usr/local/lib/python3.10/dist-packages (from pixellib==0.5.2) (4.8.0.76)\n", "Requirement already satisfied: matplotlib in /usr/local/lib/python3.10/dist-packages (from pixellib==0.5.2) (3.7.1)\n", "Requirement already satisfied: imgaug in /usr/local/lib/python3.10/dist-packages (from pixellib==0.5.2) (0.4.0)\n", "Collecting labelme2coco (from pixellib==0.5.2)\n", " Downloading labelme2coco-0.2.6-py3-none-any.whl (19 kB)\n", "Collecting imantics (from pixellib==0.5.2)\n", " Downloading imantics-0.1.12.tar.gz (13 kB)\n", " Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n", "Requirement already satisfied: numpy in /usr/local/lib/python3.10/dist-packages (from imantics->pixellib==0.5.2) (1.25.2)\n", "Requirement already satisfied: lxml in /usr/local/lib/python3.10/dist-packages (from imantics->pixellib==0.5.2) (4.9.4)\n", "Collecting xmljson (from imantics->pixellib==0.5.2)\n", " Downloading xmljson-0.2.1-py2.py3-none-any.whl (10 kB)\n", "Requirement already satisfied: six in /usr/local/lib/python3.10/dist-packages (from imgaug->pixellib==0.5.2) (1.16.0)\n", "Requirement already satisfied: scipy in /usr/local/lib/python3.10/dist-packages (from imgaug->pixellib==0.5.2) (1.11.4)\n", "Requirement already satisfied: imageio in /usr/local/lib/python3.10/dist-packages (from imgaug->pixellib==0.5.2) (2.31.6)\n", "Requirement already satisfied: Shapely in /usr/local/lib/python3.10/dist-packages (from imgaug->pixellib==0.5.2) (2.0.4)\n", "Requirement already satisfied: networkx>=2.2 in /usr/local/lib/python3.10/dist-packages (from scikit-image->pixellib==0.5.2) (3.3)\n", "Requirement already satisfied: tifffile>=2019.7.26 in /usr/local/lib/python3.10/dist-packages (from scikit-image->pixellib==0.5.2) (2024.5.22)\n", "Requirement already satisfied: PyWavelets>=1.1.1 in /usr/local/lib/python3.10/dist-packages (from scikit-image->pixellib==0.5.2) (1.6.0)\n", "Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.10/dist-packages (from scikit-image->pixellib==0.5.2) (24.1)\n", "Collecting sahi>=0.8.19 (from labelme2coco->pixellib==0.5.2)\n", " Downloading sahi-0.11.16-py3-none-any.whl (112 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m112.6/112.6 kB\u001b[0m \u001b[31m5.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hRequirement already satisfied: jsonschema>=2.6.0 in /usr/local/lib/python3.10/dist-packages (from labelme2coco->pixellib==0.5.2) (4.19.2)\n", "Requirement already satisfied: contourpy>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib->pixellib==0.5.2) (1.2.1)\n", "Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.10/dist-packages (from matplotlib->pixellib==0.5.2) (0.12.1)\n", "Requirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib->pixellib==0.5.2) (4.53.0)\n", "Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib->pixellib==0.5.2) (1.4.5)\n", "Requirement already satisfied: pyparsing>=2.3.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib->pixellib==0.5.2) (3.1.2)\n", "Requirement already satisfied: python-dateutil>=2.7 in /usr/local/lib/python3.10/dist-packages (from matplotlib->pixellib==0.5.2) (2.8.2)\n", "Requirement already satisfied: attrs>=22.2.0 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=2.6.0->labelme2coco->pixellib==0.5.2) (23.2.0)\n", "Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=2.6.0->labelme2coco->pixellib==0.5.2) (2023.12.1)\n", "Requirement already satisfied: referencing>=0.28.4 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=2.6.0->labelme2coco->pixellib==0.5.2) (0.35.1)\n", "Requirement already satisfied: rpds-py>=0.7.1 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=2.6.0->labelme2coco->pixellib==0.5.2) (0.18.1)\n", "Requirement already satisfied: tqdm>=4.48.2 in /usr/local/lib/python3.10/dist-packages (from sahi>=0.8.19->labelme2coco->pixellib==0.5.2) (4.66.4)\n", "Collecting pybboxes==0.1.6 (from sahi>=0.8.19->labelme2coco->pixellib==0.5.2)\n", " Downloading pybboxes-0.1.6-py3-none-any.whl (24 kB)\n", "Requirement already satisfied: pyyaml in /usr/local/lib/python3.10/dist-packages (from sahi>=0.8.19->labelme2coco->pixellib==0.5.2) (6.0.1)\n", "Collecting fire (from sahi>=0.8.19->labelme2coco->pixellib==0.5.2)\n", " Downloading fire-0.6.0.tar.gz (88 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m88.4/88.4 kB\u001b[0m \u001b[31m8.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25h Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n", "Collecting terminaltables (from sahi>=0.8.19->labelme2coco->pixellib==0.5.2)\n", " Downloading terminaltables-3.1.10-py2.py3-none-any.whl (15 kB)\n", "Requirement already satisfied: requests in /usr/local/lib/python3.10/dist-packages (from sahi>=0.8.19->labelme2coco->pixellib==0.5.2) (2.31.0)\n", "Requirement already satisfied: click in /usr/local/lib/python3.10/dist-packages (from sahi>=0.8.19->labelme2coco->pixellib==0.5.2) (8.1.7)\n", "Requirement already satisfied: termcolor in /usr/local/lib/python3.10/dist-packages (from fire->sahi>=0.8.19->labelme2coco->pixellib==0.5.2) (2.4.0)\n", "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests->sahi>=0.8.19->labelme2coco->pixellib==0.5.2) (3.3.2)\n", "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests->sahi>=0.8.19->labelme2coco->pixellib==0.5.2) (3.7)\n", "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests->sahi>=0.8.19->labelme2coco->pixellib==0.5.2) (2.0.7)\n", "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests->sahi>=0.8.19->labelme2coco->pixellib==0.5.2) (2024.6.2)\n", "Building wheels for collected packages: imantics, fire\n", " Building wheel for imantics (setup.py) ... \u001b[?25l\u001b[?25hdone\n", " Created wheel for imantics: filename=imantics-0.1.12-py3-none-any.whl size=16010 sha256=7d817e9d50811bc57f5430a56a85b68bdd80eb6c1bf29c0162c164ea5437ecc8\n", " Stored in directory: /root/.cache/pip/wheels/56/6a/be/4c60e88b14abec4e93234a1f7f91ce8abe1ae88a2b3eaad3ac\n", " Building wheel for fire (setup.py) ... \u001b[?25l\u001b[?25hdone\n", " Created wheel for fire: filename=fire-0.6.0-py2.py3-none-any.whl size=117029 sha256=7d054fa215963197dcfe0f04d1643078abd6b3849d6506532cce27e2499d896d\n", " Stored in directory: /root/.cache/pip/wheels/d6/6d/5d/5b73fa0f46d01a793713f8859201361e9e581ced8c75e5c6a3\n", "Successfully built imantics fire\n", "Installing collected packages: xmljson, terminaltables, pybboxes, fire, sahi, imantics, labelme2coco, pixellib\n", "Successfully installed fire-0.6.0 imantics-0.1.12 labelme2coco-0.2.6 pixellib-0.5.2 pybboxes-0.1.6 sahi-0.11.16 terminaltables-3.1.10 xmljson-0.2.1\n", "Collecting labelme2coco==0.1.0\n", " Downloading labelme2coco-0.1.0-py3-none-any.whl (19 kB)\n", "Requirement already satisfied: numpy>=1.15.1 in /usr/local/lib/python3.10/dist-packages (from labelme2coco==0.1.0) (1.25.2)\n", "Requirement already satisfied: pillow>=4.3.0 in /usr/local/lib/python3.10/dist-packages (from labelme2coco==0.1.0) (9.4.0)\n", "Requirement already satisfied: jsonschema>=2.6.0 in /usr/local/lib/python3.10/dist-packages (from labelme2coco==0.1.0) (4.19.2)\n", "Requirement already satisfied: attrs>=22.2.0 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=2.6.0->labelme2coco==0.1.0) (23.2.0)\n", "Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=2.6.0->labelme2coco==0.1.0) (2023.12.1)\n", "Requirement already satisfied: referencing>=0.28.4 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=2.6.0->labelme2coco==0.1.0) (0.35.1)\n", "Requirement already satisfied: rpds-py>=0.7.1 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=2.6.0->labelme2coco==0.1.0) (0.18.1)\n", "Installing collected packages: labelme2coco\n", " Attempting uninstall: labelme2coco\n", " Found existing installation: labelme2coco 0.2.6\n", " Uninstalling labelme2coco-0.2.6:\n", " Successfully uninstalled labelme2coco-0.2.6\n", "Successfully installed labelme2coco-0.1.0\n" ] } ], "source": [ "!pip install pixellib==0.5.2\n", "!pip install labelme2coco==0.1.0" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "LM8K9V9VEpeb" }, "outputs": [], "source": [ "# Import necessary libraries\n", "import os\n", "from PIL import Image\n", "\n", "# Initialize an empty list to store image information\n", "info = []\n", "# Define the path to the main folder containing the images\n", "main_folder_path = \"/content/gdrive/MyDrive/Orchid-Flowers-Dataset-v1.1/img\"\n", "# Walk through the directory structure starting from the main folder\n", "for root, _, files in os.walk(main_folder_path):\n", " # Iterate over each file in the current directory\n", " for file in files:\n", " # Check if the file is a JPEG image\n", " if file.endswith(\".jpg\"):\n", " # Construct the full path to the image file\n", " img_path = os.path.join(root, file)\n", " # Open the image using PIL\n", " img = Image.open(img_path)\n", " # Append a dictionary containing the image object and its path to the info list\n", " info.append({\"img\": img, \"path\": img_path})\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "cAJhT7DhhOb2" }, "outputs": [], "source": [ "#preprocess\n", "## prepares the image 'img' according to the requirements of the model\n", "img_t = transform(img)\n", "batch_t = torch.unsqueeze(img_t, 0)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "_4pQvaLEhVGG", "outputId": "f04abab6-dca9-456a-f81c-6a6a2b2574df" }, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "torch.Size([1, 1000])\n" ] } ], "source": [ "#Model Inference\n", "#put our model in eval mode.\n", "alexnet.eval()\n", "\n", "out = alexnet(batch_t)\n", "print(out.shape)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "6vwXgG-Khp4g" }, "outputs": [], "source": [ "#get images class\n", "with open('/content/gdrive/MyDrive/Orchid-Flowers-Dataset-v1.1/Multi-label Classification/Multilabel_training.csv') as f:\n", " classes = [line.strip() for line in f.readlines()]" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "oRLrd5igi72e", "outputId": "2c9eb2b8-0e34-4fe1-d201-db8e889202ee" }, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "1328.jpg;Spot;Lobed;Raceme;AFew;White;YellowBrown;24 15.88855266571045\n" ] } ], "source": [ "#find out the max prediction.\n", "_, index = torch.max(out, 1)\n", "\n", "percentage = torch.nn.functional.softmax(out, dim=1)[0] * 100\n", "\n", "print(classes[index[0]], percentage[index[0]].item())\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "UVpTbwpLjk1u", "outputId": "eb37e1df-4673-47b0-fff1-f841c3c82525" }, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "[('1328.jpg;Spot;Lobed;Raceme;AFew;White;YellowBrown;24', 15.88855266571045),\n", " ('59.jpg;Spot;Simple;SingleOrPair;SinglePair;PinkRed;Pink;3',\n", " 13.1360502243042),\n", " ('1253.jpg;Spot;Lobed;Raceme;AFew;White;Green;23', 12.89087963104248),\n", " ('1292.jpg;Spot;Lobed;Raceme;AFew;White;Green;23', 8.40053653717041),\n", " ('381.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 7.234877586364746),\n", " ('366.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 2.4095914363861084),\n", " ('367.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 1.6216557025909424),\n", " ('61.jpg;Spot;Simple;SingleOrPair;SinglePair;PinkRed;Pink;3',\n", " 1.5760637521743774),\n", " ('1336.jpg;Spot;Lobed;Raceme;AFew;White;YellowBrown;24', 1.5720475912094116),\n", " ('21.jpg;Spot;Lobed;Raceme;AFew;PinkRedWhite;White;1', 1.1183711290359497),\n", " ('379.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 1.050938606262207),\n", " ('60.jpg;Spot;Simple;SingleOrPair;SinglePair;PinkRed;Pink;3',\n", " 0.8608635663986206),\n", " ('358.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.819441020488739),\n", " ('19.jpg;Spot;Lobed;Raceme;AFew;PinkRedWhite;White;1', 0.7847009301185608),\n", " ('81.jpg;Spot;Simple;SingleOrPair;SinglePair;PinkRed;Pink;3',\n", " 0.7471103072166443),\n", " ('1260.jpg;Spot;Lobed;Raceme;AFew;White;Green;23', 0.7245150804519653),\n", " ('770.jpg;Spot;Lobed;Raceme;Many;White;YellowBrown;19', 0.7173356413841248),\n", " ('157.jpg;Nospot;Lobed;Raceme;Many;BluePurple;Pink;5', 0.6922218203544617),\n", " ('172.jpg;Nospot;Lobed;Raceme;AFew;BluePurple;Purple;7', 0.6557213068008423),\n", " ('136.jpg;Nospot;Lobed;Raceme;AFew;BluePurple;Pink;4', 0.6397452354431152),\n", " ('382.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.6052159070968628),\n", " ('95.jpg;Spot;Simple;SingleOrPair;SinglePair;PinkRed;Pink;3',\n", " 0.5833677649497986),\n", " ('668.jpg;Nospot;Lobed;Spike;AFew;White;White;13', 0.5295686721801758),\n", " ('76.jpg;Spot;Simple;SingleOrPair;SinglePair;PinkRed;Pink;3',\n", " 0.5227769017219543),\n", " ('140.jpg;Nospot;Lobed;Raceme;Many;BluePurple;Pink;5', 0.5217817425727844),\n", " ('380.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.4721907079219818),\n", " ('656.jpg;Nospot;Lobed;Spike;AFew;White;White;13', 0.45688581466674805),\n", " ('370.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.4555966258049011),\n", " ('374.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.44236528873443604),\n", " ('378.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.44061797857284546),\n", " ('543.jpg;Spot;Pouched;SingleOrPair;SinglePair;PinkRedWhite;Pink;12',\n", " 0.38045161962509155),\n", " ('497.jpg;Spot;Pouched;SingleOrPair;SinglePair;PinkRedWhite;Pink;12',\n", " 0.379602313041687),\n", " ('1254.jpg;Spot;Lobed;Raceme;AFew;White;Green;23', 0.3571322560310364),\n", " ('1092.jpg;Nospot;Simple;Raceme;Many;PinkRed;YellowPurple;22',\n", " 0.3147432208061218),\n", " ('368.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.3100665211677551),\n", " ('6.jpg;Spot;Lobed;Raceme;AFew;PinkRedWhite;White;1', 0.2809280753135681),\n", " ('167.jpg;Spot;Lobed;Raceme;AFew;Green;GreenBrown;6', 0.27919310331344604),\n", " ('1295.jpg;Spot;Lobed;Raceme;AFew;White;Green;23', 0.2738247513771057),\n", " ('66.jpg;Spot;Simple;SingleOrPair;SinglePair;PinkRed;Pink;3',\n", " 0.2725987136363983),\n", " ('418.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.26582586765289307),\n", " ('1278.jpg;Spot;Lobed;Raceme;AFew;White;Green;23', 0.26240798830986023),\n", " ('166.jpg;Spot;Lobed;Raceme;AFew;Green;GreenBrown;6', 0.2560056149959564),\n", " ('72.jpg;Spot;Simple;SingleOrPair;SinglePair;PinkRed;Pink;3',\n", " 0.25269821286201477),\n", " ('3.jpg;Spot;Lobed;Raceme;AFew;PinkRedWhite;White;1', 0.23681098222732544),\n", " ('1291.jpg;Spot;Lobed;Raceme;AFew;White;Green;23', 0.22926069796085358),\n", " ('2.jpg;Spot;Lobed;Raceme;AFew;PinkRedWhite;White;1', 0.2286931574344635),\n", " ('383.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.22630411386489868),\n", " ('1332.jpg;Spot;Lobed;Raceme;AFew;White;YellowBrown;24', 0.2254563570022583),\n", " ('1330.jpg;Spot;Lobed;Raceme;AFew;White;YellowBrown;24', 0.21111786365509033),\n", " ('52.jpg;Spot;Simple;SingleOrPair;SinglePair;PinkRed;Pink;3',\n", " 0.2055903971195221),\n", " ('152.jpg;Nospot;Lobed;Raceme;Many;BluePurple;Pink;5', 0.20558702945709229),\n", " ('879.jpg;Spot;Lobed;Raceme;Many;White;YellowBrown;19', 0.20312798023223877),\n", " ('356.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.20167100429534912),\n", " ('8.jpg;Spot;Lobed;Raceme;AFew;PinkRedWhite;White;1', 0.19924338161945343),\n", " ('24.jpg;Spot;Lobed;Raceme;AFew;PinkRedWhite;White;1', 0.19896815717220306),\n", " ('110.jpg;Spot;Simple;SingleOrPair;SinglePair;PinkRed;Pink;3',\n", " 0.19074273109436035),\n", " ('45.jpg;Spot;Simple;SingleOrPair;SinglePair;PinkRed;Pink;3',\n", " 0.18984097242355347),\n", " ('1333.jpg;Spot;Lobed;Raceme;AFew;White;YellowBrown;24', 0.1873064637184143),\n", " ('7.jpg;Spot;Lobed;Raceme;AFew;PinkRedWhite;White;1', 0.18209609389305115),\n", " ('361.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.17600329220294952),\n", " ('364.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.16741099953651428),\n", " ('365.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.16448485851287842),\n", " ('20.jpg;Spot;Lobed;Raceme;AFew;PinkRedWhite;White;1', 0.16104918718338013),\n", " ('79.jpg;Spot;Simple;SingleOrPair;SinglePair;PinkRed;Pink;3',\n", " 0.1599152684211731),\n", " ('1250.jpg;Spot;Lobed;Raceme;AFew;White;Green;23', 0.15917754173278809),\n", " ('602.jpg;Spot;Pouched;SingleOrPair;SinglePair;PinkRedWhite;Pink;12',\n", " 0.15614819526672363),\n", " ('1251.jpg;Spot;Lobed;Raceme;AFew;White;Green;23', 0.1506175547838211),\n", " ('154.jpg;Nospot;Lobed;Raceme;Many;BluePurple;Pink;5', 0.1481093168258667),\n", " ('153.jpg;Nospot;Lobed;Raceme;Many;BluePurple;Pink;5', 0.1388826221227646),\n", " ('156.jpg;Nospot;Lobed;Raceme;Many;BluePurple;Pink;5', 0.1335545927286148),\n", " ('57.jpg;Spot;Simple;SingleOrPair;SinglePair;PinkRed;Pink;3',\n", " 0.1283245086669922),\n", " ('4.jpg;Spot;Lobed;Raceme;AFew;PinkRedWhite;White;1', 0.12153234332799911),\n", " ('1294.jpg;Spot;Lobed;Raceme;AFew;White;Green;23', 0.12126421928405762),\n", " ('360.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.11958467215299606),\n", " ('149.jpg;Nospot;Lobed;Raceme;Many;BluePurple;Pink;5', 0.11674829572439194),\n", " ('77.jpg;Spot;Simple;SingleOrPair;SinglePair;PinkRed;Pink;3',\n", " 0.11610187590122223),\n", " ('44.jpg;Spot;Simple;SingleOrPair;SinglePair;PinkRed;Pink;3',\n", " 0.11539264768362045),\n", " ('375.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.1144905537366867),\n", " ('16.jpg;Spot;Lobed;Raceme;AFew;PinkRedWhite;White;1', 0.1133173331618309),\n", " ('31.jpg;Spot;Lobed;Raceme;AFew;White;GreenBrown;2', 0.11253408342599869),\n", " ('934.jpg;Spot;Lobed;Raceme;Many;White;YellowBrown;19', 0.11123257130384445),\n", " ('377.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.1095474436879158),\n", " ('345.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.10801921784877777),\n", " ('71.jpg;Spot;Simple;SingleOrPair;SinglePair;PinkRed;Pink;3',\n", " 0.10731980204582214),\n", " ('1329.jpg;Spot;Lobed;Raceme;AFew;White;YellowBrown;24', 0.1048896461725235),\n", " ('347.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.1000528559088707),\n", " ('415.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.10003134608268738),\n", " ('393.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.09839722514152527),\n", " ('67.jpg;Spot;Simple;SingleOrPair;SinglePair;PinkRed;Pink;3',\n", " 0.09760170429944992),\n", " ('372.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.09713171422481537),\n", " ('9.jpg;Spot;Lobed;Raceme;AFew;PinkRedWhite;White;1', 0.09567029029130936),\n", " ('1129.jpg;Nospot;Simple;Raceme;Many;PinkRed;YellowPurple;22',\n", " 0.09349559247493744),\n", " ('29.jpg;Spot;Lobed;Raceme;AFew;White;GreenBrown;2', 0.0917716920375824),\n", " ('43.jpg;Spot;Simple;SingleOrPair;SinglePair;PinkRed;Pink;3',\n", " 0.09113944321870804),\n", " ('151.jpg;Nospot;Lobed;Raceme;Many;BluePurple;Pink;5', 0.09085232764482498),\n", " ('68.jpg;Spot;Simple;SingleOrPair;SinglePair;PinkRed;Pink;3',\n", " 0.08954086899757385),\n", " ('1205.jpg;Spot;Lobed;Raceme;AFew;White;Green;23', 0.08864416182041168),\n", " ('397.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.08842142671346664),\n", " ('335.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.08576169610023499),\n", " ('419.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.08285453915596008),\n", " ('75.jpg;Spot;Simple;SingleOrPair;SinglePair;White;White;3',\n", " 0.08281706273555756),\n", " ('394.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.0826164186000824),\n", " ('388.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.0812898576259613),\n", " ('117.jpg;Spot;Simple;SingleOrPair;SinglePair;PinkRed;Pink;3',\n", " 0.08076874911785126),\n", " ('764.jpg;Nospot;Lobed;Raceme;AFew;Yellow;Yellow;18', 0.08051265776157379),\n", " ('357.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.07831750810146332),\n", " ('1262.jpg;Spot;Lobed;Raceme;AFew;White;Green;23', 0.07743849605321884),\n", " ('376.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.0759877860546112),\n", " ('158.jpg;Nospot;Lobed;Raceme;Many;BluePurple;Pink;5', 0.07545885443687439),\n", " ('344.jpg;Nospot;Lobed;Raceme;AFew;White;White;11', 0.07462375611066818),\n", " ('385.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.07386453449726105),\n", " ('103.jpg;Spot;Simple;SingleOrPair;SinglePair;PinkRed;Pink;3',\n", " 0.07346448302268982),\n", " ('812.jpg;Spot;Lobed;Raceme;Many;White;YellowBrown;19', 0.07209622859954834),\n", " ('1149.jpg;Nospot;Simple;Raceme;Many;PinkRed;YellowPurple;22',\n", " 0.07033940404653549),\n", " ('423.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.07011250406503677),\n", " ('369.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.06953710317611694),\n", " ('28.jpg;Spot;Lobed;Raceme;AFew;White;GreenBrown;2', 0.06891264021396637),\n", " ('226.jpg;Nospot;Lobed;Raceme;AFew;BluePurple;Purple;9', 0.06838587671518326),\n", " ('776.jpg;Spot;Lobed;Raceme;Many;White;YellowBrown;19', 0.06826956570148468),\n", " ('334.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.06826279312372208),\n", " ('69.jpg;Spot;Simple;SingleOrPair;SinglePair;PinkRed;Pink;3',\n", " 0.06743894517421722),\n", " ('818.jpg;Spot;Lobed;Raceme;Many;White;YellowBrown;19', 0.06660064309835434),\n", " ('488.jpg;Spot;Pouched;SingleOrPair;SinglePair;PinkRedWhite;Pink;12',\n", " 0.06591498851776123),\n", " ('177.jpg;Nospot;Lobed;Raceme;AFew;BluePurple;Purple;7', 0.06477275490760803),\n", " ('674.jpg;Nospot;Lobed;Spike;AFew;White;White;13', 0.06421098113059998),\n", " ('603.jpg;Spot;Pouched;SingleOrPair;SinglePair;PinkRedWhite;Pink;12',\n", " 0.06350540369749069),\n", " ('697.jpg;Nospot;Lobed;SingleOrPair;SinglePair;PinkRed;White;15',\n", " 0.06278358399868011),\n", " ('175.jpg;Nospot;Lobed;Raceme;AFew;BluePurple;Purple;7', 0.06274962425231934),\n", " ('1265.jpg;Spot;Lobed;Raceme;AFew;White;Green;23', 0.06253521144390106),\n", " ('328.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.06139958277344704),\n", " ('1160.jpg;Nospot;Simple;Raceme;Many;PinkRed;YellowPurple;22',\n", " 0.061397090554237366),\n", " ('350.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.058440323919057846),\n", " ('230.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;10', 0.057940512895584106),\n", " ('5.jpg;Spot;Lobed;Raceme;AFew;PinkRedWhite;White;1', 0.057657621800899506),\n", " ('171.jpg;Nospot;Lobed;Raceme;AFew;BluePurple;Purple;7', 0.057468231767416),\n", " ('498.jpg;Spot;Pouched;SingleOrPair;SinglePair;PinkRedWhite;Pink;12',\n", " 0.05653461068868637),\n", " ('1002.jpg;Spot;Lobed;Raceme;Many;White;YellowPurple;20',\n", " 0.05630265921354294),\n", " ('482.jpg;Spot;Pouched;SingleOrPair;SinglePair;PinkRedWhite;Pink;12',\n", " 0.056098878383636475),\n", " ('168.jpg;Spot;Lobed;Raceme;AFew;Green;GreenBrown;6', 0.05599924549460411),\n", " ('391.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.053999386727809906),\n", " ('264.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.05180278792977333),\n", " ('1244.jpg;Spot;Lobed;Raceme;AFew;White;Green;23', 0.05118359625339508),\n", " ('78.jpg;Spot;Simple;SingleOrPair;SinglePair;PinkRed;Pink;3',\n", " 0.05117344483733177),\n", " ('1075.jpg;Spot;Simple;Raceme;AFew;White;GreenBrown;21',\n", " 0.050270598381757736),\n", " ('1282.jpg;Spot;Lobed;Raceme;AFew;White;Green;23', 0.050155527889728546),\n", " ('413.jpg;Nospot;Lobed;Raceme;AFew;White;White;11', 0.049014657735824585),\n", " ('17.jpg;Spot;Lobed;Raceme;AFew;PinkRedWhite;White;1', 0.0488186813890934),\n", " ('64.jpg;Spot;Simple;SingleOrPair;SinglePair;PinkRed;Pink;3',\n", " 0.04768126830458641),\n", " ('90.jpg;Spot;Simple;SingleOrPair;SinglePair;PinkRed;Pink;3',\n", " 0.04746171087026596),\n", " ('412.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.04722648113965988),\n", " ('1095.jpg;Nospot;Simple;Raceme;Many;PinkRed;YellowPurple;22',\n", " 0.046545252203941345),\n", " ('1256.jpg;Spot;Lobed;Raceme;AFew;White;Green;23', 0.04631029814481735),\n", " ('262.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.04623924568295479),\n", " ('174.jpg;Nospot;Lobed;Raceme;AFew;BluePurple;Purple;7',\n", " 0.046176716685295105),\n", " ('240.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;White;10', 0.045038942247629166),\n", " ('286.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.044957708567380905)]" ] }, "metadata": {}, "execution_count": 14 } ], "source": [ "#sorts the output tensor out in descending order to identify the classes ranked by their predicted probabilities\n", "_, indices = torch.sort(out, descending=True)\n", "[(classes[idx], percentage[idx].item()) for idx in indices[0][:156]]" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "eCB_8WaAlH81", "outputId": "5b1892c4-c998-4d56-9858-774a0af872d3" }, "outputs": [ { "output_type": "stream", "name": "stderr", "text": [ "/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=ResNet101_Weights.IMAGENET1K_V1`. You can also use `weights=ResNet101_Weights.DEFAULT` to get the most up-to-date weights.\n", " warnings.warn(msg)\n", "Downloading: \"https://download.pytorch.org/models/resnet101-63fe2227.pth\" to /root/.cache/torch/hub/checkpoints/resnet101-63fe2227.pth\n", "100%|██████████| 171M/171M [00:01<00:00, 150MB/s]\n" ] }, { "output_type": "execute_result", "data": { "text/plain": [ "[('668.jpg;Nospot;Lobed;Spike;AFew;White;White;13', 22.527023315429688),\n", " ('366.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 12.090964317321777),\n", " ('358.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 8.455033302307129),\n", " ('379.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 6.997452735900879),\n", " ('1292.jpg;Spot;Lobed;Raceme;AFew;White;Green;23', 6.838258266448975),\n", " ('381.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 5.595933437347412),\n", " ('1253.jpg;Spot;Lobed;Raceme;AFew;White;Green;23', 3.821831226348877),\n", " ('382.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 3.7380588054656982),\n", " ('1336.jpg;Spot;Lobed;Raceme;AFew;White;YellowBrown;24', 3.2465667724609375),\n", " ('374.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 3.2281291484832764),\n", " ('361.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 2.2762434482574463),\n", " ('367.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 1.5874812602996826),\n", " ('375.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 1.492242455482483),\n", " ('1328.jpg;Spot;Lobed;Raceme;AFew;White;YellowBrown;24', 1.4696153402328491),\n", " ('19.jpg;Spot;Lobed;Raceme;AFew;PinkRedWhite;White;1', 1.4305696487426758),\n", " ('378.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 1.3636442422866821),\n", " ('1291.jpg;Spot;Lobed;Raceme;AFew;White;Green;23', 1.036311149597168),\n", " ('368.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.9036271572113037),\n", " ('380.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.765997588634491),\n", " ('1251.jpg;Spot;Lobed;Raceme;AFew;White;Green;23', 0.7222974300384521),\n", " ('369.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.5622342824935913),\n", " ('364.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.4975619614124298),\n", " ('365.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.3840673565864563),\n", " ('372.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.36875268816947937),\n", " ('1296.jpg;Spot;Lobed;Raceme;AFew;White;Green;23', 0.35623791813850403),\n", " ('377.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.3242622911930084),\n", " ('81.jpg;Spot;Simple;SingleOrPair;SinglePair;PinkRed;Pink;3',\n", " 0.30271732807159424),\n", " ('59.jpg;Spot;Simple;SingleOrPair;SinglePair;PinkRed;Pink;3',\n", " 0.2965044677257538),\n", " ('1036.jpg;Spot;Lobed;Raceme;Many;White;YellowPurple;20',\n", " 0.26680225133895874),\n", " ('136.jpg;Nospot;Lobed;Raceme;AFew;BluePurple;Pink;4', 0.26057183742523193),\n", " ('383.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.25701603293418884),\n", " ('104.jpg;Spot;Simple;SingleOrPair;SinglePair;PinkRed;Pink;3',\n", " 0.24599002301692963),\n", " ('1293.jpg;Spot;Lobed;Raceme;AFew;White;Green;23', 0.2180352807044983),\n", " ('21.jpg;Spot;Lobed;Raceme;AFew;PinkRedWhite;White;1', 0.2138841599225998),\n", " ('1294.jpg;Spot;Lobed;Raceme;AFew;White;Green;23', 0.19859229028224945),\n", " ('841.jpg;Spot;Lobed;Raceme;Many;White;YellowBrown;19', 0.19179081916809082),\n", " ('360.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.19158487021923065),\n", " ('376.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.17068561911582947),\n", " ('842.jpg;Spot;Lobed;Raceme;Many;White;YellowBrown;19', 0.16562320291996002),\n", " ('110.jpg;Spot;Simple;SingleOrPair;SinglePair;PinkRed;Pink;3',\n", " 0.13881315290927887),\n", " ('61.jpg;Spot;Simple;SingleOrPair;SinglePair;PinkRed;Pink;3',\n", " 0.13485118746757507),\n", " ('776.jpg;Spot;Lobed;Raceme;Many;White;YellowBrown;19', 0.13175946474075317),\n", " ('603.jpg;Spot;Pouched;SingleOrPair;SinglePair;PinkRedWhite;Pink;12',\n", " 0.12991517782211304),\n", " ('60.jpg;Spot;Simple;SingleOrPair;SinglePair;PinkRed;Pink;3',\n", " 0.10134583711624146),\n", " ('1333.jpg;Spot;Lobed;Raceme;AFew;White;YellowBrown;24', 0.08948017656803131),\n", " ('111.jpg;Spot;Simple;SingleOrPair;SinglePair;PinkRed;Pink;3',\n", " 0.08913480490446091),\n", " ('1295.jpg;Spot;Lobed;Raceme;AFew;White;Green;23', 0.08839907497167587),\n", " ('166.jpg;Spot;Lobed;Raceme;AFew;Green;GreenBrown;6', 0.08462517708539963),\n", " ('929.jpg;Spot;Lobed;Raceme;Many;White;YellowBrown;19', 0.07931681722402573),\n", " ('912.jpg;Spot;Lobed;Raceme;Many;White;YellowBrown;19', 0.0747298002243042),\n", " ('812.jpg;Spot;Lobed;Raceme;Many;White;YellowBrown;19', 0.0725923553109169),\n", " ('562.jpg;Spot;Pouched;SingleOrPair;SinglePair;PinkRedWhite;Pink;12',\n", " 0.07209319621324539),\n", " ('1265.jpg;Spot;Lobed;Raceme;AFew;White;Green;23', 0.07104596495628357),\n", " ('1025.jpg;Spot;Lobed;Raceme;Many;White;YellowPurple;20', 0.0684821680188179),\n", " ('934.jpg;Spot;Lobed;Raceme;Many;White;YellowBrown;19', 0.06393922865390778),\n", " ('543.jpg;Spot;Pouched;SingleOrPair;SinglePair;PinkRedWhite;Pink;12',\n", " 0.06310241669416428),\n", " ('65.jpg;Spot;Simple;SingleOrPair;SinglePair;PinkRed;Pink;3',\n", " 0.061234522610902786),\n", " ('873.jpg;Spot;Lobed;Raceme;Many;White;YellowBrown;19', 0.060004059225320816),\n", " ('656.jpg;Nospot;Lobed;Spike;AFew;White;White;13', 0.05944221466779709),\n", " ('152.jpg;Nospot;Lobed;Raceme;Many;BluePurple;Pink;5', 0.056256651878356934),\n", " ('370.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.05544749274849892),\n", " ('1219.jpg;Spot;Lobed;Raceme;AFew;White;Green;23', 0.055110733956098557),\n", " ('157.jpg;Nospot;Lobed;Raceme;Many;BluePurple;Pink;5', 0.05467784404754639),\n", " ('602.jpg;Spot;Pouched;SingleOrPair;SinglePair;PinkRedWhite;Pink;12',\n", " 0.05428561568260193),\n", " ('770.jpg;Spot;Lobed;Raceme;Many;White;YellowBrown;19', 0.054113131016492844),\n", " ('1329.jpg;Spot;Lobed;Raceme;AFew;White;YellowBrown;24', 0.05381302163004875),\n", " ('1255.jpg;Spot;Lobed;Raceme;AFew;White;Green;23', 0.05171913653612137),\n", " ('1282.jpg;Spot;Lobed;Raceme;AFew;White;Green;23', 0.0514286570250988),\n", " ('796.jpg;Spot;Lobed;Raceme;Many;White;YellowBrown;19', 0.0476374514400959),\n", " ('584.jpg;Spot;Pouched;SingleOrPair;SinglePair;PinkRedWhite;Pink;12',\n", " 0.047247808426618576),\n", " ('1092.jpg;Nospot;Simple;Raceme;Many;PinkRed;YellowPurple;22',\n", " 0.04512034356594086),\n", " ('158.jpg;Nospot;Lobed;Raceme;Many;BluePurple;Pink;5', 0.04467027261853218),\n", " ('373.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.04281145706772804),\n", " ('1162.jpg;Nospot;Simple;Raceme;Many;PinkRed;YellowPurple;22',\n", " 0.04127465561032295),\n", " ('357.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.0410861074924469),\n", " ('1260.jpg;Spot;Lobed;Raceme;AFew;White;Green;23', 0.04081709682941437),\n", " ('840.jpg;Spot;Lobed;Raceme;Many;White;YellowBrown;19', 0.04077337309718132),\n", " ('795.jpg;Spot;Lobed;Raceme;Many;White;YellowBrown;19', 0.039966385811567307),\n", " ('1075.jpg;Spot;Simple;Raceme;AFew;White;GreenBrown;21', 0.03779946640133858),\n", " ('2.jpg;Spot;Lobed;Raceme;AFew;PinkRedWhite;White;1', 0.03746962919831276),\n", " ('3.jpg;Spot;Lobed;Raceme;AFew;PinkRedWhite;White;1', 0.03715381771326065),\n", " ('1129.jpg;Nospot;Simple;Raceme;Many;PinkRed;YellowPurple;22',\n", " 0.03667420521378517),\n", " ('18.jpg;Spot;Lobed;Raceme;AFew;PinkRedWhite;White;1', 0.03613140806555748),\n", " ('24.jpg;Spot;Lobed;Raceme;AFew;PinkRedWhite;White;1', 0.03517169505357742),\n", " ('1160.jpg;Nospot;Simple;Raceme;Many;PinkRed;YellowPurple;22',\n", " 0.033885665237903595),\n", " ('57.jpg;Spot;Simple;SingleOrPair;SinglePair;PinkRed;Pink;3',\n", " 0.033026933670043945),\n", " ('1102.jpg;Nospot;Simple;Raceme;Many;PinkRed;YellowPurple;22',\n", " 0.0327843576669693),\n", " ('548.jpg;Spot;Pouched;SingleOrPair;SinglePair;PinkRedWhite;Pink;12',\n", " 0.030232133343815804),\n", " ('919.jpg;Spot;Lobed;Raceme;Many;White;YellowBrown;19', 0.029755480587482452),\n", " ('897.jpg;Spot;Lobed;Raceme;Many;White;YellowBrown;19', 0.02920762076973915),\n", " ('79.jpg;Spot;Simple;SingleOrPair;SinglePair;PinkRed;Pink;3',\n", " 0.028464388102293015),\n", " ('1218.jpg;Spot;Lobed;Raceme;AFew;White;Green;23', 0.025755522772669792),\n", " ('4.jpg;Spot;Lobed;Raceme;AFew;PinkRedWhite;White;1', 0.025370949879288673),\n", " ('739.jpg;Nospot;Lobed;Raceme;AFew;Green;Green;17', 0.02451474778354168),\n", " ('1278.jpg;Spot;Lobed;Raceme;AFew;White;Green;23', 0.023888392373919487),\n", " ('1250.jpg;Spot;Lobed;Raceme;AFew;White;Green;23', 0.02321772463619709),\n", " ('76.jpg;Spot;Simple;SingleOrPair;SinglePair;PinkRed;Pink;3',\n", " 0.02258465811610222),\n", " ('33.jpg;Spot;Lobed;Raceme;AFew;White;GreenBrown;2', 0.02256450615823269),\n", " ('155.jpg;Nospot;Lobed;Raceme;Many;BluePurple;Pink;5', 0.02138908952474594),\n", " ('168.jpg;Spot;Lobed;Raceme;AFew;Green;GreenBrown;6', 0.02103375643491745),\n", " ('497.jpg;Spot;Pouched;SingleOrPair;SinglePair;PinkRedWhite;Pink;12',\n", " 0.02076958306133747),\n", " ('1002.jpg;Spot;Lobed;Raceme;Many;White;YellowPurple;20', 0.0206283051520586),\n", " ('172.jpg;Nospot;Lobed;Raceme;AFew;BluePurple;Purple;7',\n", " 0.020343966782093048),\n", " ('66.jpg;Spot;Simple;SingleOrPair;SinglePair;PinkRed;Pink;3',\n", " 0.019313814118504524),\n", " ('815.jpg;Spot;Lobed;Raceme;Many;White;YellowBrown;19', 0.018260987475514412),\n", " ('1112.jpg;Nospot;Simple;Raceme;Many;PinkRed;YellowPurple;22',\n", " 0.018153410404920578),\n", " ('359.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.01792941242456436),\n", " ('177.jpg;Nospot;Lobed;Raceme;AFew;BluePurple;Purple;7', 0.01784311980009079),\n", " ('106.jpg;Spot;Simple;SingleOrPair;SinglePair;PinkRed;Pink;3',\n", " 0.017745058983564377),\n", " ('415.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.0175403393805027),\n", " ('1211.jpg;Spot;Lobed;Raceme;AFew;White;Green;23', 0.01693066954612732),\n", " ('896.jpg;Spot;Lobed;Raceme;Many;White;YellowBrown;19', 0.016679489985108376),\n", " ('46.jpg;Spot;Simple;SingleOrPair;SinglePair;PinkRed;Pink;3',\n", " 0.016446145251393318),\n", " ('20.jpg;Spot;Lobed;Raceme;AFew;PinkRedWhite;White;1', 0.016246825456619263),\n", " ('1095.jpg;Nospot;Simple;Raceme;Many;PinkRed;YellowPurple;22',\n", " 0.016134588047862053),\n", " ('697.jpg;Nospot;Lobed;SingleOrPair;SinglePair;PinkRed;White;15',\n", " 0.015971848741173744),\n", " ('1120.jpg;Nospot;Simple;Raceme;Many;PinkRed;YellowPurple;22',\n", " 0.015784701332449913),\n", " ('787.jpg;Spot;Lobed;Raceme;Many;White;YellowBrown;19', 0.015611162409186363),\n", " ('156.jpg;Nospot;Lobed;Raceme;Many;BluePurple;Pink;5', 0.015609643422067165),\n", " ('1254.jpg;Spot;Lobed;Raceme;AFew;White;Green;23', 0.014959271065890789),\n", " ('53.jpg;Spot;Simple;SingleOrPair;SinglePair;PinkRed;Pink;3',\n", " 0.014151744544506073),\n", " ('140.jpg;Nospot;Lobed;Raceme;Many;BluePurple;Pink;5', 0.013964534737169743),\n", " ('894.jpg;Spot;Lobed;Raceme;Many;White;YellowBrown;19', 0.013306866399943829),\n", " ('72.jpg;Spot;Simple;SingleOrPair;SinglePair;PinkRed;Pink;3',\n", " 0.012626943178474903),\n", " ('875.jpg;Spot;Lobed;Raceme;Many;White;YellowBrown;19', 0.012507344596087933),\n", " ('356.jpg;Nospot;Lobed;Raceme;AFew;PinkRed;Pink;11', 0.012436171993613243),\n", " ('674.jpg;Nospot;Lobed;Spike;AFew;White;White;13', 0.012422670610249043),\n", " ('863.jpg;Spot;Lobed;Raceme;Many;White;YellowBrown;19', 0.011972565203905106),\n", " ('764.jpg;Nospot;Lobed;Raceme;AFew;Yellow;Yellow;18', 0.011872835457324982),\n", " ('780.jpg;Spot;Lobed;Raceme;Many;White;YellowBrown;19', 0.01174514926970005),\n", " ('77.jpg;Spot;Simple;SingleOrPair;SinglePair;PinkRed;Pink;3',\n", " 0.01169571653008461),\n", " ('137.jpg;Nospot;Lobed;Raceme;AFew;BluePurple;Pink;4', 0.011682512238621712),\n", " ('44.jpg;Spot;Simple;SingleOrPair;SinglePair;PinkRed;Pink;3',\n", " 0.011502182111144066),\n", " ('1149.jpg;Nospot;Simple;Raceme;Many;PinkRed;YellowPurple;22',\n", " 0.011412670835852623),\n", " ('99.jpg;Spot;Simple;SingleOrPair;SinglePair;PinkRed;Pink;3',\n", " 0.011360845528542995),\n", " ('1256.jpg;Spot;Lobed;Raceme;AFew;White;Green;23', 0.011006956920027733),\n", " ('28.jpg;Spot;Lobed;Raceme;AFew;White;GreenBrown;2', 0.0104835731908679),\n", " ('1252.jpg;Spot;Lobed;Raceme;AFew;White;Green;23', 0.010352383367717266),\n", " ('42.jpg;Spot;Simple;SingleOrPair;SinglePair;PinkRed;Pink;3',\n", " 0.010113776661455631),\n", " ('1064.jpg;Spot;Simple;Raceme;AFew;White;GreenBrown;21',\n", " 0.009753772057592869),\n", " ('175.jpg;Nospot;Lobed;Raceme;AFew;BluePurple;Purple;7',\n", " 0.009223428554832935),\n", " ('1264.jpg;Spot;Lobed;Raceme;AFew;White;Green;23', 0.009143059141933918),\n", " ('151.jpg;Nospot;Lobed;Raceme;Many;BluePurple;Pink;5', 0.00906144455075264),\n", " ('512.jpg;Spot;Pouched;SingleOrPair;SinglePair;PinkRedWhite;Pink;12',\n", " 0.00896426197141409),\n", " ('98.jpg;Spot;Simple;SingleOrPair;SinglePair;PinkRed;Pink;3',\n", " 0.008810152299702168),\n", " ('1135.jpg;Nospot;Simple;Raceme;Many;PinkRed;YellowPurple;22',\n", " 0.008771269582211971),\n", " ('67.jpg;Spot;Simple;SingleOrPair;SinglePair;PinkRed;Pink;3',\n", " 0.00870033074170351),\n", " ('856.jpg;Spot;Lobed;Raceme;Many;White;YellowBrown;19', 0.008633521385490894),\n", " ('103.jpg;Spot;Simple;SingleOrPair;SinglePair;PinkRed;Pink;3',\n", " 0.008289733901619911),\n", " ('73.jpg;Spot;Simple;SingleOrPair;SinglePair;PinkRed;Pink;3',\n", " 0.008183479309082031),\n", " ('904.jpg;Spot;Lobed;Raceme;Many;White;YellowBrown;19', 0.008113854564726353),\n", " ('597.jpg;Spot;Pouched;SingleOrPair;SinglePair;PinkRedWhite;Pink;12',\n", " 0.00803594570606947),\n", " ('535.jpg;Spot;Pouched;SingleOrPair;SinglePair;PinkRedWhite;Pink;12',\n", " 0.008010867051780224),\n", " ('153.jpg;Nospot;Lobed;Raceme;Many;BluePurple;Pink;5', 0.008003998547792435),\n", " ('498.jpg;Spot;Pouched;SingleOrPair;SinglePair;PinkRedWhite;Pink;12',\n", " 0.007863061502575874),\n", " ('23.jpg;Spot;Lobed;Raceme;AFew;PinkRedWhite;White;1', 0.007817661389708519)]" ] }, "metadata": {}, "execution_count": 15 } ], "source": [ "# Using ResNet for Image Classification\n", "# First, load the model\n", "resnet = models.resnet101(pretrained=True)\n", "\n", "# Second, put the network in eval mode\n", "resnet.eval()\n", "\n", "# Third, carry out model inference\n", "out = resnet(batch_t)\n", "\n", "# Forth, print the top 156 classes predicted by the model\n", "_, indices = torch.sort(out, descending=True)\n", "percentage = torch.nn.functional.softmax(out, dim=1)[0] * 100\n", "[(classes[idx], percentage[idx].item()) for idx in indices[0][:156]]" ] } ], "metadata": { "accelerator": "GPU", "colab": { "gpuType": "T4", "provenance": [] }, "kernelspec": { "display_name": "Python 3", "name": "python3" }, "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 0 }