vlslice

Code for the 2023 ICCV paper "VLSlice: Interactive Vision-and-Language Slice Discovery."

https://github.com/slymane/vlslice

Science Score: 54.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
    Links to: arxiv.org
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (15.2%) to scientific vocabulary

Keywords

ai fairness responsible-ai vision-and-language visualization
Last synced: 6 months ago · JSON representation ·

Repository

Code for the 2023 ICCV paper "VLSlice: Interactive Vision-and-Language Slice Discovery."

Basic Info
Statistics
  • Stars: 7
  • Watchers: 1
  • Forks: 0
  • Open Issues: 2
  • Releases: 0
Topics
ai fairness responsible-ai vision-and-language visualization
Created almost 4 years ago · Last pushed about 2 years ago
Metadata Files
Readme License Citation

README.md

VLSlice

VLSlice is an interactive system enabling user-guided discovery of Vision-Language Slices, coherent representation-level subgroups with consistent visiolinguistic behavior, from unlabeled image sets. Slices can help identify problematic behaviors and biases learned by web-scale pretrained models. VLSlice supports users in discovering and refining slices along arbitrary bias dimensions while leveraging those slices to assist them in validating model behavior.

[ pdf ] [ poster ] [ iccv talk ] [ showcase talk ] [ video demo ] [ website ]

Getting Started

The VLSlice client is built with a JS/Svelte client running on a Python/Flask backend. To run the server, however, only the Python dependencies must be installed. The following code blocks walk through downloading precomputed image embeddings from CLIP on OpenImages, creating an appropriate Python environment with conda, and starting the VLSlice server.

We provide demo data for running VLSlice at oregonstate.box.com/v/vlslice-demo. This data contains the first million boxes extracted from OpenImages according the process described in our paper.

```bash

1. Download Data

Labels are used for pre-filtering OpenImages as described in Section 4.1.

cd vlslice/server/static/ mv [all files downloaded from box] ./ tar xf images.tar.gz && rm images.tar.gz cd -

2. Install Python dependencies with Conda

conda env create -f environment.yml conda activate vlslice

If using an Intel CPU, sklearn intelex can speed up clustering (optional)

conda install scikit-learn-intelex=2021.4.0

3. Run the server: http://127.0.0.1:5000

cd vlslice/server python server.py ```

The server should now be running locally and can be accessed at http://127.0.0.1:5000.

Configuration

Our code can be used with any ViL model that separately embeds images and text, and any image dataset. All that is required is an array of precomputed image embeddings, image URLs, and modifying the forward pass in model.py to use your model.

Configuring Flask

All properties set under flask in the config.yml are automatically passed as a dictionary unpacked into the flask app.run() call. Set whichever settings you wish for flask to use here.

Faster Image Loading

Serving images from the /static/ folder with the built-in flask server (e.g., the example above) can lead to slow image loading. This can be mitigated by either moving images behind a CDN or by using a more sophisticated web server. During our user study, we used AWS CloudFront to deliver images stored on S3 and a gunicorn web server. We describe recommended steps for setting up a more sophisticated web server below which should be used for anything beyond the most basic exploration with VLSlice.

First, install and start a gunicorn WSGI server from inside vlslice/server. The -w argument specifies the number of server processes.

bash pip install gunicorn gunicorn --bind localhost:5000 -w 2 server:app

Then, install nginx to use as our reverse proxy. You will need to allow it firewall HTTP access.

bash sudo apt update sudo apt install nginx sudo ufw allow 'Nginx HTTP'

We will create a new nginx site for VLSlice:

bash sudo nano /etc/nginx/sites-available/vlslice

Paste the following site configuration with the absolute path to your VLSlice static folder, or whatever other location you've chosen to store the images specified by imgs.npy, under location /static > alias.

```yaml server { listen 5050; server_name localhost;

location / {
    proxy_pass http://localhost:5000;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

location /static {
    alias [ABSOLUTE PATH TO YOUR STATIC FOLDER];
    expires 7d;
}

} ```

Link the VLSlice site to active and restart nginx:

bash sudo ln -s /etc/nginx/sites-available/vlslice /etc/nginx/sites-enabled sudo systemctl restart nginx

You should now be able to navigate to localhost:5050 in a web browser and use VLSlice with significantly faster image loading.

Using Your Own Data

To configure your own data, specify three numpy files in the config.yml:

```yaml data: # ndarraystring containing N image paths. # e.g., "https://d30mxw38m32j53.cloudfront.net/00000000.jpg" imgs_npy: ./static/imgs.npy

# ndarraystring containing N image classes. # Set to "null" to disable filtering. lbls_npy: ./static/lbls.npy

# ndarrayfloat containing N image embeddings of size D. embs_npy: ./static/embs.npy
```

VLSlice will use these files to load, filtering, and cluster your images. All files are expected to share the same index order. If you wish to exclude any class of images from display in VLSlice (e.g., to remove redundant subparts of people), then the target class to be removed may be specified under exclude_classes.

Using Your Own Model

To configure your own model, specify the name and configuration of the model under the config.yml:

