Home > Enterprise >  Sliding window input (image sequence) for convolutional neural network
Sliding window input (image sequence) for convolutional neural network

Time:02-25

I am currently trying to feed an image sequence as a single input entity to my CNN. I found the numpy utility Sample

CodePudding user response:

I did it without the numpy utility like so:

im_pixels is an array containing n 1d-arrays with im_height*im_width entries. The 1 stems from 1 channel (greyscale).

def prep_images(im_pixels, window_size, im_height, im_width, pixel_normalizer):
    images = np.empty((len(im_pixels), window_size, im_height, im_width, 1))

    for i in range(len(im_pixels)):
        frame = im_pixels[i:i window_size]
        im_frame = np.empty((window_size, im_height, im_width, 1))
        for j, image in enumerate(frame):
            frame[j] = normalize_pixels(image, pixel_normalizer)
            image_2d = np.reshape(frame[j], (im_height, im_width, 1))
            im_frame[j] = image_2d
        images[i] = im_frame
    return images
  • Related