-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Open
Description
Hello, I want to thank you for your impressive work!
I have a question regarding the use of the deepcopy function when concatenating mask results during the process of "Automatically Generating Object Masks" with SAM. It appears to me that replacing deepcopy with copy could not only yield the same mask results but also potentially reduce the overall time required for automatic generation. Some other ways for copying mask results might also work.
So I wonder if there is a specific reason for the necessity of using the "deepcopy" function. The original code snippets used and possible changes are shown below.
data = MaskData()
for (points,) in batch_iterator(self.points_per_batch, points_for_image):
batch_data = self._process_batch(points, cropped_im_size, crop_box, orig_size)
data.cat(batch_data)
del batch_data
self.predictor.reset_image()
def cat(self, new_stats: "MaskData") -> None:
for k, v in new_stats.items():
if k not in self._stats or self._stats[k] is None:
self._stats[k] = deepcopy(v)
# self._stats[k] = copy(v)
elif isinstance(v, torch.Tensor):
self._stats[k] = torch.cat([self._stats[k], v], dim=0)
elif isinstance(v, np.ndarray):
self._stats[k] = np.concatenate([self._stats[k], v], axis=0)
elif isinstance(v, list):
self._stats[k] = self._stats[k] + deepcopy(v)
# self._stats[k] = self._stats[k] + copy(v)
else:
raise TypeError(f"MaskData key {k} has an unsupported type {type(v)}.")
Your help on this matter would be greatly appreciated. Thank you!
Metadata
Metadata
Assignees
Labels
No labels