From b0947dd5671e4a5c8a2c77a1449a84618b49c6a8 Mon Sep 17 00:00:00 2001 From: lyhue1991 Date: Fri, 28 Apr 2023 22:32:13 +0800 Subject: [PATCH] =?UTF-8?q?Delete=2001=5FYOLOv8=E5=BC=80=E7=AE=B1=E4=BD=93?= =?UTF-8?q?=E9=AA=8C.ipynb?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...347\256\261\344\275\223\351\252\214.ipynb" | 549 ------------------ 1 file changed, 549 deletions(-) delete mode 100644 "01_YOLOv8\345\274\200\347\256\261\344\275\223\351\252\214.ipynb" diff --git "a/01_YOLOv8\345\274\200\347\256\261\344\275\223\351\252\214.ipynb" "b/01_YOLOv8\345\274\200\347\256\261\344\275\223\351\252\214.ipynb" deleted file mode 100644 index f9ed3ae..0000000 --- "a/01_YOLOv8\345\274\200\347\256\261\344\275\223\351\252\214.ipynb" +++ /dev/null @@ -1,549 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "4a515130", - "metadata": { - "slideshow": { - "slide_type": "slide" - } - }, - "source": [ - "# YOLOv8 开箱体验\n" - ] - }, - { - "cell_type": "markdown", - "id": "1948498e-3712-444d-b48e-2f6166e5a427", - "metadata": { - "slideshow": { - "slide_type": "slide" - } - }, - "source": [ - "yolov8是ultralytics公司于2023年1月开源的anchor-free的最新目标检测算法框架。\n", - "\n", - "封装在ultralytics这个库中:https://github.com/ultralytics/ultralytics" - ] - }, - { - "cell_type": "markdown", - "id": "87106d37-5ba3-4d66-949d-389b203ed43e", - "metadata": { - "slideshow": { - "slide_type": "slide" - } - }, - "source": [ - "\n", - "它具有以下优点:\n", - "\n", - "1,性能速度领先:借鉴了之前许多YOLO版本的trick,达到了领先的性能和极致的速度。\n", - "\n", - "![](./data/yolov8性能速度.png)\n" - ] - }, - { - "cell_type": "markdown", - "id": "938de0e4-5fce-4cfa-af38-d9220f903e1c", - "metadata": { - "slideshow": { - "slide_type": "slide" - } - }, - "source": [ - "2,多种任务支持:支持图片分类,目标检测, 实例分割,目标追踪,关键点检测 这些最常用的CV任务。\n", - "\n", - "![](https://user-images.githubusercontent.com/15766192/226470476-1e2c0587-fefc-468c-a236-9468af7f3c76.png)" - ] - }, - { - "cell_type": "markdown", - "id": "9b7a7754-c6c8-4e33-b921-934b9cbdd7b4", - "metadata": { - "slideshow": { - "slide_type": "slide" - } - }, - "source": [ - "3,完整的落地工具链: 提供从数据准备,到模型训练,模型评估,到模型导出部署 整个工业落地应用非常完整的工具。\n", - "\n", - "![](./data/ultralytics工具链.png)" - ] - }, - { - "cell_type": "markdown", - "id": "36912d38-68ed-4988-8f87-0cfbc78ab821", - "metadata": { - "slideshow": { - "slide_type": "slide" - } - }, - "source": [ - "4,强大的灵活性:ultralytics主打以python库的形式使用,方便定制化改进算法或者用于其它CV项目中。\n", - "\n", - "我感觉ultralytics的使用体验,非常像xgboost/lightgbm/catboost这些库,使用简单,功能强大。\n", - "\n", - "完全不懂原理的小白,简单粗暴把数据喂进去,就能够做出非常好的效果。\n", - "\n", - "下面我们主要演示yolov8中的预训练模型的使用方法。\n" - ] - }, - { - "cell_type": "markdown", - "id": "aee61da1-ec2c-4849-ba3c-552bf48ec924", - "metadata": { - "slideshow": { - "slide_type": "slide" - } - }, - "source": [ - "## 〇,环境准备" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "736bceb6-4a65-459f-ae09-a18aeee99895", - "metadata": { - "code_folding": [], - "slideshow": { - "slide_type": "-" - } - }, - "outputs": [], - "source": [ - "#!pip install -U ultralytics -i https://pypi.tuna.tsinghua.edu.cn/simple\n", - "#!pip install torchkeras -i https://pypi.tuna.tsinghua.edu.cn/simple\n", - "#!pip install 'lap>=0.4' -i https://pypi.tuna.tsinghua.edu.cn/simple" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "591e661b-090a-4aae-bcf3-e839a59132e0", - "metadata": { - "slideshow": { - "slide_type": "" - } - }, - "outputs": [], - "source": [ - "import ultralytics\n", - "print(ultralytics.__version__)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "e0a437e2-515b-4a15-bb97-432916f45248", - "metadata": { - "code_folding": [], - "slideshow": { - "slide_type": "-" - } - }, - "outputs": [], - "source": [ - "from PIL import Image \n", - "from torchkeras.data import get_example_image\n", - "import torch \n", - "img = get_example_image('park.jpg')\n", - "img.save('park.jpg')" - ] - }, - { - "cell_type": "markdown", - "id": "80b4efa6-0350-4323-affc-9674f41f97d9", - "metadata": { - "slideshow": { - "slide_type": "slide" - } - }, - "source": [ - "## 一,图片分类" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "57a84f6f-d605-46eb-9d6f-b7ae9f3479a5", - "metadata": { - "slideshow": { - "slide_type": "-" - } - }, - "outputs": [], - "source": [ - "from ultralytics import YOLO \n", - "model = YOLO('yolov8n-cls.pt')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "58c00650", - "metadata": { - "code_folding": [], - "slideshow": { - "slide_type": "-" - } - }, - "outputs": [], - "source": [ - "#save保存预测可视化, save_txt保存预测\n", - "preds = model.predict(source='park.jpg',save_txt=True,save=True) " - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "aaa15246-ad26-4ff6-8b5f-db90feacab59", - "metadata": { - "code_folding": [], - "slideshow": { - "slide_type": "slide" - } - }, - "outputs": [], - "source": [ - "#查看预测结果\n", - "from PIL import Image \n", - "Image.open(model.predictor.save_dir/'park.jpg')" - ] - }, - { - "cell_type": "markdown", - "id": "7bf0b047-8e45-4224-aaba-8c710e82bf7a", - "metadata": { - "slideshow": { - "slide_type": "slide" - } - }, - "source": [ - "## 二,目标检测" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "7f0c3f5b-40d8-47a9-bc3c-e91076863be9", - "metadata": { - "slideshow": { - "slide_type": "-" - } - }, - "outputs": [], - "source": [ - "from ultralytics import YOLO \n", - "model = YOLO('yolov8n.pt')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "b1307e2d-cf18-427e-b136-cc5453ed6a19", - "metadata": { - "slideshow": { - "slide_type": "-" - } - }, - "outputs": [], - "source": [ - "#save保存预测可视化, save_txt保存预测\n", - "preds = model.predict(source='park.jpg',save_txt=True,save=True) " - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "94100de6", - "metadata": { - "slideshow": { - "slide_type": "slide" - } - }, - "outputs": [], - "source": [ - "#查看预测结果\n", - "from PIL import Image \n", - "Image.open(model.predictor.save_dir/'park.jpg')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "040bf3ca-a9ef-43f1-954a-d578ba0b4e68", - "metadata": { - "slideshow": { - "slide_type": "slide" - } - }, - "outputs": [], - "source": [ - "#摄像头作为输入\n", - "model.predict(source=0, show=True)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "d51e0710-e238-42f8-8f11-1e054bb75615", - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "markdown", - "id": "e1b268b7-719b-4e37-8a55-742b16bdc989", - "metadata": { - "slideshow": { - "slide_type": "slide" - } - }, - "source": [ - "## 三,目标追踪" - ] - }, - { - "cell_type": "markdown", - "id": "a17ca0c0-6017-4af7-a5ab-f50b7c8f5707", - "metadata": { - "slideshow": { - "slide_type": "-" - } - }, - "source": [ - "目标追踪使用的是目标检测模型,输出中可以给视频中的每个对象分配一个id。\n", - "常用于给视频中某类物体出现的个数进行计数。" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "24e2b7e9-d3a7-4541-8adf-15df76a80753", - "metadata": { - "slideshow": { - "slide_type": "-" - } - }, - "outputs": [], - "source": [ - "from ultralytics import YOLO \n", - "model = YOLO('yolov8n.pt')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "67d0be42-7cb0-4c24-9935-df8d762915bc", - "metadata": { - "code_folding": [ - 4 - ], - "slideshow": { - "slide_type": "-" - } - }, - "outputs": [], - "source": [ - "from ultralytics.yolo.utils import set_logging\n", - "set_logging(verbose=False)\n", - "\n", - "#视频作为输入\n", - "preds = model.track(\n", - " source='乒乓球.mp4',\n", - " save=True,\n", - " show=True\n", - ")\n", - "for p in preds[::20]:\n", - " print(p.boxes.id)\n", - " " - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "c101ea60-c733-466b-952f-ef1578580bfc", - "metadata": { - "slideshow": { - "slide_type": "slide" - } - }, - "outputs": [], - "source": [ - "#摄像头作为输入\n", - "model.track(source=0, show=True)" - ] - }, - { - "cell_type": "markdown", - "id": "c5f7f0b5-19a2-4177-a10d-65a85843f267", - "metadata": { - "slideshow": { - "slide_type": "slide" - } - }, - "source": [ - "## 四,实例分割" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "e2e47ff1-b818-4967-b85c-1f2cb34edb9e", - "metadata": { - "slideshow": { - "slide_type": "-" - } - }, - "outputs": [], - "source": [ - "from ultralytics import YOLO \n", - "model = YOLO('yolov8s-seg.pt')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "95e9c394-c736-4889-af2b-331375c50232", - "metadata": { - "slideshow": { - "slide_type": "-" - } - }, - "outputs": [], - "source": [ - "#save保存预测可视化, save_txt保存预测\n", - "preds = model.predict(source='park.jpg',save_txt=True,save=True) \n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "f810d292", - "metadata": { - "slideshow": { - "slide_type": "slide" - } - }, - "outputs": [], - "source": [ - "#查看预测结果\n", - "from PIL import Image \n", - "Image.open(model.predictor.save_dir/'park.jpg')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "255c7670-0ef0-4c7a-a6ee-124c3fc3c5d8", - "metadata": { - "slideshow": { - "slide_type": "slide" - } - }, - "outputs": [], - "source": [ - "#摄像头作为输入\n", - "preds = model.predict(source=0, show=True)" - ] - }, - { - "cell_type": "markdown", - "id": "fbacdb7e-c5ae-4106-93ae-6c610f5ce6c6", - "metadata": { - "slideshow": { - "slide_type": "slide" - } - }, - "source": [ - "## 五,关键点检测" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "a0b92c7d-69d0-4ce5-83c4-149a4523557b", - "metadata": { - "slideshow": { - "slide_type": "-" - } - }, - "outputs": [], - "source": [ - "from ultralytics import YOLO \n", - "model = YOLO('yolov8s-pose.pt')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "97c00c49", - "metadata": { - "code_folding": [], - "slideshow": { - "slide_type": "-" - } - }, - "outputs": [], - "source": [ - "#save保存预测可视化, save_txt保存预测\n", - "preds = model.predict(source='park.jpg',save_txt=True,save=True) " - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "f96a20bc-bd22-453c-9ad7-c7c9c7c935e1", - "metadata": { - "code_folding": [], - "slideshow": { - "slide_type": "slide" - } - }, - "outputs": [], - "source": [ - "from PIL import Image \n", - "Image.open(model.predictor.save_dir/'park.jpg')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "2466b04f-2a30-4eb2-8c00-cca3fa2e628d", - "metadata": { - "slideshow": { - "slide_type": "slide" - } - }, - "outputs": [], - "source": [ - "#摄像头进行预测\n", - "preds = model.predict(source=0,show=True) " - ] - } - ], - "metadata": { - "celltoolbar": "Slideshow", - "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.0" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -}