MCPcopy Create free account
hub / github.com/chenhaoxing/DiffusionInst / parse_dynamic_params

Function parse_dynamic_params

diffusioninst/detector.py:169–193  ·  view source on GitHub ↗
(params, channels, weight_nums, bias_nums)

Source from the content-addressed store, hash-verified

167
168
169def parse_dynamic_params(params, channels, weight_nums, bias_nums):
170 assert params.dim() == 2
171 assert len(weight_nums) == len(bias_nums)
172 assert params.size(1) == sum(weight_nums) + sum(bias_nums)
173 num_instances = params.size(0)
174 num_layers = len(weight_nums)
175
176 params_splits = list(
177 torch.split_with_sizes(params, weight_nums + bias_nums, dim=1))
178
179 weight_splits = params_splits[:num_layers]
180 bias_splits = params_splits[num_layers:]
181
182 for l in range(num_layers):
183 if l < num_layers - 1:
184 # out_channels x in_channels x 1 x 1
185 weight_splits[l] = weight_splits[l].reshape(
186 num_instances * channels, -1, 1, 1)
187 bias_splits[l] = bias_splits[l].reshape(num_instances * channels)
188 else:
189 # out_channels x in_channels x 1 x 1
190 weight_splits[l] = weight_splits[l].reshape(
191 num_instances * 1, -1, 1, 1)
192 bias_splits[l] = bias_splits[l].reshape(num_instances)
193 return weight_splits, bias_splits
194
195def exists(x):
196 return x is not None

Callers 2

ddim_sampleMethod · 0.70
inferenceMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected