MCPcopy Create free account
hub / github.com/ImprintLab/Medical-SAM2 / __init__

Method __init__

sam2_train/utils/misc.py:109–136  ·  view source on GitHub ↗
(self, img_paths, image_size, offload_video_to_cpu, img_mean, img_std)

Source from the content-addressed store, hash-verified

107 """
108
109 def __init__(self, img_paths, image_size, offload_video_to_cpu, img_mean, img_std):
110 self.img_paths = img_paths
111 self.image_size = image_size
112 self.offload_video_to_cpu = offload_video_to_cpu
113 self.img_mean = img_mean
114 self.img_std = img_std
115 # items in `self._images` will be loaded asynchronously
116 self.images = [None] * len(img_paths)
117 # catch and raise any exceptions in the async loading thread
118 self.exception = None
119 # video_height and video_width be filled when loading the first image
120 self.video_height = None
121 self.video_width = None
122
123 # load the first frame to fill video_height and video_width and also
124 # to cache it (since it's most likely where the user will click)
125 self.__getitem__(0)
126
127 # load the rest of frames asynchronously without blocking the session start
128 def _load_frames():
129 try:
130 for n in tqdm(range(len(self.images)), desc="frame loading (JPEG)"):
131 self.__getitem__(n)
132 except Exception as e:
133 self.exception = e
134
135 self.thread = Thread(target=_load_frames, daemon=True)
136 self.thread.start()
137
138 def __getitem__(self, index):
139 if self.exception is not None:

Callers

nothing calls this directly

Calls 1

__getitem__Method · 0.95

Tested by

no test coverage detected