MCPcopy Create free account
hub / github.com/MotrixLab/ViMoGen / preprocess

Method preprocess

datasets/bucket_config.py:244–259  ·  view source on GitHub ↗

process original height width, sample a (height, width) in bucket_config with the closed aspect ratio.

(self, n_frame: int, height: int, width: int,
                   rnd_state: np.random.RandomState)

Source from the content-addressed store, hash-verified

242 pass
243
244 def preprocess(self, n_frame: int, height: int, width: int,
245 rnd_state: np.random.RandomState):
246 """process original height width, sample a (height, width) in
247 bucket_config with the closed aspect ratio."""
248 ar = height / width
249 tgt_ar_idx = find_nearest_value(ar, self.ar_value_arr, return_idx=True)
250 h_w_pixel_list, prob_list = self.bucket_config[
251 self.ar_value_arr[tgt_ar_idx]]
252 if h_w_pixel_list[-1, -1] > height * width:
253 down_num = np.sum(h_w_pixel_list[:, -1] <= height * width)
254 h_w_pixel_list = h_w_pixel_list[:down_num]
255 prob_list = prob_list[:down_num] / prob_list[:down_num].sum()
256 selected_idx = rnd_state.choice(
257 len(prob_list), size=None, replace=False, p=prob_list)
258 h, w = h_w_pixel_list[selected_idx][:2]
259 return h, w
260
261 def __call__(self, n_frame: int, height: int, width: int,
262 rnd_state: np.random.RandomState) -> Any:

Callers 3

__call__Method · 0.95
__call__Method · 0.80
__call__Method · 0.80

Calls 1

find_nearest_valueFunction · 0.85

Tested by

no test coverage detected