├── .github └── FUNDING.yml ├── LICENSE ├── README.md ├── grounded-segment-anything-colab.ipynb └── grounded-segment-anything-custom.ipynb /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: camenduru 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: camenduru 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry 13 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 🐣 Please follow me for new updates https://twitter.com/camenduru
2 | 🔥 Please join our discord server https://discord.gg/k5BwmmvJJU
3 | 🥳 Please join my patreon community https://patreon.com/camenduru
4 | 5 | ## 🚦 WIP 🚦 6 | 7 | ## 🦒 Colab 8 | 9 | | Colab | Info 10 | | --- | --- | 11 | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/camenduru/grounded-segment-anything-colab/blob/main/grounded-segment-anything-colab.ipynb) | grounded-segment-anything-colab
runwayml/stable-diffusion-inpainting 12 | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/camenduru/grounded-segment-anything-colab/blob/main/grounded-segment-anything-custom.ipynb)
🚦 WIP 🚦 | grounded-segment-anything-custom
Custom Inpainting Model
maybe only 16-bit inpainting diffuser models are compatible with Free T4 😐

16-bit models
ckpt/dreamlike-diffusion-1.0-inpainting
runwayml/stable-diffusion-inpainting
ckpt/f222-inpainting
ckpt/realistic_vision_inpainting
ckpt/SS_0.15_x_protogen-inpainting
ckpt/PhotoMerge-inpainting
ckpt/AniMerge-inpainting 13 | 14 | ## Main Repo 15 | https://github.com/IDEA-Research/Grounded-Segment-Anything 16 | 17 | ## Paper 18 | https://arxiv.org/abs/2304.02643
19 | https://arxiv.org/abs/2303.05499
20 | 21 | 22 | ## Tutorial 23 | https://www.youtube.com/watch?v=A7x513Ah1Zk 24 | 25 | ## Output 26 | | . | . 27 | | --- | --- | 28 | ![segment-inpainting](https://user-images.githubusercontent.com/54370274/230939654-6e667075-1c5c-4e91-9720-69631cd259dc.png) | ![segment-inpainting3](https://user-images.githubusercontent.com/54370274/231049649-a0c57991-ec04-4d2d-a10d-cca75ab92a13.png) 29 | -------------------------------------------------------------------------------- /grounded-segment-anything-colab.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "id": "view-in-github" 7 | }, 8 | "source": [ 9 | "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/camenduru/grounded-segment-anything-colab/blob/main/grounded-segment-anything-colab.ipynb)" 10 | ] 11 | }, 12 | { 13 | "cell_type": "code", 14 | "execution_count": null, 15 | "metadata": { 16 | "id": "YyaHcAkaOt7b" 17 | }, 18 | "outputs": [], 19 | "source": [ 20 | "%cd /content\n", 21 | "!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", 22 | "!pip install -q xformers==0.0.18 triton==2.0.0 -U\n", 23 | "\n", 24 | "!apt-get -y install -qq aria2\n", 25 | "!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", 26 | "\n", 27 | "!git clone -b dev https://github.com/camenduru/Grounded-Segment-Anything\n", 28 | "%cd /content/Grounded-Segment-Anything\n", 29 | "!pip install -q -r requirements.txt\n", 30 | "%cd /content/Grounded-Segment-Anything/GroundingDINO\n", 31 | "!pip install -q .\n", 32 | "%cd /content/Grounded-Segment-Anything/segment_anything\n", 33 | "!pip install -q .\n", 34 | "\n", 35 | "import os\n", 36 | "import shlex\n", 37 | "import subprocess\n", 38 | "from pathlib import Path\n", 39 | "from typing import Union\n", 40 | "\n", 41 | "id_rsa_file = \"/content/Grounded-Segment-Anything/id_rsa\"\n", 42 | "id_rsa_pub_file = \"/content/Grounded-Segment-Anything/id_rsa.pub\"\n", 43 | "if os.path.exists(id_rsa_file):\n", 44 | " os.remove(id_rsa_file)\n", 45 | "if os.path.exists(id_rsa_pub_file):\n", 46 | " os.remove(id_rsa_pub_file)\n", 47 | "\n", 48 | "def gen_key(path: Union[str, Path]) -> None:\n", 49 | " path = Path(path)\n", 50 | " arg_string = f'ssh-keygen -t rsa -b 4096 -N \"\" -q -f {path.as_posix()}'\n", 51 | " args = shlex.split(arg_string)\n", 52 | " subprocess.run(args, check=True)\n", 53 | " path.chmod(0o600)\n", 54 | "\n", 55 | "ssh_name = \"id_rsa\"\n", 56 | "ssh_path = Path(os.path.dirname(os.getcwd())) / ssh_name\n", 57 | "gen_key(ssh_path)" 58 | ] 59 | }, 60 | { 61 | "cell_type": "code", 62 | "execution_count": null, 63 | "metadata": {}, 64 | "outputs": [], 65 | "source": [ 66 | "%cd /content/Grounded-Segment-Anything\n", 67 | "\n", 68 | "import threading\n", 69 | "def tunnel():\n", 70 | " !ssh -R 80:127.0.0.1:7860 -o StrictHostKeyChecking=no -i /content/Grounded-Segment-Anything/id_rsa remote.moe\n", 71 | "threading.Thread(target=tunnel, daemon=True).start()\n", 72 | "\n", 73 | "print(\"Please wait until you see the 'Running on local URL' message.\")\n", 74 | "\n", 75 | "!python gradio_app.py --debug --share" 76 | ] 77 | } 78 | ], 79 | "metadata": { 80 | "accelerator": "GPU", 81 | "colab": { 82 | "provenance": [] 83 | }, 84 | "gpuClass": "standard", 85 | "kernelspec": { 86 | "display_name": "Python 3", 87 | "name": "python3" 88 | }, 89 | "language_info": { 90 | "name": "python" 91 | } 92 | }, 93 | "nbformat": 4, 94 | "nbformat_minor": 0 95 | } 96 | -------------------------------------------------------------------------------- /grounded-segment-anything-custom.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "id": "view-in-github" 7 | }, 8 | "source": [ 9 | "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/camenduru/grounded-segment-anything-colab/blob/main/grounded-segment-anything-custom.ipynb)" 10 | ] 11 | }, 12 | { 13 | "cell_type": "code", 14 | "execution_count": null, 15 | "metadata": { 16 | "id": "YyaHcAkaOt7b" 17 | }, 18 | "outputs": [], 19 | "source": [ 20 | "%cd /content\n", 21 | "!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", 22 | "!pip install -q xformers==0.0.18 triton==2.0.0 -U\n", 23 | "\n", 24 | "!apt-get -y install -qq aria2\n", 25 | "!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", 26 | "\n", 27 | "!git clone -b v1.1 https://github.com/camenduru/Grounded-Segment-Anything\n", 28 | "%cd /content/Grounded-Segment-Anything\n", 29 | "!pip install -q -r requirements.txt\n", 30 | "%cd /content/Grounded-Segment-Anything/GroundingDINO\n", 31 | "!pip install -q .\n", 32 | "%cd /content/Grounded-Segment-Anything/segment_anything\n", 33 | "!pip install -q .\n", 34 | "\n", 35 | "import os\n", 36 | "import shlex\n", 37 | "import subprocess\n", 38 | "from pathlib import Path\n", 39 | "from typing import Union\n", 40 | "\n", 41 | "id_rsa_file = \"/content/Grounded-Segment-Anything/id_rsa\"\n", 42 | "id_rsa_pub_file = \"/content/Grounded-Segment-Anything/id_rsa.pub\"\n", 43 | "if os.path.exists(id_rsa_file):\n", 44 | " os.remove(id_rsa_file)\n", 45 | "if os.path.exists(id_rsa_pub_file):\n", 46 | " os.remove(id_rsa_pub_file)\n", 47 | "\n", 48 | "def gen_key(path: Union[str, Path]) -> None:\n", 49 | " path = Path(path)\n", 50 | " arg_string = f'ssh-keygen -t rsa -b 4096 -N \"\" -q -f {path.as_posix()}'\n", 51 | " args = shlex.split(arg_string)\n", 52 | " subprocess.run(args, check=True)\n", 53 | " path.chmod(0o600)\n", 54 | "\n", 55 | "ssh_name = \"id_rsa\"\n", 56 | "ssh_path = Path(os.path.dirname(os.getcwd())) / ssh_name\n", 57 | "gen_key(ssh_path)" 58 | ] 59 | }, 60 | { 61 | "cell_type": "code", 62 | "execution_count": null, 63 | "metadata": {}, 64 | "outputs": [], 65 | "source": [ 66 | "%cd /content/Grounded-Segment-Anything\n", 67 | "\n", 68 | "import threading\n", 69 | "def tunnel():\n", 70 | " !ssh -R 80:127.0.0.1:7860 -o StrictHostKeyChecking=no -i /content/Grounded-Segment-Anything/id_rsa remote.moe\n", 71 | "threading.Thread(target=tunnel, daemon=True).start()\n", 72 | "\n", 73 | "print(\"Please wait until you see the 'Running on local URL' message.\")\n", 74 | "\n", 75 | "!python gradio_app.py --debug --share" 76 | ] 77 | } 78 | ], 79 | "metadata": { 80 | "accelerator": "GPU", 81 | "colab": { 82 | "provenance": [] 83 | }, 84 | "gpuClass": "standard", 85 | "kernelspec": { 86 | "display_name": "Python 3", 87 | "name": "python3" 88 | }, 89 | "language_info": { 90 | "name": "python" 91 | } 92 | }, 93 | "nbformat": 4, 94 | "nbformat_minor": 0 95 | } 96 | --------------------------------------------------------------------------------