MCPcopy Create free account
hub / github.com/InternRobotics/G2VLM / get_pca_map

Function get_pca_map

modeling/pi3/utils/basic.py:225–248  ·  view source on GitHub ↗

feature_map: (1, h, w, C) is the feature map of a single image.

(
    feature_map: torch.Tensor,
    return_pca_stats=False,
    pca_stats=None,
)

Source from the content-addressed store, hash-verified

223
224
225def get_pca_map(
226 feature_map: torch.Tensor,
227 return_pca_stats=False,
228 pca_stats=None,
229):
230 """
231 feature_map: (1, h, w, C) is the feature map of a single image.
232 """
233 if feature_map.shape[0] != 1:
234 # make it (1, h, w, C)
235 feature_map = feature_map[None]
236 if pca_stats is None:
237 reduct_mat, color_min, color_max = get_robust_pca(
238 feature_map.reshape(-1, feature_map.shape[-1])
239 )
240 else:
241 reduct_mat, color_min, color_max = pca_stats
242 pca_color = feature_map @ reduct_mat
243 pca_color = (pca_color - color_min) / (color_max - color_min)
244 pca_color = pca_color.clamp(0, 1)
245 pca_color = pca_color.cpu().numpy().squeeze(0)
246 if return_pca_stats:
247 return pca_color, (reduct_mat, color_min, color_max)
248 return pca_color
249
250
251def load_images_as_tensor(path='data/truck', interval=1, PIXEL_LIMIT=255000):

Callers

nothing calls this directly

Calls 1

get_robust_pcaFunction · 0.85

Tested by

no test coverage detected