IDEA-Research / Grounded-Segment-Anything

Grounded SAM: Marrying Grounding DINO with Segment Anything & Stable Diffusion & Recognize Anything - Automatically Detect , Segment and Generate Anything
https://arxiv.org/abs/2401.14159
Apache License 2.0
15.16k stars 1.4k forks source link

Getting error "No module named 'groundingdino'" #43

Closed jordan-barrett-jm closed 1 year ago

jordan-barrett-jm commented 1 year ago

I get this module import error when I attempt to run the grounded_sam.ipynb notebook

jordan-barrett-jm commented 1 year ago

ModuleNotFoundError Traceback (most recent call last) in <cell line: 11>() 9 10 # Grounding DINO ---> 11 import GroundingDINO.groundingdino.datasets.transforms as T 12 from GroundingDINO.groundingdino.models import build_model 13 from GroundingDINO.groundingdino.util import box_ops

/content/Grounded-Segment-Anything/GroundingDINO/groundingdino/datasets/transforms.py in 11 import torchvision.transforms.functional as F 12 ---> 13 from groundingdino.util.box_ops import box_xyxy_to_cxcywh 14 from groundingdino.util.misc import interpolate 15

ModuleNotFoundError: No module named 'groundingdino'

SlongLiu commented 1 year ago

It seems like you fail to install the grounding dino library. Please make sure you perform each cells from the top of the notebooks. Or you can run python -m pip install -e GroundingDINO .

jordan-barrett-jm commented 1 year ago

I ran that code block but same error. I even tried running pip install -e . from within the GroundingDINO folder...same issue

SlongLiu commented 1 year ago

Can you help to check if the lib is installed successfully? By pasting the log after performing the python -m pip install -e GroundingDINO

jordan-barrett-jm commented 1 year ago

