Skip to content

Commit

Permalink
Update heatmap assets
Browse files Browse the repository at this point in the history
  • Loading branch information
adrhill committed Dec 3, 2024
1 parent 538fe12 commit 5b7f607
Show file tree
Hide file tree
Showing 9 changed files with 870 additions and 398 deletions.
1,230 changes: 842 additions & 388 deletions assets/heatmaps/Manifest.toml

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions assets/heatmaps/Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
[deps]
DataAugmentation = "88a5189c-e7ff-4f85-ac6b-e6158070f02e"
ExplainableAI = "4f1bc3e1-d60d-4ed0-9367-9bdff9846d3b"
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c"
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
ImageIO = "82e4d734-157c-48bb-816b-45c225c6df19"
ImageInTerminal = "d8c32880-2388-543b-8c61-d9f865259254"
ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1"
Metalhead = "dbeba491-748d-5e0e-a39e-b530a07fa0cc"
RelevancePropagation = "0be6dd02-ae9e-43eb-b318-c6e81d6890d8"
VisionHeatmaps = "27106da1-f8bc-4ca8-8c66-9b8289f1e035"
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
Binary file modified assets/heatmaps/castle_Gradient.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/heatmaps/castle_IntegratedGradients.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/heatmaps/castle_SmoothGrad.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 21 additions & 10 deletions assets/heatmaps/generate_assets.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
using Pkg
Pkg.activate(@__DIR__)

using ExplainableAI
using Metalhead # pre-trained vision models
using HTTP, FileIO, ImageMagick # load image from URL
using RelevancePropagation
using VisionHeatmaps
using Zygote # load autodiff backend for gradient-based methods
using Flux, Metalhead # pre-trained vision models in Flux
using DataAugmentation # input preprocessing
using HTTP, FileIO, ImageIO # load image from URL
using ImageInTerminal # show heatmap in terminal

# Load model
model = VGG(16; pretrain=true).layers
model = strip_softmax(model)
model = canonize(model)
# Load & prepare model
model = VGG(16, pretrain=true).layers

# Load input
url = HTTP.URI("https://raw.githubusercontent.com/adrhill/ExplainableAI.jl/gh-pages/assets/heatmaps/castle.jpg")
img = load(url)
input = preprocess_imagenet(img)
input = reshape(input, 224, 224, 3, :) # reshape to WHCN format
url = HTTP.URI("https://raw.githubusercontent.com/Julia-XAI/ExplainableAI.jl/gh-pages/assets/heatmaps/castle.jpg")
img = load(url)

# Preprocess input
mean = (0.485f0, 0.456f0, 0.406f0)
std = (0.229f0, 0.224f0, 0.225f0)
tfm = CenterResizeCrop((224, 224)) |> ImageToTensor() |> Normalize(mean, std)
input = apply(tfm, Image(img)) # apply DataAugmentation transform
input = reshape(input.data, 224, 224, 3, :) # unpack data and add batch dimension

# Run XAI methods
methods = Dict(
Expand Down
Binary file modified assets/heatmaps/streetsign_Gradient.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/heatmaps/streetsign_IntegratedGradients.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/heatmaps/streetsign_SmoothGrad.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5b7f607

Please sign in to comment.