From dba0686a8f8d684d363e193cb79a2cd619dcdfba Mon Sep 17 00:00:00 2001 From: Jiacong Fang Date: Fri, 23 Dec 2022 14:43:04 +0800 Subject: [PATCH 1/9] Add utils/gradio/demo.py --- utils/gradio/demo.py | 66 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 utils/gradio/demo.py diff --git a/utils/gradio/demo.py b/utils/gradio/demo.py new file mode 100644 index 000000000000..6ec42bcb9476 --- /dev/null +++ b/utils/gradio/demo.py @@ -0,0 +1,66 @@ +""" +Run Gradio demo. + +Usage - local model: +python utils/gradio/demo.py --source local --path MODEL_FILE + +Usage - github repo: +python utils/gradio/demo.py --source github --model yolov5s +""" + +import argparse +import os +import sys +from pathlib import Path +import torch + +FILE = Path(__file__).resolve() +ROOT = FILE.parents[2] # YOLOv5 root directory +if str(ROOT) not in sys.path: + sys.path.append(str(ROOT)) # add ROOT to PATH +ROOT = Path(os.path.relpath(ROOT, Path.cwd())) # relative + +from utils.general import print_args, check_requirements +from utils.dataloaders import IMG_FORMATS + + +def run(inp, conf, iou, agnostic_nms): + model.conf = conf + model.iou = iou + model.agnostic = agnostic_nms + res = model([inp[..., ::-1]], size=opt.imgsz).render()[0][..., ::-1] + return res + + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument('--imgsz', '--img', '--img-size', nargs='+', type=int, default=[640], help='inference size h,w') + parser.add_argument('--share', action='store_true', help='share yolov5 demo with public link') + parser.add_argument('--host', type=str, default='localhost', help='server ip/name (0.0.0.0 for network request)') + parser.add_argument('--port', type=int, default=7860, help='server port') + parser.add_argument('--example_dir', type=str, default=ROOT / 'data/images', help='example image dir') + parser.add_argument('--source', type=str, default='local', help='torch hub source: github/local') + parser.add_argument('--model', type=str, default='custom', help='model name used by github source') + parser.add_argument('--path', type=str, default=ROOT / 'yolov5l.pt', help='local model path') + opt = parser.parse_args() + opt.imgsz *= 2 if len(opt.imgsz) == 1 else 1 # expand + print_args(vars(opt)) + + check_requirements(exclude=('tensorboard', 'thop')) + check_requirements('gradio') + import gradio as gr + + files = Path(opt.example_dir).glob('*') + examples = [] + for f in files: + if f.suffix.lower()[1:] in IMG_FORMATS: + examples.append([f]) + kwargs = {'path': opt.path} if opt.source == 'local' else {} + repo = ROOT if opt.source == 'local' else 'ultralytics/yolov5' # source == 'github' + model = torch.hub.load(repo, opt.model, source=opt.source, **kwargs) + demo = gr.Interface(fn=run, + inputs=[gr.Image(), gr.Slider(0, 1, 0.25), gr.Slider(0, 1, 0.45), gr.Checkbox()], + outputs="image", + examples=examples) + demo.launch(share=opt.share, server_name=opt.host, server_port=opt.port) + From f19f43a4cbc2f3be4db01cc88066f800f507e009 Mon Sep 17 00:00:00 2001 From: Jiacong Fang Date: Fri, 23 Dec 2022 15:15:00 +0800 Subject: [PATCH 2/9] Add integrated gradio example in tutorial.ipynb --- tutorial.ipynb | 541 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 534 insertions(+), 7 deletions(-) diff --git a/tutorial.ipynb b/tutorial.ipynb index e83617e9dce7..99cecd8478eb 100644 --- a/tutorial.ipynb +++ b/tutorial.ipynb @@ -355,6 +355,348 @@ "_view_name": "StyleView", "description_width": "" } + }, + "57e23f3f792f4de1ac7a0d1dc66681e0": { + "model_module": "@jupyter-widgets/controls", + "model_name": "HBoxModel", + "model_module_version": "1.5.0", + "state": { + "_dom_classes": [], + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "HBoxModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/controls", + "_view_module_version": "1.5.0", + "_view_name": "HBoxView", + "box_style": "", + "children": [ + "IPY_MODEL_b1ba65ec5cd24545915a0b6d5369e9f4", + "IPY_MODEL_3efa94127181419d816acbe9ffe46a7f", + "IPY_MODEL_0dd9e43ce73f47e9aa9adb7b6ee4d300" + ], + "layout": "IPY_MODEL_29cc15b9aa404f959ebed0c1fb45635c" + } + }, + "b1ba65ec5cd24545915a0b6d5369e9f4": { + "model_module": "@jupyter-widgets/controls", + "model_name": "HTMLModel", + "model_module_version": "1.5.0", + "state": { + "_dom_classes": [], + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "HTMLModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/controls", + "_view_module_version": "1.5.0", + "_view_name": "HTMLView", + "description": "", + "description_tooltip": null, + "layout": "IPY_MODEL_998e683fee0947a5a1e9154492f0922e", + "placeholder": "​", + "style": "IPY_MODEL_c1973d99f832441e92e5cc5c4f7fb4b2", + "value": "100%" + } + }, + "3efa94127181419d816acbe9ffe46a7f": { + "model_module": "@jupyter-widgets/controls", + "model_name": "FloatProgressModel", + "model_module_version": "1.5.0", + "state": { + "_dom_classes": [], + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "FloatProgressModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/controls", + "_view_module_version": "1.5.0", + "_view_name": "ProgressView", + "bar_style": "success", + "description": "", + "description_tooltip": null, + "layout": "IPY_MODEL_03f366c56c9d42d284a34cbf8adb9e9d", + "max": 14808437, + "min": 0, + "orientation": "horizontal", + "style": "IPY_MODEL_800dfe2ac06d4e38a998fdd731692815", + "value": 14808437 + } + }, + "0dd9e43ce73f47e9aa9adb7b6ee4d300": { + "model_module": "@jupyter-widgets/controls", + "model_name": "HTMLModel", + "model_module_version": "1.5.0", + "state": { + "_dom_classes": [], + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "HTMLModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/controls", + "_view_module_version": "1.5.0", + "_view_name": "HTMLView", + "description": "", + "description_tooltip": null, + "layout": "IPY_MODEL_d76923c171b94131869affe1409b0291", + "placeholder": "​", + "style": "IPY_MODEL_84b25fd321d14ea28ae13d7f73839c74", + "value": " 14.1M/14.1M [00:00<00:00, 32.9MB/s]" + } + }, + "29cc15b9aa404f959ebed0c1fb45635c": { + "model_module": "@jupyter-widgets/base", + "model_name": "LayoutModel", + "model_module_version": "1.2.0", + "state": { + "_model_module": "@jupyter-widgets/base", + "_model_module_version": "1.2.0", + "_model_name": "LayoutModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "LayoutView", + "align_content": null, + "align_items": null, + "align_self": null, + "border": null, + "bottom": null, + "display": null, + "flex": null, + "flex_flow": null, + "grid_area": null, + "grid_auto_columns": null, + "grid_auto_flow": null, + "grid_auto_rows": null, + "grid_column": null, + "grid_gap": null, + "grid_row": null, + "grid_template_areas": null, + "grid_template_columns": null, + "grid_template_rows": null, + "height": null, + "justify_content": null, + "justify_items": null, + "left": null, + "margin": null, + "max_height": null, + "max_width": null, + "min_height": null, + "min_width": null, + "object_fit": null, + "object_position": null, + "order": null, + "overflow": null, + "overflow_x": null, + "overflow_y": null, + "padding": null, + "right": null, + "top": null, + "visibility": null, + "width": null + } + }, + "998e683fee0947a5a1e9154492f0922e": { + "model_module": "@jupyter-widgets/base", + "model_name": "LayoutModel", + "model_module_version": "1.2.0", + "state": { + "_model_module": "@jupyter-widgets/base", + "_model_module_version": "1.2.0", + "_model_name": "LayoutModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "LayoutView", + "align_content": null, + "align_items": null, + "align_self": null, + "border": null, + "bottom": null, + "display": null, + "flex": null, + "flex_flow": null, + "grid_area": null, + "grid_auto_columns": null, + "grid_auto_flow": null, + "grid_auto_rows": null, + "grid_column": null, + "grid_gap": null, + "grid_row": null, + "grid_template_areas": null, + "grid_template_columns": null, + "grid_template_rows": null, + "height": null, + "justify_content": null, + "justify_items": null, + "left": null, + "margin": null, + "max_height": null, + "max_width": null, + "min_height": null, + "min_width": null, + "object_fit": null, + "object_position": null, + "order": null, + "overflow": null, + "overflow_x": null, + "overflow_y": null, + "padding": null, + "right": null, + "top": null, + "visibility": null, + "width": null + } + }, + "c1973d99f832441e92e5cc5c4f7fb4b2": { + "model_module": "@jupyter-widgets/controls", + "model_name": "DescriptionStyleModel", + "model_module_version": "1.5.0", + "state": { + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "DescriptionStyleModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "StyleView", + "description_width": "" + } + }, + "03f366c56c9d42d284a34cbf8adb9e9d": { + "model_module": "@jupyter-widgets/base", + "model_name": "LayoutModel", + "model_module_version": "1.2.0", + "state": { + "_model_module": "@jupyter-widgets/base", + "_model_module_version": "1.2.0", + "_model_name": "LayoutModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "LayoutView", + "align_content": null, + "align_items": null, + "align_self": null, + "border": null, + "bottom": null, + "display": null, + "flex": null, + "flex_flow": null, + "grid_area": null, + "grid_auto_columns": null, + "grid_auto_flow": null, + "grid_auto_rows": null, + "grid_column": null, + "grid_gap": null, + "grid_row": null, + "grid_template_areas": null, + "grid_template_columns": null, + "grid_template_rows": null, + "height": null, + "justify_content": null, + "justify_items": null, + "left": null, + "margin": null, + "max_height": null, + "max_width": null, + "min_height": null, + "min_width": null, + "object_fit": null, + "object_position": null, + "order": null, + "overflow": null, + "overflow_x": null, + "overflow_y": null, + "padding": null, + "right": null, + "top": null, + "visibility": null, + "width": null + } + }, + "800dfe2ac06d4e38a998fdd731692815": { + "model_module": "@jupyter-widgets/controls", + "model_name": "ProgressStyleModel", + "model_module_version": "1.5.0", + "state": { + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "ProgressStyleModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "StyleView", + "bar_color": null, + "description_width": "" + } + }, + "d76923c171b94131869affe1409b0291": { + "model_module": "@jupyter-widgets/base", + "model_name": "LayoutModel", + "model_module_version": "1.2.0", + "state": { + "_model_module": "@jupyter-widgets/base", + "_model_module_version": "1.2.0", + "_model_name": "LayoutModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "LayoutView", + "align_content": null, + "align_items": null, + "align_self": null, + "border": null, + "bottom": null, + "display": null, + "flex": null, + "flex_flow": null, + "grid_area": null, + "grid_auto_columns": null, + "grid_auto_flow": null, + "grid_auto_rows": null, + "grid_column": null, + "grid_gap": null, + "grid_row": null, + "grid_template_areas": null, + "grid_template_columns": null, + "grid_template_rows": null, + "height": null, + "justify_content": null, + "justify_items": null, + "left": null, + "margin": null, + "max_height": null, + "max_width": null, + "min_height": null, + "min_width": null, + "object_fit": null, + "object_position": null, + "order": null, + "overflow": null, + "overflow_x": null, + "overflow_y": null, + "padding": null, + "right": null, + "top": null, + "visibility": null, + "width": null + } + }, + "84b25fd321d14ea28ae13d7f73839c74": { + "model_module": "@jupyter-widgets/controls", + "model_name": "DescriptionStyleModel", + "model_module_version": "1.5.0", + "state": { + "_model_module": "@jupyter-widgets/controls", + "_model_module_version": "1.5.0", + "_model_name": "DescriptionStyleModel", + "_view_count": null, + "_view_module": "@jupyter-widgets/base", + "_view_module_version": "1.2.0", + "_view_name": "StyleView", + "description_width": "" + } } } } @@ -401,7 +743,7 @@ "colab": { "base_uri": "https://localhost:8080/" }, - "outputId": "f9f016ad-3dcf-4bd2-e1c3-d5b79efc6f32" + "outputId": "f0aa921f-9303-46bb-c590-212b518edbe9" }, "source": [ "!git clone https://github.com/ultralytics/yolov5 # clone\n", @@ -412,20 +754,20 @@ "import utils\n", "display = utils.notebook_init() # checks" ], - "execution_count": null, + "execution_count": 11, "outputs": [ { "output_type": "stream", "name": "stderr", "text": [ - "YOLOv5 🚀 v7.0-1-gb32f67f Python-3.7.15 torch-1.12.1+cu113 CUDA:0 (Tesla T4, 15110MiB)\n" + "YOLOv5 🚀 2022-12-23 Python-3.8.16 torch-1.13.0+cu116 CUDA:0 (Tesla T4, 15110MiB)\n" ] }, { "output_type": "stream", "name": "stdout", "text": [ - "Setup complete ✅ (2 CPUs, 12.7 GB RAM, 22.6/78.2 GB disk)\n" + "Setup complete ✅ (2 CPUs, 12.7 GB RAM, 23.1/78.2 GB disk)\n" ] } ] @@ -958,7 +1300,25 @@ { "cell_type": "code", "metadata": { - "id": "GMusP4OAxFu6" + "id": "GMusP4OAxFu6", + "outputId": "e94f4925-0b50-47b2-8593-6c1e6b2c930f", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 822, + "referenced_widgets": [ + "57e23f3f792f4de1ac7a0d1dc66681e0", + "b1ba65ec5cd24545915a0b6d5369e9f4", + "3efa94127181419d816acbe9ffe46a7f", + "0dd9e43ce73f47e9aa9adb7b6ee4d300", + "29cc15b9aa404f959ebed0c1fb45635c", + "998e683fee0947a5a1e9154492f0922e", + "c1973d99f832441e92e5cc5c4f7fb4b2", + "03f366c56c9d42d284a34cbf8adb9e9d", + "800dfe2ac06d4e38a998fdd731692815", + "d76923c171b94131869affe1409b0291", + "84b25fd321d14ea28ae13d7f73839c74" + ] + } }, "source": [ "# YOLOv5 PyTorch HUB Inference (DetectionModels only)\n", @@ -969,8 +1329,175 @@ "results = model(im) # inference\n", "results.print() # or .show(), .save(), .crop(), .pandas(), etc." ], - "execution_count": null, - "outputs": [] + "execution_count": 1, + "outputs": [ + { + "output_type": "stream", + "name": "stderr", + "text": [ + "/usr/local/lib/python3.8/dist-packages/torch/hub.py:267: UserWarning: You are about to download and run code from an untrusted repository. In a future release, this won't be allowed. To add the repository to your trusted list, change the command to {calling_fn}(..., trust_repo=False) and a command prompt will appear asking for an explicit confirmation of trust, or load(..., trust_repo=True), which will assume that the prompt is to be answered with 'yes'. You can also use load(..., trust_repo='check') which will only prompt for confirmation if the repo is not already trusted. This will eventually be the default behaviour\n", + " warnings.warn(\n", + "Downloading: \"https://github.com/ultralytics/yolov5/zipball/master\" to /root/.cache/torch/hub/master.zip\n", + "\u001b[31m\u001b[1mrequirements:\u001b[0m YOLOv5 requirements \"gitpython\" \"ipython\" not found, attempting AutoUpdate...\n", + "Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n", + "Collecting gitpython\n", + " Downloading GitPython-3.1.29-py3-none-any.whl (182 kB)\n", + "Requirement already satisfied: ipython in /usr/local/lib/python3.8/dist-packages (7.9.0)\n", + "Collecting gitdb<5,>=4.0.1\n", + " Downloading gitdb-4.0.10-py3-none-any.whl (62 kB)\n", + "Collecting smmap<6,>=3.0.1\n", + " Downloading smmap-5.0.0-py3-none-any.whl (24 kB)\n", + "Requirement already satisfied: setuptools>=18.5 in /usr/local/lib/python3.8/dist-packages (from ipython) (57.4.0)\n", + "Requirement already satisfied: decorator in /usr/local/lib/python3.8/dist-packages (from ipython) (4.4.2)\n", + "Requirement already satisfied: pickleshare in /usr/local/lib/python3.8/dist-packages (from ipython) (0.7.5)\n", + "Requirement already satisfied: traitlets>=4.2 in /usr/local/lib/python3.8/dist-packages (from ipython) (5.7.1)\n", + "Requirement already satisfied: pexpect in /usr/local/lib/python3.8/dist-packages (from ipython) (4.8.0)\n", + "Requirement already satisfied: backcall in /usr/local/lib/python3.8/dist-packages (from ipython) (0.2.0)\n", + "Collecting jedi>=0.10\n", + " Downloading jedi-0.18.2-py2.py3-none-any.whl (1.6 MB)\n", + "Requirement already satisfied: prompt-toolkit<2.1.0,>=2.0.0 in /usr/local/lib/python3.8/dist-packages (from ipython) (2.0.10)\n", + "Requirement already satisfied: pygments in /usr/local/lib/python3.8/dist-packages (from ipython) (2.6.1)\n", + "Requirement already satisfied: parso<0.9.0,>=0.8.0 in /usr/local/lib/python3.8/dist-packages (from jedi>=0.10->ipython) (0.8.3)\n", + "Requirement already satisfied: wcwidth in /usr/local/lib/python3.8/dist-packages (from prompt-toolkit<2.1.0,>=2.0.0->ipython) (0.2.5)\n", + "Requirement already satisfied: six>=1.9.0 in /usr/local/lib/python3.8/dist-packages (from prompt-toolkit<2.1.0,>=2.0.0->ipython) (1.15.0)\n", + "Requirement already satisfied: ptyprocess>=0.5 in /usr/local/lib/python3.8/dist-packages (from pexpect->ipython) (0.7.0)\n", + "Installing collected packages: smmap, jedi, gitdb, gitpython\n", + "Successfully installed gitdb-4.0.10 gitpython-3.1.29 jedi-0.18.2 smmap-5.0.0\n", + "\n", + "\u001b[31m\u001b[1mrequirements:\u001b[0m 2 packages updated per /root/.cache/torch/hub/ultralytics_yolov5_master/requirements.txt\n", + "\u001b[31m\u001b[1mrequirements:\u001b[0m ⚠️ \u001b[1mRestart runtime or rerun command for updates to take effect\u001b[0m\n", + "\n", + "YOLOv5 🚀 2022-12-23 Python-3.8.16 torch-1.13.0+cu116 CUDA:0 (Tesla T4, 15110MiB)\n", + "\n", + "Downloading https://github.com/ultralytics/yolov5/releases/download/v7.0/yolov5s.pt to yolov5s.pt...\n" + ] + }, + { + "output_type": "display_data", + "data": { + "text/plain": [ + " 0%| | 0.00/14.1M [00:00" + ], + "application/javascript": [ + "(async (port, path, width, height, cache, element) => {\n", + " if (!google.colab.kernel.accessAllowed && !cache) {\n", + " return;\n", + " }\n", + " element.appendChild(document.createTextNode(''));\n", + " const url = await google.colab.kernel.proxyPort(port, {cache});\n", + "\n", + " const external_link = document.createElement('div');\n", + " external_link.innerHTML = `\n", + "
\n", + " Running on \n", + " https://localhost:${port}${path}\n", + " \n", + "
\n", + " `;\n", + " element.appendChild(external_link);\n", + "\n", + " const iframe = document.createElement('iframe');\n", + " iframe.src = new URL(path, url).toString();\n", + " iframe.height = height;\n", + " iframe.allow = \"autoplay; camera; microphone; clipboard-read; clipboard-write;\"\n", + " iframe.width = width;\n", + " iframe.style.border = 0;\n", + " element.appendChild(iframe);\n", + " })(7865, \"/\", \"100%\", 500, false, window.element)" + ] + }, + "metadata": {} + }, + { + "output_type": "execute_result", + "data": { + "text/plain": [] + }, + "metadata": {}, + "execution_count": 15 + } + ] } ] } \ No newline at end of file From 6580c433303bfcac9d685f9a455a25d398e2c449 Mon Sep 17 00:00:00 2001 From: Jiacong Fang Date: Fri, 23 Dec 2022 15:20:15 +0800 Subject: [PATCH 3/9] Update colab notebook tutorial.ipynb --- tutorial.ipynb | 449 ++----------------------------------------------- 1 file changed, 15 insertions(+), 434 deletions(-) diff --git a/tutorial.ipynb b/tutorial.ipynb index 99cecd8478eb..471c4a2c37f0 100644 --- a/tutorial.ipynb +++ b/tutorial.ipynb @@ -355,348 +355,6 @@ "_view_name": "StyleView", "description_width": "" } - }, - "57e23f3f792f4de1ac7a0d1dc66681e0": { - "model_module": "@jupyter-widgets/controls", - "model_name": "HBoxModel", - "model_module_version": "1.5.0", - "state": { - "_dom_classes": [], - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "HBoxModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/controls", - "_view_module_version": "1.5.0", - "_view_name": "HBoxView", - "box_style": "", - "children": [ - "IPY_MODEL_b1ba65ec5cd24545915a0b6d5369e9f4", - "IPY_MODEL_3efa94127181419d816acbe9ffe46a7f", - "IPY_MODEL_0dd9e43ce73f47e9aa9adb7b6ee4d300" - ], - "layout": "IPY_MODEL_29cc15b9aa404f959ebed0c1fb45635c" - } - }, - "b1ba65ec5cd24545915a0b6d5369e9f4": { - "model_module": "@jupyter-widgets/controls", - "model_name": "HTMLModel", - "model_module_version": "1.5.0", - "state": { - "_dom_classes": [], - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "HTMLModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/controls", - "_view_module_version": "1.5.0", - "_view_name": "HTMLView", - "description": "", - "description_tooltip": null, - "layout": "IPY_MODEL_998e683fee0947a5a1e9154492f0922e", - "placeholder": "​", - "style": "IPY_MODEL_c1973d99f832441e92e5cc5c4f7fb4b2", - "value": "100%" - } - }, - "3efa94127181419d816acbe9ffe46a7f": { - "model_module": "@jupyter-widgets/controls", - "model_name": "FloatProgressModel", - "model_module_version": "1.5.0", - "state": { - "_dom_classes": [], - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "FloatProgressModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/controls", - "_view_module_version": "1.5.0", - "_view_name": "ProgressView", - "bar_style": "success", - "description": "", - "description_tooltip": null, - "layout": "IPY_MODEL_03f366c56c9d42d284a34cbf8adb9e9d", - "max": 14808437, - "min": 0, - "orientation": "horizontal", - "style": "IPY_MODEL_800dfe2ac06d4e38a998fdd731692815", - "value": 14808437 - } - }, - "0dd9e43ce73f47e9aa9adb7b6ee4d300": { - "model_module": "@jupyter-widgets/controls", - "model_name": "HTMLModel", - "model_module_version": "1.5.0", - "state": { - "_dom_classes": [], - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "HTMLModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/controls", - "_view_module_version": "1.5.0", - "_view_name": "HTMLView", - "description": "", - "description_tooltip": null, - "layout": "IPY_MODEL_d76923c171b94131869affe1409b0291", - "placeholder": "​", - "style": "IPY_MODEL_84b25fd321d14ea28ae13d7f73839c74", - "value": " 14.1M/14.1M [00:00<00:00, 32.9MB/s]" - } - }, - "29cc15b9aa404f959ebed0c1fb45635c": { - "model_module": "@jupyter-widgets/base", - "model_name": "LayoutModel", - "model_module_version": "1.2.0", - "state": { - "_model_module": "@jupyter-widgets/base", - "_model_module_version": "1.2.0", - "_model_name": "LayoutModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "LayoutView", - "align_content": null, - "align_items": null, - "align_self": null, - "border": null, - "bottom": null, - "display": null, - "flex": null, - "flex_flow": null, - "grid_area": null, - "grid_auto_columns": null, - "grid_auto_flow": null, - "grid_auto_rows": null, - "grid_column": null, - "grid_gap": null, - "grid_row": null, - "grid_template_areas": null, - "grid_template_columns": null, - "grid_template_rows": null, - "height": null, - "justify_content": null, - "justify_items": null, - "left": null, - "margin": null, - "max_height": null, - "max_width": null, - "min_height": null, - "min_width": null, - "object_fit": null, - "object_position": null, - "order": null, - "overflow": null, - "overflow_x": null, - "overflow_y": null, - "padding": null, - "right": null, - "top": null, - "visibility": null, - "width": null - } - }, - "998e683fee0947a5a1e9154492f0922e": { - "model_module": "@jupyter-widgets/base", - "model_name": "LayoutModel", - "model_module_version": "1.2.0", - "state": { - "_model_module": "@jupyter-widgets/base", - "_model_module_version": "1.2.0", - "_model_name": "LayoutModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "LayoutView", - "align_content": null, - "align_items": null, - "align_self": null, - "border": null, - "bottom": null, - "display": null, - "flex": null, - "flex_flow": null, - "grid_area": null, - "grid_auto_columns": null, - "grid_auto_flow": null, - "grid_auto_rows": null, - "grid_column": null, - "grid_gap": null, - "grid_row": null, - "grid_template_areas": null, - "grid_template_columns": null, - "grid_template_rows": null, - "height": null, - "justify_content": null, - "justify_items": null, - "left": null, - "margin": null, - "max_height": null, - "max_width": null, - "min_height": null, - "min_width": null, - "object_fit": null, - "object_position": null, - "order": null, - "overflow": null, - "overflow_x": null, - "overflow_y": null, - "padding": null, - "right": null, - "top": null, - "visibility": null, - "width": null - } - }, - "c1973d99f832441e92e5cc5c4f7fb4b2": { - "model_module": "@jupyter-widgets/controls", - "model_name": "DescriptionStyleModel", - "model_module_version": "1.5.0", - "state": { - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "DescriptionStyleModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "StyleView", - "description_width": "" - } - }, - "03f366c56c9d42d284a34cbf8adb9e9d": { - "model_module": "@jupyter-widgets/base", - "model_name": "LayoutModel", - "model_module_version": "1.2.0", - "state": { - "_model_module": "@jupyter-widgets/base", - "_model_module_version": "1.2.0", - "_model_name": "LayoutModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "LayoutView", - "align_content": null, - "align_items": null, - "align_self": null, - "border": null, - "bottom": null, - "display": null, - "flex": null, - "flex_flow": null, - "grid_area": null, - "grid_auto_columns": null, - "grid_auto_flow": null, - "grid_auto_rows": null, - "grid_column": null, - "grid_gap": null, - "grid_row": null, - "grid_template_areas": null, - "grid_template_columns": null, - "grid_template_rows": null, - "height": null, - "justify_content": null, - "justify_items": null, - "left": null, - "margin": null, - "max_height": null, - "max_width": null, - "min_height": null, - "min_width": null, - "object_fit": null, - "object_position": null, - "order": null, - "overflow": null, - "overflow_x": null, - "overflow_y": null, - "padding": null, - "right": null, - "top": null, - "visibility": null, - "width": null - } - }, - "800dfe2ac06d4e38a998fdd731692815": { - "model_module": "@jupyter-widgets/controls", - "model_name": "ProgressStyleModel", - "model_module_version": "1.5.0", - "state": { - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "ProgressStyleModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "StyleView", - "bar_color": null, - "description_width": "" - } - }, - "d76923c171b94131869affe1409b0291": { - "model_module": "@jupyter-widgets/base", - "model_name": "LayoutModel", - "model_module_version": "1.2.0", - "state": { - "_model_module": "@jupyter-widgets/base", - "_model_module_version": "1.2.0", - "_model_name": "LayoutModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "LayoutView", - "align_content": null, - "align_items": null, - "align_self": null, - "border": null, - "bottom": null, - "display": null, - "flex": null, - "flex_flow": null, - "grid_area": null, - "grid_auto_columns": null, - "grid_auto_flow": null, - "grid_auto_rows": null, - "grid_column": null, - "grid_gap": null, - "grid_row": null, - "grid_template_areas": null, - "grid_template_columns": null, - "grid_template_rows": null, - "height": null, - "justify_content": null, - "justify_items": null, - "left": null, - "margin": null, - "max_height": null, - "max_width": null, - "min_height": null, - "min_width": null, - "object_fit": null, - "object_position": null, - "order": null, - "overflow": null, - "overflow_x": null, - "overflow_y": null, - "padding": null, - "right": null, - "top": null, - "visibility": null, - "width": null - } - }, - "84b25fd321d14ea28ae13d7f73839c74": { - "model_module": "@jupyter-widgets/controls", - "model_name": "DescriptionStyleModel", - "model_module_version": "1.5.0", - "state": { - "_model_module": "@jupyter-widgets/controls", - "_model_module_version": "1.5.0", - "_model_name": "DescriptionStyleModel", - "_view_count": null, - "_view_module": "@jupyter-widgets/base", - "_view_module_version": "1.2.0", - "_view_name": "StyleView", - "description_width": "" - } } } } @@ -1300,25 +958,7 @@ { "cell_type": "code", "metadata": { - "id": "GMusP4OAxFu6", - "outputId": "e94f4925-0b50-47b2-8593-6c1e6b2c930f", - "colab": { - "base_uri": "https://localhost:8080/", - "height": 822, - "referenced_widgets": [ - "57e23f3f792f4de1ac7a0d1dc66681e0", - "b1ba65ec5cd24545915a0b6d5369e9f4", - "3efa94127181419d816acbe9ffe46a7f", - "0dd9e43ce73f47e9aa9adb7b6ee4d300", - "29cc15b9aa404f959ebed0c1fb45635c", - "998e683fee0947a5a1e9154492f0922e", - "c1973d99f832441e92e5cc5c4f7fb4b2", - "03f366c56c9d42d284a34cbf8adb9e9d", - "800dfe2ac06d4e38a998fdd731692815", - "d76923c171b94131869affe1409b0291", - "84b25fd321d14ea28ae13d7f73839c74" - ] - } + "id": "GMusP4OAxFu6" }, "source": [ "# YOLOv5 PyTorch HUB Inference (DetectionModels only)\n", @@ -1329,76 +969,17 @@ "results = model(im) # inference\n", "results.print() # or .show(), .save(), .crop(), .pandas(), etc." ], - "execution_count": 1, - "outputs": [ - { - "output_type": "stream", - "name": "stderr", - "text": [ - "/usr/local/lib/python3.8/dist-packages/torch/hub.py:267: UserWarning: You are about to download and run code from an untrusted repository. In a future release, this won't be allowed. To add the repository to your trusted list, change the command to {calling_fn}(..., trust_repo=False) and a command prompt will appear asking for an explicit confirmation of trust, or load(..., trust_repo=True), which will assume that the prompt is to be answered with 'yes'. You can also use load(..., trust_repo='check') which will only prompt for confirmation if the repo is not already trusted. This will eventually be the default behaviour\n", - " warnings.warn(\n", - "Downloading: \"https://github.com/ultralytics/yolov5/zipball/master\" to /root/.cache/torch/hub/master.zip\n", - "\u001b[31m\u001b[1mrequirements:\u001b[0m YOLOv5 requirements \"gitpython\" \"ipython\" not found, attempting AutoUpdate...\n", - "Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n", - "Collecting gitpython\n", - " Downloading GitPython-3.1.29-py3-none-any.whl (182 kB)\n", - "Requirement already satisfied: ipython in /usr/local/lib/python3.8/dist-packages (7.9.0)\n", - "Collecting gitdb<5,>=4.0.1\n", - " Downloading gitdb-4.0.10-py3-none-any.whl (62 kB)\n", - "Collecting smmap<6,>=3.0.1\n", - " Downloading smmap-5.0.0-py3-none-any.whl (24 kB)\n", - "Requirement already satisfied: setuptools>=18.5 in /usr/local/lib/python3.8/dist-packages (from ipython) (57.4.0)\n", - "Requirement already satisfied: decorator in /usr/local/lib/python3.8/dist-packages (from ipython) (4.4.2)\n", - "Requirement already satisfied: pickleshare in /usr/local/lib/python3.8/dist-packages (from ipython) (0.7.5)\n", - "Requirement already satisfied: traitlets>=4.2 in /usr/local/lib/python3.8/dist-packages (from ipython) (5.7.1)\n", - "Requirement already satisfied: pexpect in /usr/local/lib/python3.8/dist-packages (from ipython) (4.8.0)\n", - "Requirement already satisfied: backcall in /usr/local/lib/python3.8/dist-packages (from ipython) (0.2.0)\n", - "Collecting jedi>=0.10\n", - " Downloading jedi-0.18.2-py2.py3-none-any.whl (1.6 MB)\n", - "Requirement already satisfied: prompt-toolkit<2.1.0,>=2.0.0 in /usr/local/lib/python3.8/dist-packages (from ipython) (2.0.10)\n", - "Requirement already satisfied: pygments in /usr/local/lib/python3.8/dist-packages (from ipython) (2.6.1)\n", - "Requirement already satisfied: parso<0.9.0,>=0.8.0 in /usr/local/lib/python3.8/dist-packages (from jedi>=0.10->ipython) (0.8.3)\n", - "Requirement already satisfied: wcwidth in /usr/local/lib/python3.8/dist-packages (from prompt-toolkit<2.1.0,>=2.0.0->ipython) (0.2.5)\n", - "Requirement already satisfied: six>=1.9.0 in /usr/local/lib/python3.8/dist-packages (from prompt-toolkit<2.1.0,>=2.0.0->ipython) (1.15.0)\n", - "Requirement already satisfied: ptyprocess>=0.5 in /usr/local/lib/python3.8/dist-packages (from pexpect->ipython) (0.7.0)\n", - "Installing collected packages: smmap, jedi, gitdb, gitpython\n", - "Successfully installed gitdb-4.0.10 gitpython-3.1.29 jedi-0.18.2 smmap-5.0.0\n", - "\n", - "\u001b[31m\u001b[1mrequirements:\u001b[0m 2 packages updated per /root/.cache/torch/hub/ultralytics_yolov5_master/requirements.txt\n", - "\u001b[31m\u001b[1mrequirements:\u001b[0m ⚠️ \u001b[1mRestart runtime or rerun command for updates to take effect\u001b[0m\n", - "\n", - "YOLOv5 🚀 2022-12-23 Python-3.8.16 torch-1.13.0+cu116 CUDA:0 (Tesla T4, 15110MiB)\n", - "\n", - "Downloading https://github.com/ultralytics/yolov5/releases/download/v7.0/yolov5s.pt to yolov5s.pt...\n" - ] - }, - { - "output_type": "display_data", - "data": { - "text/plain": [ - " 0%| | 0.00/14.1M [00:00 Date: Fri, 23 Dec 2022 15:22:23 +0800 Subject: [PATCH 4/9] Update colab notebook tutorial.ipynb From 8aab1cd02050fd6c17a2adaa0fd6e612dc894ae3 Mon Sep 17 00:00:00 2001 From: Jiacong Fang Date: Fri, 23 Dec 2022 15:25:02 +0800 Subject: [PATCH 5/9] Update colab notebook tutorial.ipynb --- tutorial.ipynb | 79 +++----------------------------------------------- 1 file changed, 4 insertions(+), 75 deletions(-) diff --git a/tutorial.ipynb b/tutorial.ipynb index 471c4a2c37f0..1d1b68662eed 100644 --- a/tutorial.ipynb +++ b/tutorial.ipynb @@ -412,7 +412,7 @@ "import utils\n", "display = utils.notebook_init() # checks" ], - "execution_count": 11, + "execution_count": null, "outputs": [ { "output_type": "stream", @@ -1004,81 +1004,10 @@ "demo.launch()" ], "metadata": { - "colab": { - "base_uri": "https://localhost:8080/", - "height": 711 - }, - "id": "YVJRQLMQuxxm", - "outputId": "2ef8bcfa-b022-4631-a26a-493d6a2d9688" + "id": "YVJRQLMQuxxm" }, - "execution_count": 15, - "outputs": [ - { - "output_type": "stream", - "name": "stderr", - "text": [ - "YOLOv5 🚀 2022-12-23 Python-3.8.16 torch-1.13.0+cu116 CUDA:0 (Tesla T4, 15110MiB)\n", - "\n", - "Fusing layers... \n", - "YOLOv5s summary: 213 layers, 7225885 parameters, 0 gradients\n", - "Adding AutoShape... \n" - ] - }, - { - "output_type": "stream", - "name": "stdout", - "text": [ - "Colab notebook detected. To show errors in colab notebook, set debug=True in launch()\n", - "Note: opening Chrome Inspector may crash demo inside Colab notebooks.\n", - "\n", - "To create a public link, set `share=True` in `launch()`.\n" - ] - }, - { - "output_type": "display_data", - "data": { - "text/plain": [ - "" - ], - "application/javascript": [ - "(async (port, path, width, height, cache, element) => {\n", - " if (!google.colab.kernel.accessAllowed && !cache) {\n", - " return;\n", - " }\n", - " element.appendChild(document.createTextNode(''));\n", - " const url = await google.colab.kernel.proxyPort(port, {cache});\n", - "\n", - " const external_link = document.createElement('div');\n", - " external_link.innerHTML = `\n", - " \n", - " `;\n", - " element.appendChild(external_link);\n", - "\n", - " const iframe = document.createElement('iframe');\n", - " iframe.src = new URL(path, url).toString();\n", - " iframe.height = height;\n", - " iframe.allow = \"autoplay; camera; microphone; clipboard-read; clipboard-write;\"\n", - " iframe.width = width;\n", - " iframe.style.border = 0;\n", - " element.appendChild(iframe);\n", - " })(7865, \"/\", \"100%\", 500, false, window.element)" - ] - }, - "metadata": {} - }, - { - "output_type": "execute_result", - "data": { - "text/plain": [] - }, - "metadata": {}, - "execution_count": 15 - } - ] + "execution_count": null, + "outputs": [] } ] } \ No newline at end of file From c698731442d22e8eda9ef153e9c4931e9dc1768a Mon Sep 17 00:00:00 2001 From: Jiacong Fang Date: Fri, 23 Dec 2022 15:31:15 +0800 Subject: [PATCH 6/9] Change run() -> predict() in utils/gradio/demo.py --- utils/gradio/demo.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/gradio/demo.py b/utils/gradio/demo.py index 6ec42bcb9476..dbd0df2386ae 100644 --- a/utils/gradio/demo.py +++ b/utils/gradio/demo.py @@ -24,7 +24,7 @@ from utils.dataloaders import IMG_FORMATS -def run(inp, conf, iou, agnostic_nms): +def predict(inp, conf, iou, agnostic_nms): model.conf = conf model.iou = iou model.agnostic = agnostic_nms @@ -58,7 +58,7 @@ def run(inp, conf, iou, agnostic_nms): kwargs = {'path': opt.path} if opt.source == 'local' else {} repo = ROOT if opt.source == 'local' else 'ultralytics/yolov5' # source == 'github' model = torch.hub.load(repo, opt.model, source=opt.source, **kwargs) - demo = gr.Interface(fn=run, + demo = gr.Interface(fn=predict, inputs=[gr.Image(), gr.Slider(0, 1, 0.25), gr.Slider(0, 1, 0.45), gr.Checkbox()], outputs="image", examples=examples) From 0303e6efb290805bd59d04c3faa799fffbd395a1 Mon Sep 17 00:00:00 2001 From: Jiacong Fang Date: Fri, 23 Dec 2022 16:56:06 +0800 Subject: [PATCH 7/9] Add comment for --host 0.0.0.0 sharing --- utils/gradio/demo.py | 1 + 1 file changed, 1 insertion(+) diff --git a/utils/gradio/demo.py b/utils/gradio/demo.py index dbd0df2386ae..e0ea22a3516f 100644 --- a/utils/gradio/demo.py +++ b/utils/gradio/demo.py @@ -1,5 +1,6 @@ """ Run Gradio demo. +Add --host 0.0.0.0 to share with other machines without --share. Usage - local model: python utils/gradio/demo.py --source local --path MODEL_FILE From 8e35e7aeded08f8df8bc279af5f484d0e1764140 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 23 Dec 2022 09:13:47 +0000 Subject: [PATCH 8/9] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- utils/gradio/demo.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/utils/gradio/demo.py b/utils/gradio/demo.py index e0ea22a3516f..7722b539abaa 100644 --- a/utils/gradio/demo.py +++ b/utils/gradio/demo.py @@ -13,6 +13,7 @@ import os import sys from pathlib import Path + import torch FILE = Path(__file__).resolve() @@ -21,8 +22,8 @@ sys.path.append(str(ROOT)) # add ROOT to PATH ROOT = Path(os.path.relpath(ROOT, Path.cwd())) # relative -from utils.general import print_args, check_requirements from utils.dataloaders import IMG_FORMATS +from utils.general import check_requirements, print_args def predict(inp, conf, iou, agnostic_nms): @@ -60,8 +61,9 @@ def predict(inp, conf, iou, agnostic_nms): repo = ROOT if opt.source == 'local' else 'ultralytics/yolov5' # source == 'github' model = torch.hub.load(repo, opt.model, source=opt.source, **kwargs) demo = gr.Interface(fn=predict, - inputs=[gr.Image(), gr.Slider(0, 1, 0.25), gr.Slider(0, 1, 0.45), gr.Checkbox()], + inputs=[gr.Image(), gr.Slider(0, 1, 0.25), + gr.Slider(0, 1, 0.45), + gr.Checkbox()], outputs="image", examples=examples) demo.launch(share=opt.share, server_name=opt.host, server_port=opt.port) - From 5626bbfc67e44ee0c5ba0065d06dc444d5431f11 Mon Sep 17 00:00:00 2001 From: Jiacong Fang Date: Sun, 29 Jan 2023 16:02:28 +0800 Subject: [PATCH 9/9] Remove 'source' command line option --- utils/gradio/demo.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/utils/gradio/demo.py b/utils/gradio/demo.py index 7722b539abaa..af17850e9c51 100644 --- a/utils/gradio/demo.py +++ b/utils/gradio/demo.py @@ -1,12 +1,12 @@ """ Run Gradio demo. -Add --host 0.0.0.0 to share with other machines without --share. +Add --host 0.0.0.0 to share with other machines by IP address. Usage - local model: -python utils/gradio/demo.py --source local --path MODEL_FILE +python utils/gradio/demo.py --path MODEL_FILE Usage - github repo: -python utils/gradio/demo.py --source github --model yolov5s +python utils/gradio/demo.py --model yolov5s """ import argparse @@ -41,7 +41,6 @@ def predict(inp, conf, iou, agnostic_nms): parser.add_argument('--host', type=str, default='localhost', help='server ip/name (0.0.0.0 for network request)') parser.add_argument('--port', type=int, default=7860, help='server port') parser.add_argument('--example_dir', type=str, default=ROOT / 'data/images', help='example image dir') - parser.add_argument('--source', type=str, default='local', help='torch hub source: github/local') parser.add_argument('--model', type=str, default='custom', help='model name used by github source') parser.add_argument('--path', type=str, default=ROOT / 'yolov5l.pt', help='local model path') opt = parser.parse_args() @@ -57,9 +56,10 @@ def predict(inp, conf, iou, agnostic_nms): for f in files: if f.suffix.lower()[1:] in IMG_FORMATS: examples.append([f]) - kwargs = {'path': opt.path} if opt.source == 'local' else {} - repo = ROOT if opt.source == 'local' else 'ultralytics/yolov5' # source == 'github' - model = torch.hub.load(repo, opt.model, source=opt.source, **kwargs) + source = 'local' if opt.model == 'custom' else 'github' + kwargs = {'path': opt.path} if source == 'local' else {} + repo = ROOT if source == 'local' else 'ultralytics/yolov5' + model = torch.hub.load(repo, opt.model, source=source, **kwargs) demo = gr.Interface(fn=predict, inputs=[gr.Image(), gr.Slider(0, 1, 0.25), gr.Slider(0, 1, 0.45),