Trusted-AI / AIF360

A comprehensive set of fairness metrics for datasets and machine learning models, explanations for these metrics, and algorithms to mitigate bias in datasets and models.
https://aif360.res.ibm.com/
Apache License 2.0
2.37k stars 823 forks source link

Query regarding debiased model saving in Adversarial Debiasing #286

Open Sreyashi-Bhattacharjee opened 2 years ago

Sreyashi-Bhattacharjee commented 2 years ago

Hello, is there a way to save and reuse the debiased model created in Adversarial Debiasing? This model:

model

I have tried pickle , joblib and keras method, none of them seem to work.

tried
giandos200 commented 2 years ago

try to use the Sklearn version instead of the TF version and you will have no problem with pickle dump after the fit. if you want to use the TF version try to save it as a TF model.

Sreyashi-Bhattacharjee commented 2 years ago

I am trying to use the sklearn version but it gets stuck at :

err

I have tried sending the protected attribute as a string, a list as well as leaving it None. Nothing seems to work. Where am I going wrong? I have split the data using sklearn train test split as well as tried converting the data into BinaryDataset type.

As far as tensorflow model saving goes, those methods are not working either.

err2
minasmz commented 2 years ago

Hello,

I have a similar issue. In Tensorflow save_weight and save do not work for me either. I tried to save the Tensorflow graph in checkpoint and meta files, however, I cannot load the model! Did you find any solution? I appreciate any suggestion.

evilantal commented 10 months ago

I tried this using the sklearn version. But when I try to pickle.dump() using cloudpickle, I get an error saying "cannot pickle 'Graph' object". I'm not even sure why a fitted AdversarialDebiasing model would be a 'Graph' object.

cloudpickle version = 1.5.0 aif360 version = 0.5.0

In the example below X is a DataFrame that includes 'protfeat' set as index and y is a numpy array of 1/0 labels.

from aif360.sklearn.inprocessing import AdversarialDebiasing
import tensorflow.compat.v1 as tf
from aif360.datasets import StandardDataset
import pandas as pd
from cloudpickle import pickle

tf.disable_eager_execution()
sess = tf.Session()

model = AdversarialDebiasing(
    prot_attr='protfeat',
    scope_name='debiased_model',
    num_epochs=50,
    batch_size=128,
    debias=True, 
    random_state=1337,
    classifier_num_hidden_units=200
)

model.fit(X, y)

with open(os.path.join(folder.get_path(), 'test_pickle.pkl'), 'w') as f:
     pickle.dump(model, f)