Here you go

Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/ Obtaining file:///content/Grounded-Segment-Anything/GroundingDINO Preparing metadata (setup.py) ... done Requirement already satisfied: torch in /usr/local/lib/python3.9/dist-packages (from groundingdino==0.1.0) (2.0.0+cu118) Requirement already satisfied: torchvision in /usr/local/lib/python3.9/dist-packages (from groundingdino==0.1.0) (0.15.1+cu118) Collecting transformers Downloading transformers-4.27.4-py3-none-any.whl (6.8 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 6.8/6.8 MB 65.2 MB/s eta 0:00:00 Collecting addict Downloading addict-2.4.0-py3-none-any.whl (3.8 kB) Collecting yapf Downloading yapf-0.32.0-py2.py3-none-any.whl (190 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 190.2/190.2 KB 21.3 MB/s eta 0:00:00 Collecting timm Downloading timm-0.6.13-py3-none-any.whl (549 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 549.1/549.1 KB 39.7 MB/s eta 0:00:00 Requirement already satisfied: numpy in /usr/local/lib/python3.9/dist-packages (from groundingdino==0.1.0) (1.22.4) Requirement already satisfied: opencv-python in /usr/local/lib/python3.9/dist-packages (from groundingdino==0.1.0) (4.7.0.72) Collecting supervision==0.3.2 Downloading supervision-0.3.2-py3-none-any.whl (23 kB) Requirement already satisfied: pycocotools in /usr/local/lib/python3.9/dist-packages (from groundingdino==0.1.0) (2.0.6) Requirement already satisfied: matplotlib in /usr/local/lib/python3.9/dist-packages (from supervision==0.3.2->groundingdino==0.1.0) (3.7.1) Requirement already satisfied: pyyaml in /usr/local/lib/python3.9/dist-packages (from timm->groundingdino==0.1.0) (6.0) Collecting huggingface-hub Downloading huggingface_hub-0.13.4-py3-none-any.whl (200 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 200.1/200.1 KB 24.7 MB/s eta 0:00:00 Requirement already satisfied: triton==2.0.0 in /usr/local/lib/python3.9/dist-packages (from torch->groundingdino==0.1.0) (2.0.0) Requirement already satisfied: jinja2 in /usr/local/lib/python3.9/dist-packages (from torch->groundingdino==0.1.0) (3.1.2) Requirement already satisfied: typing-extensions in /usr/local/lib/python3.9/dist-packages (from torch->groundingdino==0.1.0) (4.5.0) Requirement already satisfied: filelock in /usr/local/lib/python3.9/dist-packages (from torch->groundingdino==0.1.0) (3.10.7) Requirement already satisfied: networkx in /usr/local/lib/python3.9/dist-packages (from torch->groundingdino==0.1.0) (3.0) Requirement already satisfied: sympy in /usr/local/lib/python3.9/dist-packages (from torch->groundingdino==0.1.0) (1.11.1) Requirement already satisfied: lit in /usr/local/lib/python3.9/dist-packages (from triton==2.0.0->torch->groundingdino==0.1.0) (16.0.0) Requirement already satisfied: cmake in /usr/local/lib/python3.9/dist-packages (from triton==2.0.0->torch->groundingdino==0.1.0) (3.25.2) Requirement already satisfied: pillow!=8.3.*,>=5.3.0 in /usr/local/lib/python3.9/dist-packages (from torchvision->groundingdino==0.1.0) (8.4.0) Requirement already satisfied: requests in /usr/local/lib/python3.9/dist-packages (from torchvision->groundingdino==0.1.0) (2.27.1) Collecting tokenizers!=0.11.3,<0.14,>=0.11.1 Downloading tokenizers-0.13.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.8 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 7.8/7.8 MB 81.9 MB/s eta 0:00:00 Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.9/dist-packages (from transformers->groundingdino==0.1.0) (23.0) Requirement already satisfied: regex!=2019.12.17 in /usr/local/lib/python3.9/dist-packages (from transformers->groundingdino==0.1.0) (2022.10.31) Requirement already satisfied: tqdm>=4.27 in /usr/local/lib/python3.9/dist-packages (from transformers->groundingdino==0.1.0) (4.65.0) Requirement already satisfied: python-dateutil>=2.7 in /usr/local/lib/python3.9/dist-packages (from matplotlib->supervision==0.3.2->groundingdino==0.1.0) (2.8.2) Requirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.9/dist-packages (from matplotlib->supervision==0.3.2->groundingdino==0.1.0) (4.39.3) Requirement already satisfied: pyparsing>=2.3.1 in /usr/local/lib/python3.9/dist-packages (from matplotlib->supervision==0.3.2->groundingdino==0.1.0) (3.0.9) Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.9/dist-packages (from matplotlib->supervision==0.3.2->groundingdino==0.1.0) (0.11.0) Requirement already satisfied: contourpy>=1.0.1 in /usr/local/lib/python3.9/dist-packages (from matplotlib->supervision==0.3.2->groundingdino==0.1.0) (1.0.7) Requirement already satisfied: importlib-resources>=3.2.0 in /usr/local/lib/python3.9/dist-packages (from matplotlib->supervision==0.3.2->groundingdino==0.1.0) (5.12.0) Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.9/dist-packages (from matplotlib->supervision==0.3.2->groundingdino==0.1.0) (1.4.4) Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.9/dist-packages (from jinja2->torch->groundingdino==0.1.0) (2.1.2) Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.9/dist-packages (from requests->torchvision->groundingdino==0.1.0) (3.4) Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.9/dist-packages (from requests->torchvision->groundingdino==0.1.0) (1.26.15) Requirement already satisfied: charset-normalizer~=2.0.0 in /usr/local/lib/python3.9/dist-packages (from requests->torchvision->groundingdino==0.1.0) (2.0.12) Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.9/dist-packages (from requests->torchvision->groundingdino==0.1.0) (2022.12.7) Requirement already satisfied: mpmath>=0.19 in /usr/local/lib/python3.9/dist-packages (from sympy->torch->groundingdino==0.1.0) (1.3.0) Requirement already satisfied: zipp>=3.1.0 in /usr/local/lib/python3.9/dist-packages (from importlib-resources>=3.2.0->matplotlib->supervision==0.3.2->groundingdino==0.1.0) (3.15.0) Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.9/dist-packages (from python-dateutil>=2.7->matplotlib->supervision==0.3.2->groundingdino==0.1.0) (1.16.0) Installing collected packages: yapf, tokenizers, addict, huggingface-hub, transformers, supervision, timm, groundingdino Running setup.py develop for groundingdino Successfully installed addict-2.4.0 groundingdino-0.1.0 huggingface-hub-0.13.4 supervision-0.3.2 timm-0.6.13 tokenizers-0.13.3 transformers-4.27.4 yapf-0.32.0