```yaml data: # Name of the model to load name: hf_clip

# Configuration options to pass to model initialization config: version: openai/clip-vit-base-patch16 device: cpu ```

You may add your own model by extending the base VLSliceModel class and adding a corresponding model name to the model registry. Properties under config will automatically be passed to your model during initialization. For an example, see HFCLIP.py, where we register a HuggingFace CLIP model.

```python class VLSliceModel(ABC, torch.nn.Module):

@classmethod
@abstractmethod
def similarity(cls, txt_embs: ArrayLike, img_embs: ArrayLike) -> ArrayLike:
    """Calculate text-image similarity scores normalized to the range [0, 1].

    Args:
        txt_embs (ArrayLike): N_t text embeddings.
        img_embs (ArrayLike): N_i image embeddings.

    Returns:
        ArrayLike: N_t x N_i similarity scores.
    """
    pass

@abstractmethod
def forward(self, txt: list[str]) -> ArrayLike:
    """Extract text embeddings.

    Args:
        txt (list[str]): List of N strings to embed.

    Returns:
        ArrayLike: Outputted NxD text embeddings.
    """
    pass

```

Note that the model used in VLSlice should be the same model used to extract embs_img.npy.

Development

To develop the client interface, first install npm and Node.js. Then, run the following commands after making edits to the interface. No special setup is required beyond installing the conda environment to develop the server.

```bash

Install packages

cd vlslice/client npm install

Choose one...

Build once.

npm run build

Build and check for updates.

npm run autobuild ```

Troubleshooting

Tokenizers may fail to install on Apple Silicon machines due to the rust compiler missing. The compiler can be installed with the following command:

bash curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh source "$HOME/.cargo/env"

Then install the environment with Conda as described above. Conda and Pip can take some time with this installation.

Citation

bibtex @InProceedings{Slyman_2023_ICCV, author = {Slyman, Eric and Kahng, Minsuk and Lee, Stefan}, title = {VLSlice: Interactive Vision-and-Language Slice Discovery}, booktitle = {Proceedings of the IEEE/CVF International Conference on Computer Vision (ICCV)}, month = {October}, year = {2023}, pages = {15291-15301} }

Owner

  • Name: Eric Slyman (they/them)
  • Login: slymane
  • Kind: user
  • Location: Oregon
  • Company: Oregon State University

PhD Student @ Oregon State University | Deep learning & HCI

Citation (CITATION.cff)

cff-version: 1.2.0
message: "If you use this software, please cite it as below."
authors:
  - given-names: Eric
    family-names: Slyman
    email: slymane@oregonstate.edu
    affiliation: Oregon State University
    orcid: 'https://orcid.org/0000-0002-2481-7942'
  - given-names: Minsuk
    family-names: Kahng
    email: kahngm@google.com
    affiliation: Google Research
    orcid: 'https://orcid.org/0000-0002-0291-6026'
  - given-names: Stefan
    family-names: Lee
    orcid: 'https://orcid.org/0000-0001-5953-1963'
    affiliation: Oregon State University
    email: leestef@oregonstate.edu
title: "VLSlice: Interactive Vision-and-Language Slice Discovery"
date-released: 2023-10-01
url: "https://github.com/slymane/vlslice"
preferred-citation:
  type: article
  authors:
  - given-names: Eric
    family-names: Slyman
    email: slymane@oregonstate.edu
    affiliation: Oregon State University
    orcid: 'https://orcid.org/0000-0002-2481-7942'
  - given-names: Minsuk
    family-names: Kahng
    email: kahngm@google.com
    affiliation: Google Research
    orcid: 'https://orcid.org/0000-0002-0291-6026'
  - given-names: Stefan
    family-names: Lee
    orcid: 'https://orcid.org/0000-0001-5953-1963'
    affiliation: Oregon State University
    email: leestef@oregonstate.edu
  doi: "10.0000/00000"
  journal: "International Conference on Computer Vision"
  month: 10
  title: "VLSlice: Interactive Vision-and-Language Slice Discovery"
  year: 2023

GitHub Events

Total
Last Year

Dependencies

vlslice/client/package-lock.json npm
  • 251 dependencies
vlslice/client/package.json npm
  • @rollup/plugin-commonjs ^17.0.0 development
  • @rollup/plugin-node-resolve ^11.0.0 development
  • concurrently ^7.2.1 development
  • cross-env ^7.0.3 development
  • postcss-cli ^9.1.0 development
  • rollup ^2.3.4 development
  • rollup-plugin-css-only ^3.1.0 development
  • rollup-plugin-svelte ^7.0.0 development
  • rollup-plugin-terser ^7.0.0 development
  • svelte ^3.0.0 development
  • tailwindcss ^3.0.24 development
  • appjs-linux-x64 ^0.0.19
  • autobuild ^0.0.2
  • autoprefixer ^10.4.7
  • d3 ^7.4.4
  • daisyui ^2.15.1
  • sirv-cli ^2.0.0
  • svelte-lazy-image ^0.5.1
environment.yml pypi
  • tokenizers ==0.12.1