MCPcopy Create free account
hub / github.com/SpatialVLA/SpatialVLA / delete_task_conditioning

Function delete_task_conditioning

data/utils/task_augmentation.py:14–61  ·  view source on GitHub ↗

Randomly drops out either the goal images or the language instruction. Only does something if both of these are present. Args: traj: A dictionary containing trajectory data. Should have a "task" key. keep_image_prob: The probability of keeping the goal images. The proba

(traj: Dict, keep_image_prob: float)

Source from the content-addressed store, hash-verified

12
13
14def delete_task_conditioning(traj: Dict, keep_image_prob: float) -> Dict:
15 """
16 Randomly drops out either the goal images or the language instruction. Only does something if both of
17 these are present.
18
19 Args:
20 traj: A dictionary containing trajectory data. Should have a "task" key.
21 keep_image_prob: The probability of keeping the goal images. The probability of keeping the language
22 instruction is 1 - keep_image_prob.
23 """
24 if "language_instruction" not in traj["task"]:
25 return traj
26
27 image_keys = {
28 key
29 for key in traj["task"].keys()
30 if key.startswith("image_") or key.startswith("depth_")
31 }
32 if not image_keys:
33 return traj
34
35 traj_len = tf.shape(traj["action"])[0]
36 should_keep_images = tf.random.uniform([traj_len]) < keep_image_prob
37 should_keep_images |= ~traj["task"]["pad_mask_dict"]["language_instruction"]
38
39 for key in image_keys | {"language_instruction"}:
40 should_keep = should_keep_images if key in image_keys else ~should_keep_images
41 # pad out the key
42 traj["task"][key] = tf.where(
43 should_keep,
44 traj["task"][key],
45 to_padding(traj["task"][key]),
46 )
47 # zero out the pad mask dict for the key
48 traj["task"]["pad_mask_dict"][key] = tf.where(
49 should_keep,
50 traj["task"]["pad_mask_dict"][key],
51 tf.zeros_like(traj["task"]["pad_mask_dict"][key]),
52 )
53
54 # when no goal images are present, the goal timestep becomes the final timestep
55 traj["task"]["timestep"] = tf.where(
56 should_keep_images,
57 traj["task"]["timestep"],
58 traj_len - 1,
59 )
60
61 return traj

Callers

nothing calls this directly

Calls 1

to_paddingFunction · 0.85

Tested by

no test coverage detected