Hi, I want to use Kedro viz to visualize images ma...
# questions
s
Hi, I want to use Kedro viz to visualize images made in a kedro pipeline. The examples I've seen so far show how to use the
plotly.PlotlyDataSet
to make bar plots etc., but I am having a hard time figuring out how to plot a image similar to how you do it with
plt.imshow(...)
in kedro viz. Anyone here who has knowledge of how to do this?
j
I’ve not done this before, but from what I can see in the docs
plt.imshow()
should never need to be used in Kedro if you’re saving figures. Whatever node is creating the figure should just return the figure object. Then, assuming you have declared a dataset for the figure in the catalog (
plotly.PlotlyDataSet
,
matplotlib.MatplotlibWriter
etc) and used that as the node output in
pipeline.py
, the visualisation should be available in Kedro Viz. However, the docs here say that the Kedro Viz figure visualisation only works up to 18.3. I just tried to get a Matplotlib figure to preview in Viz with my 18.4 project and it didn’t work, so I guess the docs are accurate.
s
Ok, I'll try that and see if it works 👍 Thanks!
a
@Jordan is definitely right here, although I’m a bit confused that this only works in 0.18.3. Is that intentional @Rashida Kanchwala or a known bug? Matplotlib plots that are saved as png in the data catalog should show up in the metadata side panel (see https://github.com/kedro-org/kedro-viz/issues/783). There’s a proposal to do this for Image dataset also (https://github.com/kedro-org/kedro-viz/issues/1043) but hasn’t been implemented as we didn’t think there was enough interest for it - but if you’re interested then that counts!
r
hi yes, you will have to use matplotlib.MatplotlibWriter to plot an image. we are currently fixing the issue on 18.4 and should be releasing the fix later this week.
a
@Rashida Kanchwala is the bug just the move of kedro-datasets?
r
yes that's right.
👍 1
s
Yes @Antony Milne, we're definitely interested in this. We make technology where the output of our analysis are images, like in medical imaging. And we compare these to known labels, so visualizing these side by side together with plots of how well it performes is of great interest. So what you are saying is that the matplotlibWriter is the best way to plot these in kedro-viz at the moment?
👍 1
👍🏽 1
a
Yes indeed - it’s currently the only way to show a png in kedro-viz. Which dataset do you use typically use for your output images? One of the kedro builtin ones or a custom one?
s
Currently we haven't saved all the intermediate datasets, only the final output of the pipeline. But our data is structured in pandas dataframes where the data is 2D numpy arrays, and PIL image objects
I have got the matplotlib dataset working, but here you miss the interactive features in the plots. It would be nice to get the plotly.express dataset working with it's imshow function to make interactive plots of the different images in the dataframe
r
I think for that you will have to use plotly instead of matplotlib if you want interactivity. You can use plotly express or plotly graph objects for more complex plots. Here are some docs on how to intergrate on kedro-viz - https://kedro.readthedocs.io/en/stable/visualisation/visualise_charts_with_plotly.html
s
I tried that last part, but did't get it to work. Do you have an example on how the dataset yml. file should look when saving image plots? I especially wondered what the plotly args
type: <type of image plot?>
should be.
j
You are probably better looking at the slightly more recent version of the docs at https://kedro.readthedocs.io/en/latest/visualisation/visualise_charts_with_plotly.html
(These changes will go live next time we make a release)
The example project is in my repo @Simen Husøy https://github.com/stichbury/kedro-projects
s
Nice, I'll take a look at those! Thanks
a
@Simen Husøy I just tried this out and it is indeed possible using plotly. Catalog entry should be:
Copy code
image:
  type: plotly.JSONDataSet
  filepath: data/image.png
and then the node should return the plotly figure created by
px.imshow()
.
The reason this works is because
plotly.JSONDataSet
takes as input a plotly Figure. It doesn’t matter what type that is (scatter plot, bar plot, image, whatever - they’re all plotly Figures). N.B. @Rashida Kanchwala @Tynan this is an interesting thing I hadn’t thought of doing before - using plotly just to show images that you can zoom in/out of.
👍 2
This is using kedro-viz 5.2.0 (literally just released, should work with the new
kedro_datasets
paths) and kedro 0.18.4. It should also work on kedro 0.18.3 fine with older versions of kedro-viz.
t
very cool
s
Yes, figured it out together with Rashida! Worked nice when using the JSONDataSet. 👏 Btw. do you know it it's possible to show multiple figs side by side or if its possible to make the figure bigger than the screen. I have a case here where I want to plot a figure with 200 rows and 3 columns of pictures (a matrix of subplots of images). This works well when using something as
web-agg
etc. Is there support for plotting multiple figures in the same kedro dataset, or make it possible to scroll down, like a web page, to make room for all the subplots. (figure under to illustrate the problem when you want to plot 50+ images):
👍 1
r
not yet, could u pls raise a github issue with these asks and we can look at it and investigate further on how we can enable it.
👍🏽 1
s
Yes, I'll do that @Rashida Kanchwala 👍