| |
| |
|
|
| import math |
|
|
| import numpy as np |
|
|
| video_frames = 97 |
| vae_stride = 16 |
| compressed_frames = video_frames // 4 + 1 |
|
|
| def append_dummy_t(ratio2hws): |
| for key in ratio2hws: |
| for i in range(len(ratio2hws[key])): |
| h, w = ratio2hws[key][i] |
| ratio2hws[key][i] = (1, h, w) |
| return ratio2hws |
|
|
| def get_full_ratio2hws(ratio2hws, total_pixels2scales): |
| full_ratio2hws = {} |
| for ratio, hws in ratio2hws.items(): |
| real_ratio = hws[-1][1] / hws[-1][2] |
| full_ratio2hws[int(real_ratio*1000)/1000] = hws |
| if ratio != 1.000: |
| full_ratio2hws[int(1/real_ratio*1000)/1000] = [(item[0], item[2], item[1]) for item in hws] |
|
|
| dynamic_resolution_h_w = {} |
| for ratio in full_ratio2hws: |
| dynamic_resolution_h_w[ratio] = {} |
| for _, scales_num in total_pixels2scales.items(): |
| h, w = full_ratio2hws[ratio][scales_num-1][1], full_ratio2hws[ratio][scales_num-1][2] |
| |
| scales = full_ratio2hws[ratio][:scales_num] |
| dynamic_resolution_h_w[ratio][(h, w)] = scales |
| return dynamic_resolution_h_w |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| def get_ratio2hws_video_v2(): |
| ratio2hws_video_common_v2 = {} |
| for h_div_w in [1, 100/116, 3/4, 2/3, 9/16, 1/2, 2/5, 1/3]: |
| scale_schedule = [] |
| |
| |
| for scale in [1,2,3,4,5,6,7,8,10,12,16] + [24, 32, 40, 48, 60]: |
| area = scale * scale |
| pw_float = math.sqrt(area / h_div_w) |
| ph_float = pw_float * h_div_w |
| ph, pw = int(np.round(ph_float)), int(np.round(pw_float)) |
| scale_schedule.append((ph, pw)) |
| ratio2hws_video_common_v2[h_div_w] = scale_schedule |
| total_pixels2scales = { |
| '0.06M': 11, |
| '0.15M': 13, |
| '0.40M': 14, |
| '0.60M': 15, |
| '0.90M': 16, |
| } |
| return ratio2hws_video_common_v2, total_pixels2scales |
|
|
| ratio2hws, total_pixels2scales = get_ratio2hws_video_v2() |
| ratio2hws = append_dummy_t(ratio2hws) |
| dynamic_resolution_h_w = get_full_ratio2hws(ratio2hws, total_pixels2scales) |
| dynamic_resolution_thw = {} |
| for ratio in dynamic_resolution_h_w: |
| for (h, w) in dynamic_resolution_h_w[ratio]: |
| image_scale_schedule = dynamic_resolution_h_w[ratio][(h, w)] |
| spatial_time_schedule = [] |
| spatial_time_schedule.extend(image_scale_schedule) |
| firstframe_scalecnt = len(image_scale_schedule) |
| |
| |
| |
| |
| |
| dynamic_resolution_thw[(h, w)] = {} |
| dynamic_resolution_thw[(h, w)]['scales'] = spatial_time_schedule |
| dynamic_resolution_thw[(h, w)]['tower_split_index'] = firstframe_scalecnt |
|
|
| |
|
|
| if __name__ == '__main__': |
| ratio2hws_video_common_v2, total_pixels2scales = get_ratio2hws_video_v2() |
| for h_div_w in ratio2hws_video_common_v2: |
| print(h_div_w, ratio2hws_video_common_v2[h_div_w][10]) |
| |