{ "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 }