MCPcopy Create free account
hub / github.com/Francis-Rings/FlashPortrait / get_random_downsample_ratio

Function get_random_downsample_ratio

train_portrait.py:84–113  ·  view source on GitHub ↗
(sample_size, image_ratio=[], all_choices=False, rng=None)

Source from the content-addressed store, hash-verified

82
83
84def get_random_downsample_ratio(sample_size, image_ratio=[], all_choices=False, rng=None):
85 def _create_special_list(length):
86 if length == 1:
87 return [1.0]
88 if length >= 2:
89 first_element = 0.75
90 remaining_sum = 1.0 - first_element
91 other_elements_value = remaining_sum / (length - 1)
92 special_list = [first_element] + [other_elements_value] * (length - 1)
93 return special_list
94
95 if sample_size >= 1536:
96 number_list = [1, 1.25, 1.5, 2, 2.5, 3] + image_ratio
97 elif sample_size >= 1024:
98 number_list = [1, 1.25, 1.5, 2] + image_ratio
99 elif sample_size >= 768:
100 number_list = [1, 1.25, 1.5] + image_ratio
101 elif sample_size >= 512:
102 number_list = [1] + image_ratio
103 else:
104 number_list = [1]
105
106 if all_choices:
107 return number_list
108
109 number_list_prob = np.array(_create_special_list(len(number_list)))
110 if rng is None:
111 return np.random.choice(number_list, p=number_list_prob)
112 else:
113 return rng.choice(number_list, p=number_list_prob)
114
115
116def resize_mask(mask, latent, process_first_frame_only=True):

Callers

nothing calls this directly

Calls 1

_create_special_listFunction · 0.85

Tested by

no test coverage detected