Skip to content

Commit e9bc7ee

Browse files
wadeKeithyin
authored andcommitted
fix(train): ensure consistent color augmentation RNG across base and wrist cameras
Fixes #859. augmax.Chain splits RNG by transform count, so base cameras (4 transforms) and wrist cameras (1 transform) received different sub-RNGs for ColorJitter despite the same input seed. This caused inconsistent color semantics between camera views. Split augmentation into spatial (camera-specific) and color (shared) stages with deterministic RNG derivation via jax.random.fold_in, ensuring all cameras see the same ColorJitter parameters within each sample.
1 parent c23745b commit e9bc7ee

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

src/openpi/models/model.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,20 +168,23 @@ def preprocess_observation(
168168
if train:
169169
# Convert from [-1, 1] to [0, 1] for augmax.
170170
image = image / 2.0 + 0.5
171+
sub_rngs = jax.random.split(rng, image.shape[0])
171172

172-
transforms = []
173+
# Stage 1: Apply spatial transforms (base cameras only)
173174
if "wrist" not in key:
174175
height, width = image.shape[1:3]
175-
transforms += [
176+
spatial_rngs = jax.vmap(lambda k: jax.random.fold_in(k, 0))(sub_rngs)
177+
image = jax.vmap(augmax.Chain(
176178
augmax.RandomCrop(int(width * 0.95), int(height * 0.95)),
177179
augmax.Resize(width, height),
178180
augmax.Rotate((-5, 5)),
179-
]
180-
transforms += [
181+
))(spatial_rngs, image)
182+
183+
# Stage 2: Apply color transforms (all cameras, consistent RNG)
184+
color_rngs = jax.vmap(lambda k: jax.random.fold_in(k, 1))(sub_rngs)
185+
image = jax.vmap(augmax.Chain(
181186
augmax.ColorJitter(brightness=0.3, contrast=0.4, saturation=0.5),
182-
]
183-
sub_rngs = jax.random.split(rng, image.shape[0])
184-
image = jax.vmap(augmax.Chain(*transforms))(sub_rngs, image)
187+
))(color_rngs, image)
185188

186189
# Back to [-1, 1].
187190
image = image * 2.0 - 1.0

0 commit comments

Comments
 (0)