Spaces:
Running
Running
File size: 2,844 Bytes
10f4748 |
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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from fastsam import FastSAM, FastSAMPrompt\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"model = FastSAM(\"FastSAM-x.pt\")\n",
"IMAGE_PATH = \"./sample_images/3.jpg\"\n"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"DEVICE = \"cpu\""
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"\n",
"image 1/1 /home/ravi.naik/learning/era/s19/sample_images/3.jpg: 704x1024 5 objects, 5524.6ms\n",
"Speed: 77.9ms preprocess, 5524.6ms inference, 75.1ms postprocess per image at shape (1, 3, 1024, 1024)\n"
]
}
],
"source": [
"everything_results = model(\n",
" IMAGE_PATH,\n",
" device=DEVICE,\n",
" retina_masks=True,\n",
" imgsz=1024,\n",
" conf=0.4,\n",
" iou=0.9,\n",
")\n",
"prompt_process = FastSAMPrompt(IMAGE_PATH, everything_results, device=DEVICE)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|βββββββββββββββββββββββββββββββββββββββ| 338M/338M [00:32<00:00, 10.9MiB/s]\n"
]
}
],
"source": [
"# everything prompt\n",
"ann = prompt_process.everything_prompt()\n",
"\n",
"# bbox default shape [0,0,0,0] -> [x1,y1,x2,y2]\n",
"# ann = prompt_process.box_prompt(bbox=[[200, 200, 300, 300]])\n",
"\n",
"# text prompt\n",
"ann = prompt_process.text_prompt(text=\"a photo of a dog\")\n",
"\n",
"# point prompt\n",
"# points default [[0,0]] [[x1,y1],[x2,y2]]\n",
"# point_label default [0] [1,0] 0:background, 1:foreground\n",
"# ann = prompt_process.point_prompt(points=[[620, 360]], pointlabel=[1])\n",
"\n",
"prompt_process.plot(\n",
" annotations=ann,\n",
" output_path=\"./output/dog.jpg\",\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.10.12"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
|