jordan-barrett-jm commented 1 year ago

If I run it a second time this is the output

Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/ Obtaining file:///content/Grounded-Segment-Anything/GroundingDINO Preparing metadata (setup.py) ... done Requirement already satisfied: torch in /usr/local/lib/python3.9/dist-packages (from groundingdino==0.1.0) (2.0.0+cu118) Requirement already satisfied: torchvision in /usr/local/lib/python3.9/dist-packages (from groundingdino==0.1.0) (0.15.1+cu118) Requirement already satisfied: transformers in /usr/local/lib/python3.9/dist-packages (from groundingdino==0.1.0) (4.27.4) Requirement already satisfied: addict in /usr/local/lib/python3.9/dist-packages (from groundingdino==0.1.0) (2.4.0) Requirement already satisfied: yapf in /usr/local/lib/python3.9/dist-packages (from groundingdino==0.1.0) (0.32.0) Requirement already satisfied: timm in /usr/local/lib/python3.9/dist-packages (from groundingdino==0.1.0) (0.6.13) Requirement already satisfied: numpy in /usr/local/lib/python3.9/dist-packages (from groundingdino==0.1.0) (1.22.4) Requirement already satisfied: opencv-python in /usr/local/lib/python3.9/dist-packages (from groundingdino==0.1.0) (4.7.0.72) Requirement already satisfied: supervision==0.3.2 in /usr/local/lib/python3.9/dist-packages (from groundingdino==0.1.0) (0.3.2) Requirement already satisfied: pycocotools in /usr/local/lib/python3.9/dist-packages (from groundingdino==0.1.0) (2.0.6) Requirement already satisfied: matplotlib in /usr/local/lib/python3.9/dist-packages (from supervision==0.3.2->groundingdino==0.1.0) (3.7.1) Requirement already satisfied: huggingface-hub in /usr/local/lib/python3.9/dist-packages (from timm->groundingdino==0.1.0) (0.13.4) Requirement already satisfied: pyyaml in /usr/local/lib/python3.9/dist-packages (from timm->groundingdino==0.1.0) (6.0) Requirement already satisfied: networkx in /usr/local/lib/python3.9/dist-packages (from torch->groundingdino==0.1.0) (3.0) Requirement already satisfied: triton==2.0.0 in /usr/local/lib/python3.9/dist-packages (from torch->groundingdino==0.1.0) (2.0.0) Requirement already satisfied: sympy in /usr/local/lib/python3.9/dist-packages (from torch->groundingdino==0.1.0) (1.11.1) Requirement already satisfied: typing-extensions in /usr/local/lib/python3.9/dist-packages (from torch->groundingdino==0.1.0) (4.5.0) Requirement already satisfied: filelock in /usr/local/lib/python3.9/dist-packages (from torch->groundingdino==0.1.0) (3.10.7) Requirement already satisfied: jinja2 in /usr/local/lib/python3.9/dist-packages (from torch->groundingdino==0.1.0) (3.1.2) Requirement already satisfied: cmake in /usr/local/lib/python3.9/dist-packages (from triton==2.0.0->torch->groundingdino==0.1.0) (3.25.2) Requirement already satisfied: lit in /usr/local/lib/python3.9/dist-packages (from triton==2.0.0->torch->groundingdino==0.1.0) (16.0.0) Requirement already satisfied: requests in /usr/local/lib/python3.9/dist-packages (from torchvision->groundingdino==0.1.0) (2.27.1) Requirement already satisfied: pillow!=8.3.*,>=5.3.0 in /usr/local/lib/python3.9/dist-packages (from torchvision->groundingdino==0.1.0) (8.4.0) Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.9/dist-packages (from transformers->groundingdino==0.1.0) (23.0) Requirement already satisfied: regex!=2019.12.17 in /usr/local/lib/python3.9/dist-packages (from transformers->groundingdino==0.1.0) (2022.10.31) Requirement already satisfied: tqdm>=4.27 in /usr/local/lib/python3.9/dist-packages (from transformers->groundingdino==0.1.0) (4.65.0) Requirement already satisfied: tokenizers!=0.11.3,<0.14,>=0.11.1 in /usr/local/lib/python3.9/dist-packages (from transformers->groundingdino==0.1.0) (0.13.3) Requirement already satisfied: importlib-resources>=3.2.0 in /usr/local/lib/python3.9/dist-packages (from matplotlib->supervision==0.3.2->groundingdino==0.1.0) (5.12.0) Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.9/dist-packages (from matplotlib->supervision==0.3.2->groundingdino==0.1.0) (1.4.4) Requirement already satisfied: contourpy>=1.0.1 in /usr/local/lib/python3.9/dist-packages (from matplotlib->supervision==0.3.2->groundingdino==0.1.0) (1.0.7) Requirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.9/dist-packages (from matplotlib->supervision==0.3.2->groundingdino==0.1.0) (4.39.3) Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.9/dist-packages (from matplotlib->supervision==0.3.2->groundingdino==0.1.0) (0.11.0) Requirement already satisfied: pyparsing>=2.3.1 in /usr/local/lib/python3.9/dist-packages (from matplotlib->supervision==0.3.2->groundingdino==0.1.0) (3.0.9) Requirement already satisfied: python-dateutil>=2.7 in /usr/local/lib/python3.9/dist-packages (from matplotlib->supervision==0.3.2->groundingdino==0.1.0) (2.8.2) Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.9/dist-packages (from jinja2->torch->groundingdino==0.1.0) (2.1.2) Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/local/lib/python3.9/dist-packages (from requests->torchvision->groundingdino==0.1.0) (1.26.15) Requirement already satisfied: charset-normalizer~=2.0.0 in /usr/local/lib/python3.9/dist-packages (from requests->torchvision->groundingdino==0.1.0) (2.0.12) Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.9/dist-packages (from requests->torchvision->groundingdino==0.1.0) (2022.12.7) Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.9/dist-packages (from requests->torchvision->groundingdino==0.1.0) (3.4) Requirement already satisfied: mpmath>=0.19 in /usr/local/lib/python3.9/dist-packages (from sympy->torch->groundingdino==0.1.0) (1.3.0) Requirement already satisfied: zipp>=3.1.0 in /usr/local/lib/python3.9/dist-packages (from importlib-resources>=3.2.0->matplotlib->supervision==0.3.2->groundingdino==0.1.0) (3.15.0) Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.9/dist-packages (from python-dateutil>=2.7->matplotlib->supervision==0.3.2->groundingdino==0.1.0) (1.16.0) Installing collected packages: groundingdino Attempting uninstall: groundingdino Found existing installation: groundingdino 0.1.0 Can't uninstall 'groundingdino'. No files were found to uninstall. Running setup.py develop for groundingdino Successfully installed groundingdino-0.1.0

