MCPcopy Create free account
hub / github.com/facebookresearch/sam-3d-objects / build_batch_extractor

Function build_batch_extractor

sam3d_objects/data/utils.py:149–182  ·  view source on GitHub ↗
(mapping: MappingType)

Source from the content-addressed store, hash-verified

147
148
149def build_batch_extractor(mapping: MappingType):
150 extract_args_fn = lambda x: ()
151 extract_kwargs_fn = lambda x: {}
152
153 if mapping is None:
154
155 def extract_args_fn(batch):
156 return (batch,)
157
158 elif mapping is empty_mapping:
159 pass
160 elif mapping is kwargs_identity_mapping:
161 extract_kwargs_fn = lambda x: x
162 elif isinstance(mapping, Sequence) and (not isinstance(mapping, str)):
163 if (
164 len(mapping) == 2
165 and isinstance(mapping[0], Sequence)
166 and isinstance(mapping[1], Dict)
167 ):
168 extract_args_fn = build_args_batch_extractor(mapping[0])
169 extract_kwargs_fn = build_kwargs_batch_extractor(mapping[1])
170 else:
171 extract_args_fn = build_args_batch_extractor(mapping)
172 elif isinstance(mapping, Mapping):
173 extract_kwargs_fn = build_kwargs_batch_extractor(mapping)
174 else:
175
176 def extract_args_fn(batch):
177 return (get_child(batch, *as_keys(mapping)),)
178
179 def extract_fn(batch):
180 return extract_args_fn(batch), extract_kwargs_fn(batch)
181
182 return extract_fn
183
184
185# >

Callers

nothing calls this directly

Calls 2

Tested by

no test coverage detected