AlexNet trains on fixed-size inputs cut from square images. Each image is cropped to its central square, the mean image of the training set is subtracted, and every time the image is used a random size x size patch is cut out and, with probability one half, mirrored left to right. Implement the pipeline on arrays of shape (H, W, C).
mean_image(images)
images has shape (N, H, W, C). Return the per-position mean over the N images as a float array of shape (H, W, C).central_square(image)
S = min(H, W). Return the S x S block starting at row (H - S) // 2 and column (W - S) // 2.training_patch(image, mean_img, top, left, flip, size)
mean_img from image (as floats), cut rows top .. top+size-1 and columns left .. left+size-1, and if flip is true reverse the column order. Return the patch.sample_training_patch(image, mean_img, rng, size)
top = rng.integers(0, H - size + 1), left = rng.integers(0, W - size + 1) and flip = rng.random() < 0.5, where rng is a numpy.random.Generator.(patch, (top, left, flip)) with top and left as Python ints and flip as a Python bool.(H, W, C) array.