yzhu319 commented 1 year ago

same issue here

stefanjaspers commented 1 year ago

Same issue, the first cell in the notebook ran without errors and groundingdino-0.1.0 was installed successfully.

image

jordan-barrett-jm commented 1 year ago

Fixed the problem by installing the modules from their respective git repos (didn't bother cloning this one). !pip install git+https://github.com/facebookresearch/segment-anything.git

!git clone https://github.com/IDEA-Research/GroundingDINO %cd /content/GroundingDINO !pip install -e .

! pip install diffusers transformers accelerate scipy safetensors

I also changed how I import the models (I also commented out the transforms import because it's not used in the notebook.

import argparse
import os
import copy

import numpy as np
import torch
from PIL import Image, ImageDraw, ImageFont
from torchvision.ops import box_convert

# Grounding DINO

from groundingdino.models import build_model
from groundingdino.util import box_ops
from groundingdino.util.slconfig import SLConfig
from groundingdino.util.utils import clean_state_dict, get_phrases_from_posmap
from groundingdino.util.inference import annotate, load_image, predict
# import groundingdino.datasets.transforms as T

import supervision as sv

# segment anything
from segment_anything import build_sam, SamPredictor 
import cv2
import numpy as np
import matplotlib.pyplot as plt

# diffusers
import PIL
import requests
import torch
from io import BytesIO
from diffusers import StableDiffusionInpaintPipeline

from huggingface_hub import hf_hub_download
jordan-barrett-jm commented 1 year ago

Also, ensure you're in the GroundingDINO folder before importing

stefanjaspers commented 1 year ago

Also, ensure you're in the GroundingDINO folder before importing

Sorry for reopening, but I have a question. Which versions of Python, PyTorch, Torchvision and CUDA are you using?

jordan-barrett-jm commented 1 year ago

Also, ensure you're in the GroundingDINO folder before importing

Sorry for reopening, but I have a question. Which versions of Python, PyTorch, Torchvision and CUDA are you using?

No worries, here's the output

Python version: 3.9.16 (main, Dec  7 2022, 01:11:51) 
[GCC 9.4.0]
PyTorch version: 2.0.0+cu118
Torchvision version: 0.15.1+cu118
CUDA version: 11.8
stefanjaspers commented 1 year ago

Thank you! And last question: Are you using a virtual environment, a Conda environment or neither?

jordan-barrett-jm commented 1 year ago

Nope I'm not

On Mon, Apr 10, 2023 at 5:44 PM Stefan Jaspers @.***> wrote:

Thank you! And last question: Are you using a virtual environment, a Conda environment or neither?

— Reply to this email directly, view it on GitHub https://github.com/IDEA-Research/Grounded-Segment-Anything/issues/43#issuecomment-1502429423, or unsubscribe https://github.com/notifications/unsubscribe-auth/AI4IAWCMASYFHFX5FEZMLWDXASEMPANCNFSM6AAAAAAWY5PS3A . You are receiving this because you modified the open/close state.Message ID: @.*** com>

SlongLiu commented 1 year ago

Thanks for pointing out the issue, we will fix it soon.

The simple way to solve this is to add:

sys.path.append(os.path.join(os.getcwd(), "GroundingDINO"))

after the installations.

Jeredriq commented 8 months ago

During the environment preparation:

! python -m pip install -e segment_anything
! python -m pip install -e GroundingDINO

these lines are giving the following error:

ERROR: segment_anything is not a valid editable requirement. It should either be a path to a local project or a VCS URL (beginning with bzr+http, bzr+https, bzr+ssh, bzr+sftp, bzr+ftp, bzr+lp, bzr+file, git+http, git+https, git+ssh, git+git, git+file, hg+file, hg+http, hg+https, hg+ssh, hg+static-http, svn+ssh, svn+http, svn+https, svn+svn, svn+file).

ERROR: GroundingDINO is not a valid editable requirement. It should either be a path to a local project or a VCS URL (beginning with bzr+http, bzr+https, bzr+ssh, bzr+sftp, bzr+ftp, bzr+lp, bzr+file, git+http, git+https, git+ssh, git+git, git+file, hg+file, hg+http, hg+https, hg+ssh, hg+static-http, svn+ssh, svn+http, svn+https, svn+svn, svn+file).

And after these lines, I receive No module named groundingdino error.