Random noise is an unstructured pseudo-random perturbation added to an image to create training variations. In image classification, this augmentation increases dataset diversity and can act as implicit regularization against overfitting. section 9.1
A JAX implementation follows a small, practical pipeline:
- Create a PRNG key from a seed, then generate Gaussian values with jax.random.normal() using the image shape. section 9.1.2
- Scale and shift the standard Gaussian tensor, add it to the image, and normalize the result back to [0.0, 1.0]. section 9.1.2
- Split keys when selecting an augmentation and generating its noise; reusing one key can produce correlated results. section 9.1.3
Noisy image
For an image shaped (200, 200, 3), generate noise with jax.random.normal(key, image.shape), compute noise = 0.5 + 0.1*std_noise, add it to the image, and normalize the result. The same idea can be demonstrated with scikit-image's random_noise(img, mode='gaussian'). section 9.1.2 section 3.1.3
Listing 9.8 Performing a random augmentation
def add_noise_func(image, rng_key): #1
noise = 0.5 + 0.1*jax.random.normal(rng_key, image.shape)
new_image = image + noise
new_image = (new_image - new_image.min())/(
new_image.max() - new_image.min())
return new_image
def horizontal_flip_func(image, rng_key): #2
return jnp.fliplr(image)
augmentations = [ #3
add_noise_func,
horizontal_flip_func
]
def random_augmentation(image, augmentations, rng_key): #4
key1, key2 = jax.random.split(rng_key) #5
augmentation_index = jax.random.randint(
key=key1, minval=0, maxval=len(augmentations), shape=()) #6
augmented_image = jax.lax.switch(
augmentation_index, augmentations, image, key2) #7
return augmented_image
key = jax.random.PRNGKey(4242) #8
img = random_augmentation(image, augmentations, key) #9
plt.imshow(img)
#1 Function for generating a noisy image
#2 Function for performing a horizontal flip
#3 A list of augmentations
#4 Function for doing a random augmentation
#5 Splits a key into two keys
#6 Randomly chooses one of the augmentation functions using the first key
#7 Applies the chosen function to an image and the second key
#8 Initializes a key with some seed
#9 Calls the whole pipeline for random augmentation
Shows noise generation, normalization, and random selection between noise and horizontal flipping. section 9.1.3










