From f4f7b488d667fc2dfb3d4c5b6f001d13489c4850 Mon Sep 17 00:00:00 2001 From: krystianzun <44001786+krystianzun@users.noreply.github.com> Date: Thu, 1 Jun 2023 09:00:11 +0100 Subject: [PATCH 1/5] Ignore metadata --- .gitignore | 1 + Object Detection/object_detection.ipynb | 403 +++++++++++++++--------- 2 files changed, 255 insertions(+), 149 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1f8d547 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +Object Detection/object_detection.ipynb diff --git a/Object Detection/object_detection.ipynb b/Object Detection/object_detection.ipynb index 8a678fc..76c0664 100644 --- a/Object Detection/object_detection.ipynb +++ b/Object Detection/object_detection.ipynb @@ -1,10 +1,11 @@ { "cells": [ { + "attachments": {}, "cell_type": "markdown", "metadata": { - "id": "T3vCYmDG8XPN", - "colab_type": "text" + "colab_type": "text", + "id": "T3vCYmDG8XPN" }, "source": [ "In this tutorial we will train a simple object detector for one class. We'd like to have a system which works on low-end devices in real-time. The provided code is simplified to show key steps in model creation, training and exporting to Lens Studio. If you'd like to obtain better precision then the first steps you could try are training for longer time, using higher resolution, increasing the 'width_mult' parameter in config (the model will become slower and bigger in this case so be careful with it).\n", @@ -15,10 +16,11 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": { - "id": "A6IYmh4d92cu", - "colab_type": "text" + "colab_type": "text", + "id": "A6IYmh4d92cu" }, "source": [ "\n", @@ -32,10 +34,11 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": { - "id": "S5AznYqOMzQ0", - "colab_type": "text" + "colab_type": "text", + "id": "S5AznYqOMzQ0" }, "source": [ "# Install libraries\n", @@ -49,24 +52,28 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { - "id": "36XnOD0PGhEH", + "colab": {}, "colab_type": "code", - "colab": {} + "id": "36XnOD0PGhEH", + "vscode": { + "languageId": "python" + } }, + "outputs": [], "source": [ "%pip install -q numpy==1.18.1 opencv-python-headless==4.2.0.32 \\\n", " torch==1.4.0 torchvision==0.5.0 \\\n", " albumentations==0.4.5 tqdm==4.43.0" - ], - "execution_count": 0, - "outputs": [] + ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": { - "id": "Q0ITyuv8omR9", - "colab_type": "text" + "colab_type": "text", + "id": "Q0ITyuv8omR9" }, "source": [ "# Imports\n", @@ -76,11 +83,16 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { - "id": "QzjQZ5mT8ikz", + "colab": {}, "colab_type": "code", - "colab": {} + "id": "QzjQZ5mT8ikz", + "vscode": { + "languageId": "python" + } }, + "outputs": [], "source": [ "import cv2\n", "import json\n", @@ -121,15 +133,14 @@ "# Flip values for slower training speed, but more determenistic results.\n", "torch.backends.cudnn.deterministic = False\n", "torch.backends.cudnn.benchmark = True" - ], - "execution_count": 0, - "outputs": [] + ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": { - "id": "5fCRHPEheyWF", - "colab_type": "text" + "colab_type": "text", + "id": "5fCRHPEheyWF" }, "source": [ "It is recommened to train on GPU but you can run the model on CPU also" @@ -137,22 +148,26 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { - "id": "QjZwwHj0ewc_", + "colab": {}, "colab_type": "code", - "colab": {} + "id": "QjZwwHj0ewc_", + "vscode": { + "languageId": "python" + } }, + "outputs": [], "source": [ "DEVICE = torch.device('cpu')\n", "if torch.cuda.is_available():\n", " DEVICE = torch.device('cuda:0')\n", " torch.cuda.manual_seed(RANDOM_SEED)\n", "DEVICE" - ], - "execution_count": 0, - "outputs": [] + ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": { "colab_type": "text", @@ -173,43 +188,54 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { + "colab": {}, "colab_type": "code", "id": "rRL-7EVJUCsm", - "colab": {} + "vscode": { + "languageId": "python" + } }, + "outputs": [], "source": [ "# Following classes will be united into single category\n", "OBJECT_LABELS_UNION = ['car', 'truck', 'bus']\n", "# You can create your own categories like these:\n", "# OBJECT_LABELS_UNION = ['cat', 'dog']\n", "# OBJECT_LABELS_UNION = ['bird']" - ], - "execution_count": 0, - "outputs": [] + ] }, { "cell_type": "code", + "execution_count": null, "metadata": { + "colab": {}, "colab_type": "code", "id": "pZCiq6wTQvK4", - "colab": {} + "vscode": { + "languageId": "python" + } }, + "outputs": [], "source": [ "DATASET_PATH = Path('.') # Path to the dataset\n", "DIR_TO_SAVE_RESULTS = Path('centernet_model') # Model snapshots will be saved here\n", "os.makedirs(DIR_TO_SAVE_RESULTS, exist_ok=True)" - ], - "execution_count": 0, - "outputs": [] + ] }, { "cell_type": "code", + "execution_count": null, "metadata": { + "colab": {}, "colab_type": "code", "id": "JfHCARftVtRH", - "colab": {} + "vscode": { + "languageId": "python" + } }, + "outputs": [], "source": [ "# This number can be different\n", "# The bigger number of epochs, longer training time, but better model quality\n", @@ -217,15 +243,14 @@ "# NUM_EPOCHS = 70\n", "\n", "NUM_EPOCHS = 100 # => better quality " - ], - "execution_count": 0, - "outputs": [] + ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": { - "id": "KsYoY5X10hN1", - "colab_type": "text" + "colab_type": "text", + "id": "KsYoY5X10hN1" }, "source": [ "Advanced constants" @@ -233,11 +258,16 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { - "id": "Nmx9RJqX0gqd", + "colab": {}, "colab_type": "code", - "colab": {} + "id": "Nmx9RJqX0gqd", + "vscode": { + "languageId": "python" + } }, + "outputs": [], "source": [ "BATCH_SIZE = 32\n", "LEARNING_RATE = 1e-3\n", @@ -250,11 +280,10 @@ "# width_mult is a coefficient which defines how many filters\n", "# to use from original mobilenet:\n", "MOBILENET_WIDTH_MULTIPLIER = 0.3" - ], - "execution_count": 0, - "outputs": [] + ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": { "colab_type": "text", @@ -270,11 +299,16 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { - "id": "a_BxNY2QoYBx", + "colab": {}, "colab_type": "code", - "colab": {} + "id": "a_BxNY2QoYBx", + "vscode": { + "languageId": "python" + } }, + "outputs": [], "source": [ "def download_and_unpack_file(link, filename, unpack=True):\n", " \"\"\" Download and unpack dataset's annotation files \"\"\"\n", @@ -299,68 +333,79 @@ " shutil.unpack_archive(archname, DATASET_PATH)\n", " os.remove(archname)\n", " print(\"Successfuly downloaded and extracted archive\")" - ], - "execution_count": 0, - "outputs": [] + ] }, { "cell_type": "code", + "execution_count": null, "metadata": { - "id": "QkGY9Dkm6qrz", + "colab": {}, "colab_type": "code", - "colab": {} + "id": "QkGY9Dkm6qrz", + "vscode": { + "languageId": "python" + } }, + "outputs": [], "source": [ "os.listdir(\"./\")" - ], - "execution_count": 0, - "outputs": [] + ] }, { "cell_type": "code", + "execution_count": null, "metadata": { - "id": "dDa7QyyhQ4uZ", + "colab": {}, "colab_type": "code", - "colab": {} + "id": "dDa7QyyhQ4uZ", + "vscode": { + "languageId": "python" + } }, + "outputs": [], "source": [ "# Train set is too big for colab so we will extract only files used in training. You can unpack whole dataset locally if you have enough free space\n", "download_and_unpack_file('http://images.cocodataset.org/zips/train2017.zip', 'train2017', unpack=False)" - ], - "execution_count": 0, - "outputs": [] + ] }, { "cell_type": "code", + "execution_count": null, "metadata": { - "id": "wgAM6ULkZF5V", + "colab": {}, "colab_type": "code", - "colab": {} + "id": "wgAM6ULkZF5V", + "vscode": { + "languageId": "python" + } }, + "outputs": [], "source": [ "download_and_unpack_file('http://images.cocodataset.org/annotations/annotations_trainval2017.zip', 'annotations')" - ], - "execution_count": 0, - "outputs": [] + ] }, { "cell_type": "code", + "execution_count": null, "metadata": { - "id": "naFK1JknZIy5", + "colab": {}, "colab_type": "code", - "colab": {} + "id": "naFK1JknZIy5", + "vscode": { + "languageId": "python" + } }, + "outputs": [], "source": [ "download_and_unpack_file('http://images.cocodataset.org/zips/val2017.zip', 'val2017')" - ], - "execution_count": 0, - "outputs": [] + ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": { - "id": "fklGsd0to2ru", - "colab_type": "text" + "colab_type": "text", + "id": "fklGsd0to2ru" }, "source": [ "# 3. Data class\n", @@ -370,11 +415,16 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { - "id": "b-04kuy8Nt14", + "colab": {}, "colab_type": "code", - "colab": {} + "id": "b-04kuy8Nt14", + "vscode": { + "languageId": "python" + } }, + "outputs": [], "source": [ "class Dataset(torch.utils.data.Dataset):\n", " def __init__(self, phase, box_coder=None, transform=None):\n", @@ -481,11 +531,10 @@ "\n", " def __len__(self):\n", " return len(self.dataset)" - ], - "execution_count": 0, - "outputs": [] + ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": { "colab_type": "text", @@ -503,11 +552,16 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { + "colab": {}, "colab_type": "code", "id": "ClD9OTUnUw4P", - "colab": {} + "vscode": { + "languageId": "python" + } }, + "outputs": [], "source": [ "def train_transform(annotations):\n", " image = annotations['image']\n", @@ -562,11 +616,10 @@ " augmented['out_size'] = size\n", " augmented['intermediate_size'] = intermediate_size\n", " return augmented" - ], - "execution_count": 0, - "outputs": [] + ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": { "colab_type": "text", @@ -580,11 +633,16 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { + "colab": {}, "colab_type": "code", "id": "v_9nTSADUw1o", - "colab": {} + "vscode": { + "languageId": "python" + } }, + "outputs": [], "source": [ "class BoxCoder:\n", " def __init__(self, image_size, ratio):\n", @@ -672,11 +730,10 @@ " \n", " boxes[:, 2:] = boxes[:, 2:] - boxes[:, :2]\n", " return boxes, labels, scores" - ], - "execution_count": 0, - "outputs": [] + ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": { "colab_type": "text", @@ -702,11 +759,16 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { + "colab": {}, "colab_type": "code", "id": "MGBXj2EyUwyl", - "colab": {} + "vscode": { + "languageId": "python" + } }, + "outputs": [], "source": [ "def convert_layers(model):\n", " \"\"\" Convert relu6 to relu for faster inference in libdnn \"\"\"\n", @@ -828,11 +890,10 @@ " boxes = self.rescale_boxes(boxes, sample['out_size'], sample['intermediate_size'], sample['scale'])\n", "\n", " return boxes, labels, probs" - ], - "execution_count": 0, - "outputs": [] + ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": { "colab_type": "text", @@ -846,11 +907,16 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { + "colab": {}, "colab_type": "code", "id": "iuOpJ2jicAqr", - "colab": {} + "vscode": { + "languageId": "python" + } }, + "outputs": [], "source": [ "class Loss(nn.Module):\n", " \"\"\" Focal loss is used for classification and L1-loss for regression. \"\"\"\n", @@ -882,11 +948,10 @@ "\n", " loss = loc_loss + cls_loss\n", " return loss, loc_loss, cls_loss" - ], - "execution_count": 0, - "outputs": [] + ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": { "colab_type": "text", @@ -900,37 +965,44 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { + "colab": {}, "colab_type": "code", "id": "RMlhAClogwXc", - "colab": {} + "vscode": { + "languageId": "python" + } }, + "outputs": [], "source": [ "box_coder = BoxCoder(INPUT_SIZE, FEATURE_MAP_SIZE_RATIO)" - ], - "execution_count": 0, - "outputs": [] + ] }, { "cell_type": "code", + "execution_count": null, "metadata": { + "colab": {}, "colab_type": "code", "id": "9laVXWem8KHo", "scrolled": true, - "colab": {} + "vscode": { + "languageId": "python" + } }, + "outputs": [], "source": [ "val_dataset = Dataset('val', box_coder, validation_transform)\n", "train_dataset = Dataset('train', box_coder, train_transform)" - ], - "execution_count": 0, - "outputs": [] + ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": { - "id": "yOvxqR8f8dhI", - "colab_type": "text" + "colab_type": "text", + "id": "yOvxqR8f8dhI" }, "source": [ "Create dataloaders for parallel loading of images" @@ -938,11 +1010,16 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { - "id": "_-P2U00y5OAv", + "colab": {}, "colab_type": "code", - "colab": {} + "id": "_-P2U00y5OAv", + "vscode": { + "languageId": "python" + } }, + "outputs": [], "source": [ "train_loader = torch.utils.data.DataLoader(\n", " train_dataset,\n", @@ -960,11 +1037,10 @@ " num_workers=NUM_WORKERS,\n", " drop_last=False\n", ")" - ], - "execution_count": 0, - "outputs": [] + ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": { "colab_type": "text", @@ -978,23 +1054,27 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { + "colab": {}, "colab_type": "code", "id": "jkvSk_QxBelG", - "colab": {} + "vscode": { + "languageId": "python" + } }, + "outputs": [], "source": [ "model = Detector(MOBILENET_WIDTH_MULTIPLIER, box_transformer=box_coder,\n", " test_transform=validation_transform)" - ], - "execution_count": 0, - "outputs": [] + ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": { - "id": "9BwuMrz5CrgS", - "colab_type": "text" + "colab_type": "text", + "id": "9BwuMrz5CrgS" }, "source": [ "We'll also set up learning rate scheduler to drop learning rate if our network training platoes." @@ -1002,11 +1082,16 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { + "colab": {}, "colab_type": "code", "id": "7j1ho5GXs-Wd", - "colab": {} + "vscode": { + "languageId": "python" + } }, + "outputs": [], "source": [ "optimizer = torch.optim.Adam(model.parameters(), lr=LEARNING_RATE,\n", " weight_decay=1e-4)\n", @@ -1017,28 +1102,30 @@ "print(\"Using ReduceLROnPlateau scheduler.\")\n", "scheduler = torch.optim.lr_scheduler.ReduceLROnPlateau(\n", " optimizer, 'min', factor=0.5, patience=5, verbose=True)" - ], - "execution_count": 0, - "outputs": [] + ] }, { "cell_type": "code", + "execution_count": null, "metadata": { + "colab": {}, "colab_type": "code", "id": "z_26xSX3uLwf", - "colab": {} + "vscode": { + "languageId": "python" + } }, + "outputs": [], "source": [ "print(\"Device used for training:\", DEVICE)" - ], - "execution_count": 0, - "outputs": [] + ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": { - "id": "Ia0E9m_hVUh6", - "colab_type": "text" + "colab_type": "text", + "id": "Ia0E9m_hVUh6" }, "source": [ "Define train, validation functions and train the network" @@ -1046,11 +1133,16 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { + "colab": {}, "colab_type": "code", "id": "xqX0uGZYTitH", - "colab": {} + "vscode": { + "languageId": "python" + } }, + "outputs": [], "source": [ "def train(loader, net, criterion, optimizer, device):\n", " net.train(True)\n", @@ -1113,11 +1205,10 @@ " model_path = DIR_TO_SAVE_RESULTS / f\"e-{epoch}-{val_loss:.3f}.pth\"\n", " model.save(model_path)\n", " print(f\"Saved model {model_path}\")" - ], - "execution_count": 0, - "outputs": [] + ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": { "colab_type": "text", @@ -1131,24 +1222,28 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { + "colab": {}, "colab_type": "code", "id": "bglf8wgHs2CJ", - "colab": {} + "vscode": { + "languageId": "python" + } }, + "outputs": [], "source": [ "# model.load(DIR_TO_SAVE_RESULTS / 'e-5-1.583.pth') # Use to load saved model snapshot\n", "model.eval()\n", "model = model.to('cpu')" - ], - "execution_count": 0, - "outputs": [] + ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": { - "id": "DMfD0XdNd_8n", - "colab_type": "text" + "colab_type": "text", + "id": "DMfD0XdNd_8n" }, "source": [ "Use test image 'car_test_image.png'. Make sure you've uploaded it to the google colab environment. Try changing the score_threshold in model.predict() to see how the model predicts less confident detections." @@ -1156,11 +1251,16 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { + "colab": {}, "colab_type": "code", "id": "W1fzLsQGWGYA", - "colab": {} + "vscode": { + "languageId": "python" + } }, + "outputs": [], "source": [ "sample = {'image': cv2.imread('./car_test_image.png')} # Load the image in BGR format\n", "\n", @@ -1175,11 +1275,10 @@ "plt.figure(figsize=(10, 10))\n", "plt.axis('off')\n", "plt.imshow(cv2.cvtColor(sample['image'], cv2.COLOR_BGR2RGB))" - ], - "execution_count": 0, - "outputs": [] + ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": { "colab_type": "text", @@ -1197,26 +1296,34 @@ }, { "cell_type": "code", + "execution_count": null, "metadata": { + "colab": {}, "colab_type": "code", "id": "fczQK-MWh_Z7", - "colab": {} + "vscode": { + "languageId": "python" + } }, + "outputs": [], "source": [ "onnx_model_path = DIR_TO_SAVE_RESULTS / 'det.onnx'\n", "dummy_input = torch.ones(1, 3, INPUT_SIZE[1], INPUT_SIZE[0],\n", " dtype=torch.float32)" - ], - "execution_count": 0, - "outputs": [] + ] }, { "cell_type": "code", + "execution_count": null, "metadata": { + "colab": {}, "colab_type": "code", "id": "29S6RiMJhh_g", - "colab": {} + "vscode": { + "languageId": "python" + } }, + "outputs": [], "source": [ "# model.load(DIR_TO_SAVE_RESULTS / 'e-75-1.091.pth') # Use to load saved model snapshot\n", "model.to('cpu')\n", @@ -1233,24 +1340,22 @@ "\n", "model.set_conversion_mode(to_convert=False)\n", "print(\"Successfully saved model as {}\".format(onnx_model_path))" - ], - "execution_count": 0, - "outputs": [] + ] } ], "metadata": { "accelerator": "GPU", "colab": { + "collapsed_sections": [], "name": "object_detection.ipynb", "provenance": [], - "collapsed_sections": [], "toc_visible": true }, "kernelspec": { - "name": "python3", - "display_name": "Python 3" + "display_name": "Python 3", + "name": "python3" } }, "nbformat": 4, "nbformat_minor": 0 -} \ No newline at end of file +} From f55cf860016074b2b5d3642abaa2a65e43ea43a8 Mon Sep 17 00:00:00 2001 From: krystianzun <44001786+krystianzun@users.noreply.github.com> Date: Thu, 1 Jun 2023 09:01:12 +0100 Subject: [PATCH 2/5] Update pip install dependencies --- Object Detection/object_detection.ipynb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Object Detection/object_detection.ipynb b/Object Detection/object_detection.ipynb index 76c0664..5d5c27b 100644 --- a/Object Detection/object_detection.ipynb +++ b/Object Detection/object_detection.ipynb @@ -63,9 +63,9 @@ }, "outputs": [], "source": [ - "%pip install -q numpy==1.18.1 opencv-python-headless==4.2.0.32 \\\n", - " torch==1.4.0 torchvision==0.5.0 \\\n", - " albumentations==0.4.5 tqdm==4.43.0" + "%pip install -q numpy opencv-python-headless \\\n", + " torch torchvision xarray-einstats \\\n", + " albumentations tqdm" ] }, { From 2c820b70a6876a3ccaa12be6d9578de7a3000aea Mon Sep 17 00:00:00 2001 From: krystianzun <44001786+krystianzun@users.noreply.github.com> Date: Thu, 1 Jun 2023 09:04:28 +0100 Subject: [PATCH 3/5] Update torchvision import source --- Object Detection/object_detection.ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Object Detection/object_detection.ipynb b/Object Detection/object_detection.ipynb index 5d5c27b..b76e73e 100644 --- a/Object Detection/object_detection.ipynb +++ b/Object Detection/object_detection.ipynb @@ -121,7 +121,7 @@ "from torch.utils.data import DataLoader\n", "\n", "import torchvision\n", - "from torchvision.models.mobilenet import ConvBNReLU\n", + "from torchvision.models.mobilenetv2 import Conv2dNormActivation\n", "from torchvision.ops import box_iou, nms\n", "\n", "# Set random seeds for the libraries to obtain reproducible results\n", @@ -791,7 +791,7 @@ " self.backbone = self.get_backbone(width_mult)\n", "\n", " neck_dim = 160\n", - " self.neck = ConvBNReLU(self.backbone[-1].conv[-1].num_features,\n", + " self.neck = Conv2dNormActivation(self.backbone[-1].conv[-1].num_features,\n", " neck_dim, kernel_size=1)\n", "\n", " self.smooth = nn.Conv2d(neck_dim, neck_dim, kernel_size=3, stride=1,\n", From f2531e60bc62c18b19b10417831df39f6c91c772 Mon Sep 17 00:00:00 2001 From: krystianzun <44001786+krystianzun@users.noreply.github.com> Date: Thu, 1 Jun 2023 18:06:33 +0100 Subject: [PATCH 4/5] Add pip install onnx --- Object Detection/object_detection.ipynb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Object Detection/object_detection.ipynb b/Object Detection/object_detection.ipynb index b76e73e..1e8ed56 100644 --- a/Object Detection/object_detection.ipynb +++ b/Object Detection/object_detection.ipynb @@ -1294,6 +1294,19 @@ "BatchNorm layers will be fused with convolution layers in studio so there is no need to do it in pytorch." ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "vscode": { + "languageId": "python" + } + }, + "outputs": [], + "source": [ + "%pip install onnx" + ] + }, { "cell_type": "code", "execution_count": null, From c2ee8e873a3c7588d3ef3c4db0b0036aea61ad33 Mon Sep 17 00:00:00 2001 From: krystianzun <44001786+krystianzun@users.noreply.github.com> Date: Thu, 1 Jun 2023 19:07:43 +0100 Subject: [PATCH 5/5] Define data type --- Object Detection/object_detection.ipynb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Object Detection/object_detection.ipynb b/Object Detection/object_detection.ipynb index 1e8ed56..98c76df 100644 --- a/Object Detection/object_detection.ipynb +++ b/Object Detection/object_detection.ipynb @@ -1267,10 +1267,10 @@ "boxes, labels, probs = model.predict(sample, score_threshold=0.4)\n", "for i in range(boxes.size(0)):\n", " box = boxes[i, :]\n", - " label = f\"{probs[i]:.2f}\"\n", - " cv2.rectangle(sample['image'], (box[0], box[1]),\n", - " (box[0] + box[2], box[1] + box[3]), (255, 255, 0), 4)\n", - " cv2.putText(sample['image'], label, (box[0] + 20, box[1] + 40),\n", + " label = f\"{probs[i]: 2f}\"\n", + " cv2.rectangle(sample['image'], (int(box[0]), int(box[1])),\n", + " (int(box[0]) + int(box[2]), int(box[1]) + int(box[3])), (255, 255, 0), 4)\n", + " cv2.putText(sample['image'], label, (int(box[0]) + 20, int(box[1]) + 40),\n", " cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 0, 255), 2)\n", "plt.figure(figsize=(10, 10))\n", "plt.axis('off')\n",