def bgr_to_rgb(epsd: dict):
    """
    Convert BGR images to RGB images.
    """
    past_frames_0 = epsd['past_frames_0']
    past_frames_0 = tf.cond(
        tf.equal(tf.shape(past_frames_0)[-1], 3),
        lambda: tf.stack([
            past_frames_0[..., 2],
            past_frames_0[..., 1],
            past_frames_0[..., 0]
        ], axis=-1),
        lambda: past_frames_0
    )
    
    past_frames_1 = epsd['past_frames_1']
    past_frames_1 = tf.cond(
        tf.equal(tf.shape(past_frames_1)[-1], 3),
        lambda: tf.stack([
            past_frames_1[..., 2],
            past_frames_1[..., 1],
            past_frames_1[..., 0]
        ], axis=-1),
        lambda: past_frames_1
    )
    
    past_frames_2 = epsd['past_frames_2']
    past_frames_2 = tf.cond(
        tf.equal(tf.shape(past_frames_2)[-1], 3),
        lambda: tf.stack([
            past_frames_2[..., 2],
            past_frames_2[..., 1],
            past_frames_2[..., 0]
        ], axis=-1),
        lambda: past_frames_2
    )
    
    past_frames_3 = epsd['past_frames_3']
    past_frames_3 = tf.cond(
        tf.equal(tf.shape(past_frames_3)[-1], 3),
        lambda: tf.stack([
            past_frames_3[..., 2],
            past_frames_3[..., 1],
            past_frames_3[..., 0]
        ], axis=-1),
        lambda: past_frames_3
    )
    
    return {
        'dataset_name': epsd['dataset_name'],
        'episode_dict': epsd['episode_dict'],
        'step_id': epsd['step_id'],
        'past_frames_0': past_frames_0,
        'past_frames_0_time_mask': epsd['past_frames_0_time_mask'],
        'past_frames_1': past_frames_1,
        'past_frames_1_time_mask': epsd['past_frames_1_time_mask'],
        'past_frames_2': past_frames_2,
        'past_frames_2_time_mask': epsd['past_frames_2_time_mask'],
        'past_frames_3': past_frames_3,
        'past_frames_3_time_mask': epsd['past_frames_3_time_mask'],
    }

    Convert BGR images to RGB images.
    
policy/RDT/data/episode_transform.py