How can I use generator to feed the optimize() in the DFC?

In some cases it would be more convenient to use a generator that will pull-in an image, do the relevant preprocessing needed, instread of creating a buffer of prepared images for the optimization process.
Let’s assume that I need to optimize a YOLOv5s with an input image resolution of (640, 640), and the default normalization values.
In this case, I’m going to use the Model-Zoo built-in methods:

from hailo_model_zoo.core.preprocessing import preprocessing_factory
from import ImageFeed

I’m also assuming that the images are available at this directory:

input_dir = '/data/coco/images/val2017/'

I’ll create the pre-processing function, from the model-zoo:

preproc_fn = preprocessing_factory.get_preprocessing('yolo_v5', 
                                                      640, 640, 

Create the generator, and take from it only the pre-processed image:

data_feed_cb = lambda: ImageFeed(*(preproc_fn, None, input_dir))
dataset      = data_feed_cb().dataset

That’s it basically, now I can feed the optimize funtion with the created generator: