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

Use a class attribute for type checking #721

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
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
6 changes: 3 additions & 3 deletions segment_anything/utils/amg.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import numpy as np
import torch

import math
from copy import deepcopy
from itertools import product
Expand All @@ -18,17 +17,18 @@ class MaskData:
A structure for storing masks and their related data in batched format.
Implements basic filtering and concatenation.
"""
SUPPORTED_TYPES = (list, np.ndarray, torch.Tensor)

def __init__(self, **kwargs) -> None:
for v in kwargs.values():
assert isinstance(
v, (list, np.ndarray, torch.Tensor)
v, (self.SUPPORTED_TYPES)
), "MaskData only supports list, numpy arrays, and torch tensors."
self._stats = dict(**kwargs)

def __setitem__(self, key: str, item: Any) -> None:
assert isinstance(
item, (list, np.ndarray, torch.Tensor)
item, (self.SUPPORTED_TYPES)
), "MaskData only supports list, numpy arrays, and torch tensors."
self._stats[key] = item

Expand Down