Hey, i´m trying to load and transform a dataset of...
# ask-community
t
Hey, i´m trying to load and transform a dataset of images with prefect tasks. Below is a code snippet, first i load images with task
load_data_task
. This provides me
images_train
and
images_val
. And now i want to transform
images_train
with task
rescaling_images_task
. I need to map over `images_train`d(for each image and label) and then apply to
recaling_images_task
. Outside of prefect this works with following code:
images_train_rescaled = images_train.map(lambda x, y: ((preprocess.rescaling_images() (x, training=True), y))
But how i can run this in prefect flow?
Copy code
preprocess = PreprocessingClass_Images(cfg)

with Flow("Preprocess") as flow:

        #1. load images
        images_train, images_val = preprocess.load_data_task()

        # 2. rescaling
        #the code below works outside of prefect flow
        images_train_rescaled = images_train.map(lambda x, y: ((preprocess.rescaling_images() (x, training=True), y))
k
I think it would be:
Copy code
with Flow("Preprocess") as flow:\
        images_train, images_val = preprocess.load_data_task()

        images_train_rescaled = rescaling_images_task.map(images_train)
but the
rescaling_images_task
must be defined to handle 1 image.
t
ok, so if i map over the images IN task
rescaling_images_task
and then "outside" it should work. I´ll try this. Thanks Kevin =)
But how can i get access to
images_train_rescaled
in flow? Or can i handle it as normal as outside of the flow? For example:
print("Class Names:", images_train.class_names)
?
k
You need to log it inside a task
Copy code
logger = prefect.context.get("logger")
<http://logger.info|logger.info>(images_train.class_names)
because
print
is executed during build time but you want it to execute during runtime (which tasks are for)
🎉 1
t
Great 🎉 thank u very much =)