Performing HOG Matrices on PIMS Chunks through ImageIO

@jmdelahanty

  • Hmm … it seems the error is not dask-related, so I can’t be sure from here what is causing it. Corrupted video file perhaps?

  • Correction: once you call compute() dask will execute the task-graph, not generate it. A task-graph is built any time you call a dask function like map_blocks() or imread().

  • Since the chunksize (number of images in a chunk) has been changed to 100, you must be aware that make_hogs() receives a chunk of 100 images at once as input. So you probably should loop hog() over all those images and stack-up all the processed images, since hog() is unable to process more than one image at a time (right?). Alternatively, you could rewrite hog()'s source code to do that (without looping), like I did for pims.as_grey(). In fact, I encourage you to try that and see if it boosts performance. In the meantime, here’s an untested code snippet:

def make_hogs(frames, coords):
    new_frames = frames[
        :,
        coords[1]:coords[1] + coords[3],
        coords[0]:coords[1] + coords[2],
    ]
	
	nframes = new_frames.shape[0]
	first_frame = new_frames[0]

    hog_descriptor, hog_image = hog(first_frame)
    hog_images = np.empty((nframes,) + hog_image.shape, dtype=frames.dtype)
    hog_descriptors = np.empty((nframes,) + hog_descriptor.shape, dtype=frames.dtype)

    for i, image in enumerate(new_frames):
        hog_descriptor, hog_image = hog(image)
        hog_descriptors[i, ...] = hog_descriptor
        hog_images[i, ...] = hog_image

    return hog_descriptors, hog_images

I do not know exactly what hog() does. I’ve simply assumed above that it returns a tuple of two arrays whose sizes remain constant over all the images in the chunk.

  • See this link for help on how to return more than one output.
2 Likes