Skip to main content

B-cos models.

Project description

B-cos Networks v2

M. Böhle, N. Singh, M. Fritz, B. Schiele.

Improved B-cos Networks.

If you want to take a quick look at the explanations the models generate, you can try out the Gradio web demo on 🤗 Spaces.

If you prefer a more hands-on approach, you can take a look at the demo notebook on Colab. or load the models directly via torch hub as explained below.

Quick Start

Loading the models via torch hub is as easy as:

import torch

# list all available models
torch.hub.list('B-cos/B-cos-v2')

# load a pretrained model
model = torch.hub.load('B-cos/B-cos-v2', 'resnet50', pretrained=True)

Inference and explanation visualization is as simple as:

from PIL import Image
import matplotlib.pyplot as plt

# load image
img = model.transform(Image.open('cat.jpg'))
img = img[None].requires_grad_()

# predict and explain
model.eval()
expl_out = model.explain(img)
print("Prediction:", expl_out["prediction"])  # predicted class idx
plt.imshow(expl_out["explanation"])
plt.show()

See the demo notebook for more details.

Stay tuned, more info to come soon!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bcos-0.0.1.tar.gz (83.8 kB view hashes)

Uploaded Source

Built Distribution

bcos-0.0.1-py3-none-any.whl (108.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page