Commit
·
7ecd6f5
1
Parent(s):
363c22a
Upload grounded_segment_anything_colab.ipynb
Browse files
grounded_segment_anything_colab.ipynb
ADDED
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": null,
|
6 |
+
"metadata": {
|
7 |
+
"id": "YyaHcAkaOt7b"
|
8 |
+
},
|
9 |
+
"outputs": [],
|
10 |
+
"source": [
|
11 |
+
"%cd /content\n",
|
12 |
+
"!pip install -q torch==2.0.0+cu118 torchvision==0.15.1+cu118 torchaudio==2.0.1+cu118 torchtext==0.15.1 torchdata==0.6.0 --extra-index-url https://download.pytorch.org/whl/cu118 -U\n",
|
13 |
+
"!pip install -q xformers==0.0.18 triton==2.0.0 -U\n",
|
14 |
+
"\n",
|
15 |
+
"!apt-get -y install -qq aria2\n",
|
16 |
+
"!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/camenduru/ovseg/resolve/main/sam_vit_h_4b8939.pth -d /content -o sam_vit_h_4b8939.pth\n",
|
17 |
+
"\n",
|
18 |
+
"!git clone -b dev https://github.com/camenduru/Grounded-Segment-Anything\n",
|
19 |
+
"%cd /content/Grounded-Segment-Anything\n",
|
20 |
+
"!pip install -q -r requirements.txt\n",
|
21 |
+
"%cd /content/Grounded-Segment-Anything/GroundingDINO\n",
|
22 |
+
"!pip install -q .\n",
|
23 |
+
"%cd /content/Grounded-Segment-Anything/segment_anything\n",
|
24 |
+
"!pip install -q .\n",
|
25 |
+
"\n",
|
26 |
+
"import os\n",
|
27 |
+
"import shlex\n",
|
28 |
+
"import subprocess\n",
|
29 |
+
"from pathlib import Path\n",
|
30 |
+
"from typing import Union\n",
|
31 |
+
"\n",
|
32 |
+
"id_rsa_file = \"/content/Grounded-Segment-Anything/id_rsa\"\n",
|
33 |
+
"id_rsa_pub_file = \"/content/Grounded-Segment-Anything/id_rsa.pub\"\n",
|
34 |
+
"if os.path.exists(id_rsa_file):\n",
|
35 |
+
" os.remove(id_rsa_file)\n",
|
36 |
+
"if os.path.exists(id_rsa_pub_file):\n",
|
37 |
+
" os.remove(id_rsa_pub_file)\n",
|
38 |
+
"\n",
|
39 |
+
"def gen_key(path: Union[str, Path]) -> None:\n",
|
40 |
+
" path = Path(path)\n",
|
41 |
+
" arg_string = f'ssh-keygen -t rsa -b 4096 -N \"\" -q -f {path.as_posix()}'\n",
|
42 |
+
" args = shlex.split(arg_string)\n",
|
43 |
+
" subprocess.run(args, check=True)\n",
|
44 |
+
" path.chmod(0o600)\n",
|
45 |
+
"\n",
|
46 |
+
"ssh_name = \"id_rsa\"\n",
|
47 |
+
"ssh_path = Path(os.path.dirname(os.getcwd())) / ssh_name\n",
|
48 |
+
"gen_key(ssh_path)"
|
49 |
+
]
|
50 |
+
},
|
51 |
+
{
|
52 |
+
"cell_type": "code",
|
53 |
+
"execution_count": null,
|
54 |
+
"metadata": {
|
55 |
+
"id": "MoW8GUIFFs-x"
|
56 |
+
},
|
57 |
+
"outputs": [],
|
58 |
+
"source": [
|
59 |
+
"%cd /content/Grounded-Segment-Anything\n",
|
60 |
+
"\n",
|
61 |
+
"import threading\n",
|
62 |
+
"def tunnel():\n",
|
63 |
+
" !ssh -R 80:127.0.0.1:7860 -o StrictHostKeyChecking=no -i /content/Grounded-Segment-Anything/id_rsa remote.moe\n",
|
64 |
+
"threading.Thread(target=tunnel, daemon=True).start()\n",
|
65 |
+
"\n",
|
66 |
+
"print(\"Please wait until you see the 'Running on local URL' message.\")\n",
|
67 |
+
"\n",
|
68 |
+
"!python gradio_app.py --debug --share"
|
69 |
+
]
|
70 |
+
}
|
71 |
+
],
|
72 |
+
"metadata": {
|
73 |
+
"accelerator": "GPU",
|
74 |
+
"colab": {
|
75 |
+
"provenance": []
|
76 |
+
},
|
77 |
+
"gpuClass": "standard",
|
78 |
+
"kernelspec": {
|
79 |
+
"display_name": "Python 3",
|
80 |
+
"name": "python3"
|
81 |
+
},
|
82 |
+
"language_info": {
|
83 |
+
"name": "python"
|
84 |
+
}
|
85 |
+
},
|
86 |
+
"nbformat": 4,
|
87 |
+
"nbformat_minor": 0
|
88 |
+
}
|