File size: 1,764 Bytes
c485cb0
 
 
 
ab3b07b
c485cb0
 
 
ab3b07b
c485cb0
 
 
 
ab3b07b
c485cb0
 
 
 
 
 
ab3b07b
c485cb0
 
 
 
 
 
ab3b07b
c485cb0
 
 
 
 
ab3b07b
 
c485cb0
ab3b07b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c485cb0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 140,
   "metadata": {},
   "outputs": [],
   "source": [
    "from ultralyticsplus import YOLO, render_result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 141,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Downloading https://dl.ndl.go.jp/api/iiif/1879314/R0000039/full/640,640/0/default.jpg to 'default.jpg'...\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "100%|β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ| 152k/152k [00:00<00:00, 6.69MB/s]\n"
     ]
    }
   ],
   "source": [
    "# load model\n",
    "model = YOLO('best.pt')\n",
    "# model = YOLO(\"nakamura196/yolov8s-layout-detection\")\n",
    "\n",
    "# set image\n",
    "image = \"https://dl.ndl.go.jp/api/iiif/1879314/R0000039/full/640,640/0/default.jpg\"\n",
    "\n",
    "filename = image.split(\"/\")[-1]\n",
    "\n",
    "import os\n",
    "\n",
    "if image.startswith(\"http\"):\n",
    "\n",
    "    os.remove(filename)\n",
    "\n",
    "# perform inference\n",
    "results = model.predict(image, conf=0.25, verbose=False)\n",
    "\n",
    "# observe results\n",
    "render = render_result(model=model, image=image, result=results[0])\n",
    "render.show()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": ".venv",
   "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.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}