diff --git a/demo/inference_on_a_image.py b/demo/inference_on_a_image.py index 6802451..2e895e9 100644 --- a/demo/inference_on_a_image.py +++ b/demo/inference_on_a_image.py @@ -2,8 +2,6 @@ import argparse import os import sys -sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) - import numpy as np import torch from PIL import Image, ImageDraw, ImageFont @@ -14,6 +12,8 @@ from groundingdino.util import box_ops from groundingdino.util.slconfig import SLConfig from groundingdino.util.utils import clean_state_dict, get_phrases_from_posmap +sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) + def plot_boxes_to_image(image_pil, tgt): H, W = tgt["size"] @@ -88,7 +88,6 @@ def get_grounding_output(model, image, caption, box_threshold, text_threshold, w logits = outputs["pred_logits"].cpu().sigmoid()[0] # (nq, 256) boxes = outputs["pred_boxes"].cpu()[0] # (nq, 4) logits.shape[0] - # filter output logits_filt = logits.clone() @@ -126,12 +125,8 @@ if __name__ == "__main__": "--output_dir", "-o", type=str, default="outputs", required=True, help="output directory" ) - parser.add_argument( - "--box_threshold", type=float, default=0.3, help="box threshold" - ) - parser.add_argument( - "--text_threshold", type=float, default=0.25, help="text threshold" - ) + parser.add_argument("--box_threshold", type=float, default=0.3, help="box threshold") + parser.add_argument("--text_threshold", type=float, default=0.25, help="text threshold") args = parser.parse_args() # cfg diff --git a/groundingdino/models/GroundingDINO/__init__.py b/groundingdino/models/GroundingDINO/__init__.py index 4ca1bd2..2af819d 100644 --- a/groundingdino/models/GroundingDINO/__init__.py +++ b/groundingdino/models/GroundingDINO/__init__.py @@ -1,4 +1,9 @@ # ------------------------------------------------------------------------ +# Grounding DINO +# url: https://github.com/IDEA-Research/GroundingDINO +# Copyright (c) 2023 IDEA. All Rights Reserved. +# Licensed under the Apache License, Version 2.0 [see LICENSE for details] +# ------------------------------------------------------------------------ # Conditional DETR # Copyright (c) 2021 Microsoft. All Rights Reserved. # Licensed under the Apache License, Version 2.0 [see LICENSE for details] diff --git a/groundingdino/models/GroundingDINO/backbone/backbone.py b/groundingdino/models/GroundingDINO/backbone/backbone.py index b4c8642..c8340c7 100644 --- a/groundingdino/models/GroundingDINO/backbone/backbone.py +++ b/groundingdino/models/GroundingDINO/backbone/backbone.py @@ -1,4 +1,9 @@ # ------------------------------------------------------------------------ +# Grounding DINO +# url: https://github.com/IDEA-Research/GroundingDINO +# Copyright (c) 2023 IDEA. All Rights Reserved. +# Licensed under the Apache License, Version 2.0 [see LICENSE for details] +# ------------------------------------------------------------------------ # Conditional DETR # Copyright (c) 2021 Microsoft. All Rights Reserved. # Licensed under the Apache License, Version 2.0 [see LICENSE for details] diff --git a/groundingdino/models/GroundingDINO/backbone/position_encoding.py b/groundingdino/models/GroundingDINO/backbone/position_encoding.py index 2131aee..14b429c 100644 --- a/groundingdino/models/GroundingDINO/backbone/position_encoding.py +++ b/groundingdino/models/GroundingDINO/backbone/position_encoding.py @@ -1,4 +1,9 @@ # ------------------------------------------------------------------------ +# Grounding DINO +# url: https://github.com/IDEA-Research/GroundingDINO +# Copyright (c) 2023 IDEA. All Rights Reserved. +# Licensed under the Apache License, Version 2.0 [see LICENSE for details] +# ------------------------------------------------------------------------ # DINO # Copyright (c) 2022 IDEA. All Rights Reserved. # Licensed under the Apache License, Version 2.0 [see LICENSE for details] diff --git a/groundingdino/models/GroundingDINO/backbone/swin_transformer.py b/groundingdino/models/GroundingDINO/backbone/swin_transformer.py index 767868d..1c66194 100644 --- a/groundingdino/models/GroundingDINO/backbone/swin_transformer.py +++ b/groundingdino/models/GroundingDINO/backbone/swin_transformer.py @@ -1,4 +1,9 @@ # ------------------------------------------------------------------------ +# Grounding DINO +# url: https://github.com/IDEA-Research/GroundingDINO +# Copyright (c) 2023 IDEA. All Rights Reserved. +# Licensed under the Apache License, Version 2.0 [see LICENSE for details] +# ------------------------------------------------------------------------ # DINO # Copyright (c) 2022 IDEA. All Rights Reserved. # Licensed under the Apache License, Version 2.0 [see LICENSE for details] diff --git a/groundingdino/models/GroundingDINO/bertwarper.py b/groundingdino/models/GroundingDINO/bertwarper.py index 8474c1c..f0cf977 100644 --- a/groundingdino/models/GroundingDINO/bertwarper.py +++ b/groundingdino/models/GroundingDINO/bertwarper.py @@ -1,3 +1,10 @@ +# ------------------------------------------------------------------------ +# Grounding DINO +# url: https://github.com/IDEA-Research/GroundingDINO +# Copyright (c) 2023 IDEA. All Rights Reserved. +# Licensed under the Apache License, Version 2.0 [see LICENSE for details] +# ------------------------------------------------------------------------ + import torch import torch.nn.functional as F import torch.utils.checkpoint as checkpoint diff --git a/groundingdino/models/GroundingDINO/fuse_modules.py b/groundingdino/models/GroundingDINO/fuse_modules.py index 67aa5ac..2753b3d 100644 --- a/groundingdino/models/GroundingDINO/fuse_modules.py +++ b/groundingdino/models/GroundingDINO/fuse_modules.py @@ -1,3 +1,10 @@ +# ------------------------------------------------------------------------ +# Grounding DINO +# url: https://github.com/IDEA-Research/GroundingDINO +# Copyright (c) 2023 IDEA. All Rights Reserved. +# Licensed under the Apache License, Version 2.0 [see LICENSE for details] +# ------------------------------------------------------------------------ + import torch import torch.nn as nn import torch.nn.functional as F diff --git a/groundingdino/models/GroundingDINO/groundingdino.py b/groundingdino/models/GroundingDINO/groundingdino.py index 29385cf..052df62 100644 --- a/groundingdino/models/GroundingDINO/groundingdino.py +++ b/groundingdino/models/GroundingDINO/groundingdino.py @@ -1,6 +1,7 @@ # ------------------------------------------------------------------------ -# DINO -# Copyright (c) 2022 IDEA. All Rights Reserved. +# Grounding DINO +# url: https://github.com/IDEA-Research/GroundingDINO +# Copyright (c) 2023 IDEA. All Rights Reserved. # Licensed under the Apache License, Version 2.0 [see LICENSE for details] # ------------------------------------------------------------------------ # Conditional DETR model and criterion classes. diff --git a/groundingdino/models/GroundingDINO/ms_deform_attn.py b/groundingdino/models/GroundingDINO/ms_deform_attn.py index 938bfaa..a51d7d2 100644 --- a/groundingdino/models/GroundingDINO/ms_deform_attn.py +++ b/groundingdino/models/GroundingDINO/ms_deform_attn.py @@ -1,18 +1,9 @@ -# coding=utf-8 -# Copyright 2022 The IDEA Authors. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ------------------------------------------------------------------------------------------------ +# ------------------------------------------------------------------------ +# Grounding DINO +# url: https://github.com/IDEA-Research/GroundingDINO +# Copyright (c) 2023 IDEA. All Rights Reserved. +# Licensed under the Apache License, Version 2.0 [see LICENSE for details] +# ------------------------------------------------------------------------ # Deformable DETR # Copyright (c) 2020 SenseTime. All Rights Reserved. # Licensed under the Apache License, Version 2.0 [see LICENSE for details] @@ -26,12 +17,14 @@ import math import warnings from typing import Optional + import torch import torch.nn as nn import torch.nn.functional as F from torch.autograd import Function from torch.autograd.function import once_differentiable from torch.nn.init import constant_, xavier_uniform_ + from groundingdino import _C @@ -290,7 +283,6 @@ class MultiScaleDeformableAttention(nn.Module): assert (spatial_shapes[:, 0] * spatial_shapes[:, 1]).sum() == num_value - value = self.value_proj(value) if key_padding_mask is not None: value = value.masked_fill(key_padding_mask[..., None], float(0)) @@ -339,7 +331,6 @@ class MultiScaleDeformableAttention(nn.Module): sampling_locations = sampling_locations.float() attention_weights = attention_weights.float() - output = MultiScaleDeformableAttnFunction.apply( value, spatial_shapes, @@ -416,4 +407,3 @@ def create_dummy_func(func, dependency, message=""): raise ImportError(err) return _dummy - diff --git a/groundingdino/models/GroundingDINO/transformer.py b/groundingdino/models/GroundingDINO/transformer.py index 44cd2b2..fcb8742 100644 --- a/groundingdino/models/GroundingDINO/transformer.py +++ b/groundingdino/models/GroundingDINO/transformer.py @@ -1,4 +1,9 @@ # ------------------------------------------------------------------------ +# Grounding DINO +# url: https://github.com/IDEA-Research/GroundingDINO +# Copyright (c) 2023 IDEA. All Rights Reserved. +# Licensed under the Apache License, Version 2.0 [see LICENSE for details] +# ------------------------------------------------------------------------ # DINO # Copyright (c) 2022 IDEA. All Rights Reserved. # Licensed under the Apache License, Version 2.0 [see LICENSE for details] @@ -744,7 +749,13 @@ class DeformableTransformerEncoderLayer(nn.Module): super().__init__() # self attention - self.self_attn = MSDeformAttn(embed_dim=d_model, num_levels=n_levels, num_heads=n_heads, num_points=n_points, batch_first=True) + self.self_attn = MSDeformAttn( + embed_dim=d_model, + num_levels=n_levels, + num_heads=n_heads, + num_points=n_points, + batch_first=True, + ) self.dropout1 = nn.Dropout(dropout) self.norm1 = nn.LayerNorm(d_model) @@ -804,7 +815,13 @@ class DeformableTransformerDecoderLayer(nn.Module): super().__init__() # cross attention - self.cross_attn = MSDeformAttn(embed_dim=d_model, num_levels=n_levels, num_heads=n_heads, num_points=n_points, batch_first=True) + self.cross_attn = MSDeformAttn( + embed_dim=d_model, + num_levels=n_levels, + num_heads=n_heads, + num_points=n_points, + batch_first=True, + ) self.dropout1 = nn.Dropout(dropout) if dropout > 0 else nn.Identity() self.norm1 = nn.LayerNorm(d_model) diff --git a/groundingdino/models/GroundingDINO/transformer_vanilla.py b/groundingdino/models/GroundingDINO/transformer_vanilla.py index 1c982f4..10c0920 100644 --- a/groundingdino/models/GroundingDINO/transformer_vanilla.py +++ b/groundingdino/models/GroundingDINO/transformer_vanilla.py @@ -1,3 +1,9 @@ +# ------------------------------------------------------------------------ +# Grounding DINO +# url: https://github.com/IDEA-Research/GroundingDINO +# Copyright (c) 2023 IDEA. All Rights Reserved. +# Licensed under the Apache License, Version 2.0 [see LICENSE for details] +# ------------------------------------------------------------------------ # Copyright (c) Aishwarya Kamath & Nicolas Carion. Licensed under the Apache License 2.0. All Rights Reserved # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved """ diff --git a/groundingdino/models/GroundingDINO/utils.py b/groundingdino/models/GroundingDINO/utils.py index 1f04705..caf0f1b 100644 --- a/groundingdino/models/GroundingDINO/utils.py +++ b/groundingdino/models/GroundingDINO/utils.py @@ -1,6 +1,7 @@ # ------------------------------------------------------------------------ -# DINO -# Copyright (c) 2022 IDEA. All Rights Reserved. +# Grounding DINO +# url: https://github.com/IDEA-Research/GroundingDINO +# Copyright (c) 2023 IDEA. All Rights Reserved. # Licensed under the Apache License, Version 2.0 [see LICENSE for details] # ------------------------------------------------------------------------ diff --git a/groundingdino/models/__init__.py b/groundingdino/models/__init__.py index 96f2b36..e341396 100644 --- a/groundingdino/models/__init__.py +++ b/groundingdino/models/__init__.py @@ -1,6 +1,7 @@ # ------------------------------------------------------------------------ -# DINO -# Copyright (c) 2022 IDEA. All Rights Reserved. +# Grounding DINO +# url: https://github.com/IDEA-Research/GroundingDINO +# Copyright (c) 2023 IDEA. All Rights Reserved. # Licensed under the Apache License, Version 2.0 [see LICENSE for details] # ------------------------------------------------------------------------ # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved diff --git a/groundingdino/models/registry.py b/groundingdino/models/registry.py index cfd4144..2d22a59 100644 --- a/groundingdino/models/registry.py +++ b/groundingdino/models/registry.py @@ -1,3 +1,9 @@ +# ------------------------------------------------------------------------ +# Grounding DINO +# url: https://github.com/IDEA-Research/GroundingDINO +# Copyright (c) 2023 IDEA. All Rights Reserved. +# Licensed under the Apache License, Version 2.0 [see LICENSE for details] +# ------------------------------------------------------------------------ # -*- coding: utf-8 -*- # @Author: Yihao Chen # @Date: 2021-08-16 16:03:17 diff --git a/groundingdino/version.py b/groundingdino/version.py index b794fd4..3dc1f76 100644 --- a/groundingdino/version.py +++ b/groundingdino/version.py @@ -1 +1 @@ -__version__ = '0.1.0' +__version__ = "0.1.0"