{ "cells": [ { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "view-in-github" }, "source": [ "\"Open" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "VaLHNIS5vFr8" }, "outputs": [], "source": [ "def get_iou(boxA, boxB, epsilon=1e-5):\n", " x1 = max(boxA[0], boxB[0])\n", " y1 = max(boxA[1], boxB[1])\n", " x2 = min(boxA[2], boxB[2])\n", " y2 = min(boxA[3], boxB[3])\n", " width = (x2 - x1)\n", " height = (y2 - y1)\n", " if (width<0) or (height <0):\n", " return 0.0\n", " area_overlap = width * height\n", " area_a = (boxA[2] - boxA[0]) * (boxA[3] - boxA[1])\n", " area_b = (boxB[2] - boxB[0]) * (boxB[3] - boxB[1])\n", " area_combined = area_a + area_b - area_overlap\n", " iou = area_overlap / (area_combined+epsilon)\n", " return iou" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "3bvslWV_viWJ" }, "outputs": [], "source": [] } ], "metadata": { "colab": { "include_colab_link": true, "name": "Calculating_intersection_over_union.ipynb", "provenance": [] }, "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.13" }, "latex_envs": { "LaTeX_envs_menu_present": true, "autoclose": false, "autocomplete": true, "bibliofile": "biblio.bib", "cite_by": "apalike", "current_citInitial": 1, "eqLabelWithNumbers": true, "eqNumInitial": 1, "hotkeys": { "equation": "Ctrl-E", "itemize": "Ctrl-I" }, "labels_anchors": false, "latex_user_defs": false, "report_style_numbering": false, "user_envs_cfg": false } }, "nbformat": 4, "nbformat_minor": 1 }