Git Product home page Git Product logo

attribute-cam's Introduction

Biased Binary Attribute Classifiers Ignore the Majority Classes

This package provides all implementations of methods and scripts to reproduce the results of our paper Biased Binary Attribute Classifiers Ignore the Majority Classes to be presented at the Swiss Conference on Data Science (SDS) 2024:

If you are making use of the source code for your own experiments, please cite the following:

@inproceedings{zhang2024attribute,
    author = {Zhang, Xinyi and Bieri, Johanna Sophie and G\"unther, Manuel},
    title = {Biased Binary Attribute Classifiers Ignore the Majority Classes},
    booktitle = {Swiss Conference on Data Science (SDS)},
    year = {2024}
}

This code runs and evaluates different CAM techniques on two different attribute classifiers. For creating the CAMs, we directly rely on functionality from PyTorch-Grad-CAM. It is based on the Bachelor thesis of Johanna Bieri in the Artificial Intelligence and Machine Learning group at the Department of Informatics, University of Zurich.

Installation

This code comes with a conda installation, which you can use via:

conda env create -f environment.yaml
conda activate attribute-cam

This will install several executable scripts into the conda environment attribute-cam. Additionally, this will automatically install this package in editable mode via pip.

Pre-trained Models

In this package, we evaluate two facial attribute prediction models, which have been trained within the Caffe framework, and which were converted to PyTorch and slightly adapted to work with CAM techniques. Please download the Pre-trained Models and place them into the model directory.

Data

All of our evaluation relies on faces aligned to 224x224 pixels. We strictly follow the implementation in The Original AFFACT Paper. For simplicity, you can download the Pre-aligned Faces of the CelebA dataset and extract them into the CelebA directory. Required protocol files can be found within the CelebA/protocol directory, which are partially taken from Kaggle and partially created by ourselves.

Scripts

Implementations of the following scripts can be found in attribute_cam/script. All scripts contain a --help option to show possible arguments.

  • predict.py computes the prediction of the model on the original frontal images. This is rather quick.

  • extract_cams.py extracts CAM images for the frontal images of the given model and CAM technique and all attributes. This might take a while.

  • average_cams.py will compute average CAM images using various filter criteria, based on the ground truth and the prediction for each attribute. This requires both predict.py and extract_cams.py to have run.

  • analyze.py evaluates mean (and std) of the proportional energy measured over all attributes for various filter criteria. This requires both predict.py and extract_cams.py to have run.

Code

The following code files are available in attribute_cam:

  • dataset.py implements the dataset and the image IO

  • model.py implements the original AFFACT models and the attribute prediction

  • cam.py implements the extraction of CAMs from the images for all attributes, and the averaging of CAM images

  • filter.py implements IO of prediction and ground-truth attributes, and defines several filters that make use of the prediction and the ground truth

  • evaluation.py computes proportional energy and error rates

  • mask.py defines precise masks for all attributes that are required to compute the proportional energy

Additional Scripts

  • additional_scripts scripts to compute frontal subsets, earlier versions of the masks, and alike

Troubleshooting

In case you find mistakes in our code, please either file an issue, or contact Manuel Günther.

attribute-cam's People

Contributors

siebenkopf avatar johannauzh avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.