https://prefect.io logo
#prefect-community
Title
# prefect-community
t

Tim-Oliver

11/03/2022, 7:24 AM
Hi, I would like to save task-results in a custom way. Say a task produces an image and I would like to cache this result. Does anyone know how I could save it as
.tif
file? I tried to implement a custom
Serializer
which just passes the image through and then wanted to use a custom
WritableFileSystem
as storage option that takes care of writing/reading the image as
.tif
. So far I did not manage and would be grateful for some advice. I am trying this in Prefect 2.x. In Prefect 1.x I managed to do something like this by implementing a custom
LocalResult
.
a

Anna Geller

11/03/2022, 12:16 PM
what problem are you trying to solve? results are not meant for persisting data to use by your end system, they are meant for orchestration (retries, caching) you can still write data as .tif files where needed explicitly in your tasks/flows
t

Tim-Oliver

11/03/2022, 1:24 PM
I work on biomedical image analysis and our workflows can be broken down into three big steps (i) preprocessing, (ii) segmentation and (iii) feature extraction. The three steps produce (a) images, (b) images and (c) tabular data respectively. The first two steps are most of the time the expensive ones in terms of compute, memory and result size, which is why it makes a lot of sense to cache/persist them. Additionally, these intermediate results are often used to understand the final tabular data and we want to interactively visualize them together. Currently, I am handling the writing of e.g. tif files inside of the tasks and only return the file-path. The problem I am trying to solve is the reduction of boiler plate code for image saving in the tasks. Since, it was possible to have custom result types in Prefect 1.x I was wondering if this is something that you are also considering for Prefect 2.x? I guess I could also come up with my own decorator that takes care of writing/reading image data and put it before the task decorator. Or maybe there is a Prefect 2.x pattern that I am not aware of and you could point me towards it.
1
a

Anna Geller

11/03/2022, 2:16 PM
I think you could solve this problem of boilerplate code by implementing a custom storage block that does the processing you need But let me tag @Zanie since he built results and IIRC he used to work on similar kind of problems before joining Prefect
🙏 1
z

Zanie

11/03/2022, 3:21 PM
We have not added hooks for custom persisted result classes yet, but intend to.
I’ve seen people asking about this particular form of human readable result before too, so we’ll probably add it to the core library.
🙏 3
3 Views