galatasaray commited on
Commit
ff45a16
β€’
1 Parent(s): a47966f
Gradio.ipynb DELETED
@@ -1 +0,0 @@
1
- {"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"Gradio.ipynb","provenance":[],"collapsed_sections":[],"authorship_tag":"ABX9TyMP5m/oK5+rqNLpzprjWgfY"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"code","execution_count":1,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"68CgGISA0OQu","executionInfo":{"status":"ok","timestamp":1657789122929,"user_tz":-180,"elapsed":20255,"user":{"displayName":"orhan ekinci","userId":"08596083551140132378"}},"outputId":"de975cdf-9dd8-4454-f587-bf831c035834"},"outputs":[{"output_type":"stream","name":"stdout","text":["Mounted at /content/drive\n"]}],"source":["from google.colab import drive\n","drive.mount('/content/drive')"]},{"cell_type":"code","source":["!ls \"/content/drive/My Drive/Colab Notebooks/Model Representation/\"\n","%cd drive/My Drive/Colab Notebooks/Model Representation/"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"NN8c3dXt0hfN","executionInfo":{"status":"ok","timestamp":1657789124086,"user_tz":-180,"elapsed":1161,"user":{"displayName":"orhan ekinci","userId":"08596083551140132378"}},"outputId":"0626aab3-f0ea-439e-f487-2c704b22a575"},"execution_count":2,"outputs":[{"output_type":"stream","name":"stdout","text":["datasets flagged Gradio.ipynb saved_model yolov5\n","/content/drive/My Drive/Colab Notebooks/Model Representation\n"]}]},{"cell_type":"code","source":["import os\n","cwd = os.getcwd()\n","cwd"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":35},"id":"vN36F7c50mF4","executionInfo":{"status":"ok","timestamp":1657789124087,"user_tz":-180,"elapsed":11,"user":{"displayName":"orhan ekinci","userId":"08596083551140132378"}},"outputId":"85d491ab-1f37-40bd-f344-0ca02e38065c"},"execution_count":3,"outputs":[{"output_type":"execute_result","data":{"text/plain":["'/content/drive/My Drive/Colab Notebooks/Model Representation'"],"application/vnd.google.colaboratory.intrinsic+json":{"type":"string"}},"metadata":{},"execution_count":3}]},{"cell_type":"code","source":["!pip install -qr https://raw.githubusercontent.com/ultralytics/yolov5/master/requirements.txt gradio # install dependencies"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"8xT1CQBM1Afx","executionInfo":{"status":"ok","timestamp":1657789272147,"user_tz":-180,"elapsed":148069,"user":{"displayName":"orhan ekinci","userId":"08596083551140132378"}},"outputId":"f45c871a-7627-45c3-c529-aca081b2253d"},"execution_count":4,"outputs":[{"output_type":"stream","name":"stdout","text":["\u001b[K |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 5.1 MB 4.3 MB/s \n","\u001b[K |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 596 kB 45.0 MB/s \n","\u001b[K |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 750.6 MB 11 kB/s \n","\u001b[K |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 21.0 MB 1.3 MB/s \n","\u001b[K |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 57 kB 4.5 MB/s \n","\u001b[K |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 54 kB 3.0 MB/s \n","\u001b[K |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 212 kB 59.8 MB/s \n","\u001b[K |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 2.3 MB 44.1 MB/s \n","\u001b[K |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 1.1 MB 50.8 MB/s \n","\u001b[K |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 84 kB 2.7 MB/s \n","\u001b[K |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 140 kB 58.8 MB/s \n","\u001b[K |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 272 kB 43.8 MB/s \n","\u001b[K |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 84 kB 2.9 MB/s \n","\u001b[K |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 94 kB 2.9 MB/s \n","\u001b[K |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 144 kB 47.4 MB/s \n","\u001b[K |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 271 kB 41.4 MB/s \n","\u001b[K |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 63 kB 1.8 MB/s \n","\u001b[K |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 80 kB 8.1 MB/s \n","\u001b[K |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 68 kB 6.1 MB/s \n","\u001b[K |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 54 kB 2.9 MB/s \n","\u001b[K |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 43 kB 2.1 MB/s \n","\u001b[K |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 62 kB 804 kB/s \n","\u001b[K |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 856 kB 59.3 MB/s \n","\u001b[K |β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 4.1 MB 42.2 MB/s \n","\u001b[?25h Building wheel for ffmpy (setup.py) ... \u001b[?25l\u001b[?25hdone\n"," Building wheel for python-multipart (setup.py) ... \u001b[?25l\u001b[?25hdone\n","\u001b[31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n","torchtext 0.13.0 requires torch==1.12.0, but you have torch 1.11.0 which is incompatible.\n","torchaudio 0.12.0+cu113 requires torch==1.12.0, but you have torch 1.11.0 which is incompatible.\u001b[0m\n"]}]},{"cell_type":"code","source":["import gradio as gr\n","import torch\n","from PIL import Image\n","\n","# Images\n","#torch.hub.download_url_to_file('https://github.com/ultralytics/yolov5/raw/master/data/images/zidane.jpg', 'zidane.jpg')\n","#torch.hub.download_url_to_file('https://github.com/ultralytics/yolov5/raw/master/data/images/bus.jpg', 'bus.jpg')\n","\n","# Model\n","#model = torch.hub.load('ultralytics/yolov5', 'yolov5s') # force_reload=True to update\n","\n","model = torch.hub.load(cwd+'/yolov5', 'custom', path=cwd+'/saved_model/yolov5s.pt', source='local') # local model\n","\n","\n","\n","def yolo(im, size=640):\n"," g = (size / max(im.size)) # gain\n"," im = im.resize((int(x * g) for x in im.size), Image.ANTIALIAS) # resize\n","\n"," results = model(im) # inference\n"," results.render() # updates results.imgs with boxes and labels\n"," return Image.fromarray(results.imgs[0])\n","\n","\n","inputs = gr.inputs.Image(type='pil', label=\"Original Image\")\n","outputs = gr.outputs.Image(type=\"pil\", label=\"Output Image\")\n","\n","title = \"YOLOv5\"\n","description = \"YOLOv5 Gradio demo for object detection. Upload an image or click an example image to use.\"\n","article = \"<p style='text-align: center'>YOLOv5 is a family of compound-scaled object detection models trained on the COCO dataset, and includes \" \\\n"," \"simple functionality for Test Time Augmentation (TTA), model ensembling, hyperparameter evolution, \" \\\n"," \"and export to ONNX, CoreML and TFLite. <a href='https://github.com/ultralytics/yolov5'>Source code</a> |\" \\\n"," \"<a href='https://apps.apple.com/app/id1452689527'>iOS App</a> | <a href='https://pytorch.org/hub/ultralytics_yolov5'>PyTorch Hub</a></p>\"\n","\n","examples = [[cwd+'/datasets/zidane.jpg'], [cwd+'/datasets/bus.jpg']]\n","gr.Interface(yolo, inputs, outputs, title=title, description=description, article=article, examples=examples, analytics_enabled=False).launch(\n"," debug=True)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":1000},"id":"FwCb9Nmk1n6n","executionInfo":{"status":"ok","timestamp":1657788661371,"user_tz":-180,"elapsed":223749,"user":{"displayName":"orhan ekinci","userId":"08596083551140132378"}},"outputId":"219fa614-9dda-4870-fe54-dfce5b4e4b05"},"execution_count":10,"outputs":[{"output_type":"stream","name":"stderr","text":["\u001b[31m\u001b[1mrequirements:\u001b[0m PyYAML>=5.3.1 not found and is required by YOLOv5, attempting auto-update...\n","Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n","Requirement already satisfied: PyYAML>=5.3.1 in /usr/local/lib/python3.7/dist-packages (6.0)\n","\n","\u001b[31m\u001b[1mrequirements:\u001b[0m torch!=1.12.0,>=1.7.0 not found and is required by YOLOv5, attempting auto-update...\n","Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n","Requirement already satisfied: torch!=1.12.0,>=1.7.0 in /usr/local/lib/python3.7/dist-packages (1.11.0)\n","Requirement already satisfied: typing-extensions in /usr/local/lib/python3.7/dist-packages (from torch!=1.12.0,>=1.7.0) (4.1.1)\n","\n","\u001b[31m\u001b[1mrequirements:\u001b[0m torchvision!=0.13.0,>=0.8.1 not found and is required by YOLOv5, attempting auto-update...\n","Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n","Requirement already satisfied: torchvision!=0.13.0,>=0.8.1 in /usr/local/lib/python3.7/dist-packages (0.12.0)\n","Requirement already satisfied: torch==1.11.0 in /usr/local/lib/python3.7/dist-packages (from torchvision!=0.13.0,>=0.8.1) (1.11.0)\n","Requirement already satisfied: pillow!=8.3.*,>=5.3.0 in /usr/local/lib/python3.7/dist-packages (from torchvision!=0.13.0,>=0.8.1) (7.1.2)\n","Requirement already satisfied: requests in /usr/local/lib/python3.7/dist-packages (from torchvision!=0.13.0,>=0.8.1) (2.23.0)\n","Requirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (from torchvision!=0.13.0,>=0.8.1) (1.21.6)\n","Requirement already satisfied: typing-extensions in /usr/local/lib/python3.7/dist-packages (from torchvision!=0.13.0,>=0.8.1) (4.1.1)\n","Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.7/dist-packages (from requests->torchvision!=0.13.0,>=0.8.1) (3.0.4)\n","Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.7/dist-packages (from requests->torchvision!=0.13.0,>=0.8.1) (1.24.3)\n","Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/dist-packages (from requests->torchvision!=0.13.0,>=0.8.1) (2022.6.15)\n","Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.7/dist-packages (from requests->torchvision!=0.13.0,>=0.8.1) (2.10)\n","\n","\u001b[31m\u001b[1mrequirements:\u001b[0m 3 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-7-14 Python-3.7.13 torch-1.11.0+cu102 CPU\n","\n","Fusing layers... \n","YOLOv5s summary: 213 layers, 7225885 parameters, 0 gradients\n","Adding AutoShape... \n","/usr/local/lib/python3.7/dist-packages/gradio/deprecation.py:40: UserWarning: `optional` parameter is deprecated, and it has no effect\n"," warnings.warn(value)\n"]},{"output_type":"stream","name":"stdout","text":["Colab notebook detected. This cell will run indefinitely so that you can see errors and logs. To turn off, set debug=False in launch().\n"]},{"output_type":"stream","name":"stderr","text":["Connected (version 2.0, client OpenSSH_7.6p1)\n","Authentication (publickey) successful!\n"]},{"output_type":"stream","name":"stdout","text":["Running on public URL: https://21879.gradio.app\n","\n","This share link expires in 72 hours. For free permanent hosting, check out Spaces (https://huggingface.co/spaces)\n"]},{"output_type":"display_data","data":{"text/plain":["<IPython.core.display.HTML object>"],"text/html":["<div><iframe src=\"https://21879.gradio.app\" width=\"900\" height=\"500\" allow=\"autoplay; camera; microphone;\" frameborder=\"0\" allowfullscreen></iframe></div>"]},"metadata":{}},{"output_type":"stream","name":"stdout","text":["Keyboard interruption in main thread... closing server.\n"]},{"output_type":"execute_result","data":{"text/plain":["(<gradio.routes.App at 0x7f39e2421b50>,\n"," 'http://127.0.0.1:7860/',\n"," 'https://21879.gradio.app')"]},"metadata":{},"execution_count":10}]},{"cell_type":"code","source":["import gradio as gr\n","import torch\n","from PIL import Image\n","\n","# Images\n","#torch.hub.download_url_to_file('https://github.com/ultralytics/yolov5/raw/master/data/images/zidane.jpg', 'zidane.jpg')\n","#torch.hub.download_url_to_file('https://github.com/ultralytics/yolov5/raw/master/data/images/bus.jpg', 'bus.jpg')\n","\n","# Model\n","#model = torch.hub.load('ultralytics/yolov5', 'yolov5s') # force_reload=True to update\n","model = torch.hub.load(cwd+'/yolov5', 'custom', path=cwd+'/saved_model/s1000_best.pt', source='local') # local model\n","\n","\n","def yolo(im, size=640):\n"," g = (size / max(im.size)) # gain\n"," im = im.resize((int(x * g) for x in im.size), Image.ANTIALIAS) # resize\n","\n"," results = model(im) # inference\n"," results.render() # updates results.imgs with boxes and labels\n"," return Image.fromarray(results.imgs[0])\n","\n","\n","inputs = gr.inputs.Image(type='pil', label=\"Original Image\")\n","outputs = gr.outputs.Image(type=\"pil\", label=\"Output Image\")\n","\n","title = \"YOLOv5\"\n","description = \"YOLOv5 Gradio demo for object detection. Upload an image or click an example image to use.\"\n","article = \"<p style='text-align: center'>YOLOv5 is a family of compound-scaled object detection models trained on the COCO dataset, and includes \" \\\n"," \"simple functionality for Test Time Augmentation (TTA), model ensembling, hyperparameter evolution, \" \\\n"," \"and export to ONNX, CoreML and TFLite. <a href='https://github.com/ultralytics/yolov5'>Source code</a> |\" \\\n"," \"<a href='https://apps.apple.com/app/id1452689527'>iOS App</a> | <a href='https://pytorch.org/hub/ultralytics_yolov5'>PyTorch Hub</a></p>\"\n","\n","path_folder = cwd+'/datasets/s1000/'\n","examples = [[path_folder+'s1000 (1).png'], [path_folder+'s1000 (2).png'],[path_folder+'s1000 (3).png'],[path_folder+'s1000 (4).png'],[path_folder+'s1000 (5).png']]\n","gr.Interface(yolo, inputs, outputs, title=title, description=description, article=article, examples=examples, analytics_enabled=False).launch(\n"," debug=True)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":1000},"id":"8kaOPNyz2cEr","executionInfo":{"status":"ok","timestamp":1657789820492,"user_tz":-180,"elapsed":541032,"user":{"displayName":"orhan ekinci","userId":"08596083551140132378"}},"outputId":"dd0ad238-a602-4bd0-e610-2f523a37d378"},"execution_count":5,"outputs":[{"output_type":"stream","name":"stderr","text":["\u001b[31m\u001b[1mrequirements:\u001b[0m PyYAML>=5.3.1 not found and is required by YOLOv5, attempting auto-update...\n","Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n","Requirement already satisfied: PyYAML>=5.3.1 in /usr/local/lib/python3.7/dist-packages (6.0)\n","\n","\u001b[31m\u001b[1mrequirements:\u001b[0m torch>=1.7.0 not found and is required by YOLOv5, attempting auto-update...\n","Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n","Requirement already satisfied: torch>=1.7.0 in /usr/local/lib/python3.7/dist-packages (1.11.0)\n","Requirement already satisfied: typing-extensions in /usr/local/lib/python3.7/dist-packages (from torch>=1.7.0) (4.1.1)\n","\n","\u001b[31m\u001b[1mrequirements:\u001b[0m torchvision>=0.8.1 not found and is required by YOLOv5, attempting auto-update...\n","Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n","Requirement already satisfied: torchvision>=0.8.1 in /usr/local/lib/python3.7/dist-packages (0.12.0)\n","Requirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (from torchvision>=0.8.1) (1.21.6)\n","Requirement already satisfied: pillow!=8.3.*,>=5.3.0 in /usr/local/lib/python3.7/dist-packages (from torchvision>=0.8.1) (7.1.2)\n","Requirement already satisfied: torch==1.11.0 in /usr/local/lib/python3.7/dist-packages (from torchvision>=0.8.1) (1.11.0)\n","Requirement already satisfied: requests in /usr/local/lib/python3.7/dist-packages (from torchvision>=0.8.1) (2.23.0)\n","Requirement already satisfied: typing-extensions in /usr/local/lib/python3.7/dist-packages (from torchvision>=0.8.1) (4.1.1)\n","Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.7/dist-packages (from requests->torchvision>=0.8.1) (2.10)\n","Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.7/dist-packages (from requests->torchvision>=0.8.1) (1.24.3)\n","Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.7/dist-packages (from requests->torchvision>=0.8.1) (3.0.4)\n","Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/dist-packages (from requests->torchvision>=0.8.1) (2022.6.15)\n","\n","\u001b[31m\u001b[1mrequirements:\u001b[0m 3 packages updated per /content/drive/My Drive/Colab Notebooks/Model Representation/yolov5/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-6-24 Python-3.7.13 torch-1.11.0+cu102 CPU\n","\n","Fusing layers... \n","Model summary: 213 layers, 7012822 parameters, 0 gradients\n","Adding AutoShape... \n","/usr/local/lib/python3.7/dist-packages/gradio/deprecation.py:40: UserWarning: `optional` parameter is deprecated, and it has no effect\n"," warnings.warn(value)\n"]},{"output_type":"stream","name":"stdout","text":["Colab notebook detected. This cell will run indefinitely so that you can see errors and logs. To turn off, set debug=False in launch().\n"]},{"output_type":"stream","name":"stderr","text":["Connected (version 2.0, client OpenSSH_7.6p1)\n","Authentication (publickey) successful!\n"]},{"output_type":"stream","name":"stdout","text":["Running on public URL: https://32048.gradio.app\n","\n","This share link expires in 72 hours. For free permanent hosting, check out Spaces (https://huggingface.co/spaces)\n"]},{"output_type":"display_data","data":{"text/plain":["<IPython.core.display.HTML object>"],"text/html":["<div><iframe src=\"https://32048.gradio.app\" width=\"900\" height=\"500\" allow=\"autoplay; camera; microphone;\" frameborder=\"0\" allowfullscreen></iframe></div>"]},"metadata":{}},{"output_type":"stream","name":"stderr","text":["Traceback (most recent call last):\n"," File \"/usr/local/lib/python3.7/dist-packages/gradio/routes.py\", line 256, in run_predict\n"," fn_index, raw_input, username, session_state\n"," File \"/usr/local/lib/python3.7/dist-packages/gradio/blocks.py\", line 548, in process_api\n"," predictions, duration = await self.call_function(fn_index, processed_input)\n"," File \"/usr/local/lib/python3.7/dist-packages/gradio/blocks.py\", line 464, in call_function\n"," block_fn.fn, *processed_input, limiter=self.limiter\n"," File \"/usr/local/lib/python3.7/dist-packages/anyio/to_thread.py\", line 32, in run_sync\n"," func, *args, cancellable=cancellable, limiter=limiter\n"," File \"/usr/local/lib/python3.7/dist-packages/anyio/_backends/_asyncio.py\", line 937, in run_sync_in_worker_thread\n"," return await future\n"," File \"/usr/local/lib/python3.7/dist-packages/anyio/_backends/_asyncio.py\", line 867, in run\n"," result = context.run(func, *args)\n"," File \"/usr/local/lib/python3.7/dist-packages/gradio/interface.py\", line 515, in <lambda>\n"," if len(self.output_components) == 1\n"," File \"/usr/local/lib/python3.7/dist-packages/gradio/interface.py\", line 718, in run_prediction\n"," prediction = predict_fn(*processed_input)\n"," File \"<ipython-input-5-7438d39302b1>\", line 15, in yolo\n"," g = (size / max(im.size)) # gain\n","AttributeError: 'NoneType' object has no attribute 'size'\n"]},{"output_type":"stream","name":"stdout","text":["Keyboard interruption in main thread... closing server.\n"]},{"output_type":"execute_result","data":{"text/plain":["(<gradio.routes.App at 0x7f9be15b0ed0>,\n"," 'http://127.0.0.1:7860/',\n"," 'https://32048.gradio.app')"]},"metadata":{},"execution_count":5}]}]}
 
 
app.py CHANGED
@@ -2,9 +2,14 @@ import gradio as gr
2
  import torch
3
  from PIL import Image
4
 
 
5
  import os
6
  cwd = os.getcwd()
7
 
 
 
 
 
8
  # Images
9
  #torch.hub.download_url_to_file('https://github.com/ultralytics/yolov5/raw/master/data/images/zidane.jpg', 'zidane.jpg')
10
  #torch.hub.download_url_to_file('https://github.com/ultralytics/yolov5/raw/master/data/images/bus.jpg', 'bus.jpg')
@@ -34,6 +39,20 @@ article = "<p style='text-align: center'>YOLOv5 is a family of compound-scaled o
34
  "<a href='https://apps.apple.com/app/id1452689527'>iOS App</a> | <a href='https://pytorch.org/hub/ultralytics_yolov5'>PyTorch Hub</a></p>"
35
 
36
  path_folder = cwd+'/datasets/s1000/'
37
- examples = [[path_folder+'s1000 (1).png'], [path_folder+'s1000 (2).png'],[path_folder+'s1000 (3).png'],[path_folder+'s1000 (4).png'],[path_folder+'s1000 (5).png']]
38
  gr.Interface(yolo, inputs, outputs, title=title, description=description, article=article, examples=examples, analytics_enabled=False).launch(
39
- debug=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  import torch
3
  from PIL import Image
4
 
5
+
6
  import os
7
  cwd = os.getcwd()
8
 
9
+ # !pip install -qr https://raw.githubusercontent.com/ultralytics/yolov5/master/requirements.txt gradio
10
+
11
+
12
+
13
  # Images
14
  #torch.hub.download_url_to_file('https://github.com/ultralytics/yolov5/raw/master/data/images/zidane.jpg', 'zidane.jpg')
15
  #torch.hub.download_url_to_file('https://github.com/ultralytics/yolov5/raw/master/data/images/bus.jpg', 'bus.jpg')
 
39
  "<a href='https://apps.apple.com/app/id1452689527'>iOS App</a> | <a href='https://pytorch.org/hub/ultralytics_yolov5'>PyTorch Hub</a></p>"
40
 
41
  path_folder = cwd+'/datasets/s1000/'
42
+ examples = [[path_folder+'s1000_50_metre.jpg'], [path_folder+'s1000_100_metre.jpg'],[path_folder+'s1000_150_metre.jpg'],[path_folder+'s1000_200_metre.jpg'],[path_folder+'s1000_250_metre.jpg']]
43
  gr.Interface(yolo, inputs, outputs, title=title, description=description, article=article, examples=examples, analytics_enabled=False).launch(
44
+ debug=True)
45
+
46
+
47
+ '''
48
+
49
+
50
+ git init
51
+ git config user.name bulentsofttech
52
+ git config user.email bulent.softtech@gmail.com
53
+ git add *
54
+ git commit -m "WriteCommit"
55
+ git push origin master
56
+
57
+
58
+ '''
datasets/s1000/s1000 (1).jpg DELETED
Binary file (882 kB)
 
datasets/s1000/s1000 (2).jpg DELETED
Binary file (884 kB)
 
datasets/s1000/s1000 (3).jpg DELETED
Binary file (858 kB)
 
datasets/s1000/s1000 (4).jpg DELETED
Binary file (847 kB)
 
datasets/s1000/s1000 (5).jpg DELETED
Binary file (877 kB)
 
datasets/s1000/s1000_100_metre.jpg ADDED
datasets/s1000/s1000_150_metre.jpg ADDED
datasets/s1000/s1000_200_metre.jpg ADDED
datasets/s1000/s1000_250_metre.jpg ADDED
datasets/s1000/s1000_50_metre.jpg ADDED