JuliaTrustworthyAI / CounterfactualExplanations.jl

A package for Counterfactual Explanations and Algorithmic Recourse in Julia.
https://juliatrustworthyai.github.io/CounterfactualExplanations.jl/
MIT License
117 stars 7 forks source link

Investigate `ONNX.jl` to handle Python models #171

Closed RaunoArike closed 1 year ago

RaunoArike commented 1 year ago

Instead of relying on PythonCall to explain models trained in Python, investigate whether it's possible to use ONNX.jl to transform models into Flux models and then proceed as usual.

VincentPikand commented 1 year ago

Report: Integrating PyTorch models into the package

This report describes the design choices we made throughout the process of integrating models defined using PyTorch into the CounterfactualExplanations.jl package. We wrote functionality that supports generating counterfactuals for any neural network the user has defined and trained in PyTorch, regardless of the specific architectural details of the model.

Design choice 1: using PythonCall.jl

When we started looking into possible ways of generating counterfactuals for Python models using Julia, we found three libraries that offered functionalities for conversion between Python and Julia:

For the reasons described above, we decided to solve this problem using PythonCall.jl.

Design choice 2: Supporting only pretrained PyTorch models

Once we had implemented basic support for generating counterfactuals for PyTorch models through PythonCall.jl, we discussed with the client whether the package should offer support only for PyTorch models predefined by the user in a Python environment or whether we should also offer support for training PyTorch models inside the package. Since defining PyTorch models through Julia code is tedious and error-prone, the client expected most users to only want counterfactuals for models they have themselves previously trained using PyTorch. Since the client has considerable machine learning experience and offered compelling reasons for this design choice, we decided not to offer special support for defining and training PyTorch models through our package.