Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/owlv2 support (#1) #39

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
align_rois argument added
cuevas1208 committed Jul 29, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 91baacd619bcf8c15bff1a0e985fc074bd7a202b
4 changes: 3 additions & 1 deletion nanoowl/build_image_encoder_engine.py
Original file line number Diff line number Diff line change
@@ -25,10 +25,12 @@
parser.add_argument("--model_name", type=str, default="google/owlvit-base-patch32")
parser.add_argument("--fp16_mode", type=bool, default=True)
parser.add_argument("--onnx_opset", type=int, default=16)
parser.add_argument("--align_rois", type=bool, default=True)
args = parser.parse_args()

predictor = OwlPredictor(
model_name=args.model_name
model_name=args.model_name,
align_rois =args.align_rois,
)

predictor.build_image_encoder_engine(
15 changes: 12 additions & 3 deletions nanoowl/owl_predictor.py
Original file line number Diff line number Diff line change
@@ -65,7 +65,6 @@ def _owl_get_image_size(hf_name: str):


def _owl_get_patch_size(hf_name: str):

patch_sizes = {
"google/owlvit-base-patch32": 32,
"google/owlvit-base-patch16": 16,
@@ -153,11 +152,13 @@ def __init__(self,
device: str = "cuda",
image_encoder_engine: Optional[str] = None,
image_encoder_engine_max_batch_size: int = 1,
image_preprocessor: Optional[ImagePreprocessor] = None
image_preprocessor: Optional[ImagePreprocessor] = None,
align_rois=True,
):

super().__init__()

self.align_rois = align_rois
self.image_size = _owl_get_image_size(model_name)
self.device = device

@@ -275,7 +276,15 @@ def extract_rois(self, image: torch.Tensor, rois: torch.Tensor, pad_square: bool
mask = (mask_x & mask_y)

# extract rois
roi_images = roi_align(image, [rois], output_size=self.get_image_size())
if self.align_rois:
roi_images = roi_align(image, [rois], output_size=self.get_image_size())
else:
# Crop the image for each object detected
roi_images = []
for i in range(len(rois)):
bbox = tuple(rois[i])
object_image = image.crop(bbox)
roi_images.append(object_image)

# mask rois
if pad_square:
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -3,6 +3,6 @@

setup(
name="nanoowl",
version="0.0.0",
version="0.0.1",
packages=find_packages()
)