MCPcopy Create free account
hub / github.com/CompVis/flow-poke-transformer / _decode

Method _decode

myriad/data_2d.py:313–429  ·  view source on GitHub ↗
(self, sample: dict[str, bytes])

Source from the content-addressed store, hash-verified

311 return target_sample
312
313 def _decode(self, sample: dict[str, bytes]) -> dict[str, torch.Tensor]:
314 try:
315 assert all(
316 k in sample
317 for k in [
318 "video.mp4",
319 # "times.npy",
320 f"{self.track_key}.npy",
321 "logits_visible.npy",
322 "certainty.npy"
323 ]
324 ), f"{sample.keys()=}"
325
326 tracks = decode_npy(sample[f"{self.track_key}.npy"])
327 tracks = torch.from_numpy(tracks).float()
328 tracks = (tracks + 1) / 2 # to [0, 1]
329 tracks = tracks[..., [1, 0]] # (yx) to (xy)
330
331 num_tracks_unfiltered = tracks.shape[1]
332 certainty = torch.from_numpy(decode_npy(sample["certainty.npy"]))
333
334 d = {
335 "tracks": tracks, # [t, n_t, 2]
336 "visibility": torch.sigmoid(torch.from_numpy(decode_npy(sample["logits_visible.npy"]))), # [t, n_t]
337 "certainty": certainty,
338 }
339
340 # get fps and real time
341 got_fps = False
342 if "meta.json" in sample.keys():
343 meta_bytes = sample["meta.json"]
344 meta_str = meta_bytes.decode("utf-8")
345 meta = json.loads(meta_str)
346 if "fps" in meta.keys():
347 fps = float(meta["fps"])
348 got_fps = True
349 if "fps" in sample.keys() and not got_fps:
350 fps = float(sample["fps"])
351 got_fps = True
352 if not got_fps:
353 fps = 30
354 d["times"] = torch.arange(d["tracks"].shape[0]) / fps
355
356 # get sample and valid tracks
357 sample_out = self.extract_training_sample(d)
358 if not sample_out.get("valid", True):
359 return {"valid": False}
360
361 # camera static filtering
362 camera_static = sample_out["camera_static"]
363 if self.filter_static_camera and not camera_static.item():
364 return {"valid": False}
365
366 # get frame
367 i_f = sample_out.get("i_frame", 0) if not self.return_video_without_cutting else 0
368 x, pos, visibility, track_in_frame = self._load_adjusted_frame(sample["video.mp4"], i_f, sample_out["pos"], sample_out["visibility"])
369
370 if x is None:

Callers

nothing calls this directly

Calls 4

_load_adjusted_frameMethod · 0.95
_build_targetsMethod · 0.95
decode_npyFunction · 0.70

Tested by

no test coverage detected