From 56ab1c106b3255ee0915409ad74ffe223d4316dd Mon Sep 17 00:00:00 2001 From: Adrian Hill Date: Tue, 20 Feb 2024 00:02:27 +0100 Subject: [PATCH 1/2] Make XAIBase a direct dependency --- Project.toml | 10 +--------- src/VisionHeatmaps.jl | 12 ++---------- src/heatmap.jl | 2 +- ext/VisionHeatmapsXAIBaseExt.jl => src/xaibase.jl | 13 ++----------- test/runtests.jl | 4 ++-- test/{test_xaibase_ext.jl => test_xaibase.jl} | 0 6 files changed, 8 insertions(+), 33 deletions(-) rename ext/VisionHeatmapsXAIBaseExt.jl => src/xaibase.jl (85%) rename test/{test_xaibase_ext.jl => test_xaibase.jl} (100%) diff --git a/Project.toml b/Project.toml index e6d722a..98a853a 100644 --- a/Project.toml +++ b/Project.toml @@ -1,27 +1,19 @@ name = "VisionHeatmaps" uuid = "27106da1-f8bc-4ca8-8c66-9b8289f1e035" authors = ["Adrian Hill "] -version = "1.3.0" +version = "1.3.1-DEV" [deps] ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4" ImageCore = "a09fc81d-aa75-5fe9-8630-4744c3626534" ImageTransformations = "02fcd773-0e25-5acc-982a-7f6622650795" Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59" -Requires = "ae029012-a4dd-5104-9daa-d747884805df" XAIBase = "9b48221d-a747-4c1b-9860-46a1d8ba24a7" -[weakdeps] -XAIBase = "9b48221d-a747-4c1b-9860-46a1d8ba24a7" - -[extensions] -VisionHeatmapsXAIBaseExt = "XAIBase" - [compat] ColorSchemes = "3" ImageCore = "0.9, 0.10" ImageTransformations = "0.10" Interpolations = "0.15" -Requires = "1" XAIBase = "3" julia = "1.6" diff --git a/src/VisionHeatmaps.jl b/src/VisionHeatmaps.jl index b6ada9b..27a59a8 100644 --- a/src/VisionHeatmaps.jl +++ b/src/VisionHeatmaps.jl @@ -4,19 +4,11 @@ using ColorSchemes: ColorScheme, colorschemes, get, seismic using ImageTransformations: imresize using Interpolations: Lanczos using ImageCore -using Requires: @require +using XAIBase: Explanation, AbstractXAIMethod, analyze include("heatmap.jl") include("overlay.jl") - -if !isdefined(Base, :get_extension) - using Requires - function __init__() - @require XAIBase = "9b48221d-a747-4c1b-9860-46a1d8ba24a7" include( - "../ext/VisionHeatmapsXAIBaseExt.jl" - ) - end -end +include("xaibase.jl") export heatmap, heatmap_overlay diff --git a/src/heatmap.jl b/src/heatmap.jl index e381277..56bee01 100644 --- a/src/heatmap.jl +++ b/src/heatmap.jl @@ -1,4 +1,4 @@ -const DEFAULT_COLORSCHEME = seismic +const DEFAULT_COLORSCHEME = :seismic const DEFAULT_REDUCE = :sum const DEFAULT_RANGESCALE = :centered diff --git a/ext/VisionHeatmapsXAIBaseExt.jl b/src/xaibase.jl similarity index 85% rename from ext/VisionHeatmapsXAIBaseExt.jl rename to src/xaibase.jl index a204403..e443d1f 100644 --- a/ext/VisionHeatmapsXAIBaseExt.jl +++ b/src/xaibase.jl @@ -1,16 +1,9 @@ -module VisionHeatmapsXAIBaseExt - -using VisionHeatmaps, XAIBase - struct HeatmapConfig colorscheme::Symbol reduce::Symbol rangescale::Symbol end -const DEFAULT_COLORSCHEME = :seismic -const DEFAULT_REDUCE = :sum -const DEFAULT_RANGESCALE = :centered const DEFAULT_HEATMAP_PRESET = HeatmapConfig( DEFAULT_COLORSCHEME, DEFAULT_REDUCE, DEFAULT_RANGESCALE ) @@ -42,7 +35,7 @@ end Visualize `Explanation` from XAIBase as a vision heatmap. Assumes WHCN convention (width, height, channels, batchsize) for `explanation.val`. """ -function VisionHeatmaps.heatmap(expl::Explanation; kwargs...) +function heatmap(expl::Explanation; kwargs...) c = get_heatmapping_config(expl; kwargs...) return heatmap( expl.val; @@ -65,9 +58,7 @@ Refer to the `analyze` documentation for more information on available keyword a To customize the heatmapping style, first compute an explanation using `analyze` and then call [`heatmap`](@ref) on the explanation. """ -function VisionHeatmaps.heatmap(input, analyzer::AbstractXAIMethod, args...; kwargs...) +function heatmap(input, analyzer::AbstractXAIMethod, args...; kwargs...) expl = analyze(input, analyzer, args...; kwargs...) return heatmap(expl) end - -end # module diff --git a/test/runtests.jl b/test/runtests.jl index 3a11516..1ba3c7f 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -19,8 +19,8 @@ using JuliaFormatter @info "Testing heatmaps..." include("test_heatmap.jl") end - @testset "XAIBase extension" begin + @testset "XAIBase Explanations" begin @info "Testing heatmaps on XAIBase explanations..." - include("test_xaibase_ext.jl") + include("test_xaibase.jl") end end diff --git a/test/test_xaibase_ext.jl b/test/test_xaibase.jl similarity index 100% rename from test/test_xaibase_ext.jl rename to test/test_xaibase.jl From 03e7068a46aba9d1110933fd1eda88d6f54fddb7 Mon Sep 17 00:00:00 2001 From: Adrian Hill Date: Tue, 20 Feb 2024 00:09:02 +0100 Subject: [PATCH 2/2] Improve documentation --- src/heatmap.jl | 2 +- src/xaibase.jl | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/heatmap.jl b/src/heatmap.jl index 56bee01..e926610 100644 --- a/src/heatmap.jl +++ b/src/heatmap.jl @@ -3,7 +3,7 @@ const DEFAULT_REDUCE = :sum const DEFAULT_RANGESCALE = :centered """ - heatmap(x) + heatmap(x::AbstractArray) Visualize 4D arrays as heatmaps, assuming the WHCN convention for input array dimensions (width, height, color channels, batch dimension). diff --git a/src/xaibase.jl b/src/xaibase.jl index e443d1f..7e7e818 100644 --- a/src/xaibase.jl +++ b/src/xaibase.jl @@ -30,10 +30,13 @@ function get_heatmapping_config(expl::Explanation; kwargs...) end """ - heatmap(explanation) + heatmap(expl::Explanation) Visualize `Explanation` from XAIBase as a vision heatmap. -Assumes WHCN convention (width, height, channels, batchsize) for `explanation.val`. +Assumes WHCN convention (width, height, channels, batch dimension) for `explanation.val`. + +This will use the default heatmapping style for the given type of explanation. +Defaults can be overridden via keyword arguments. """ function heatmap(expl::Explanation; kwargs...) c = get_heatmapping_config(expl; kwargs...) @@ -47,7 +50,7 @@ function heatmap(expl::Explanation; kwargs...) end """ - heatmap(input, analyzer) + heatmap(input::AbstractArray, analyzer::AbstractXAIMethod) Compute an `Explanation` for a given `input` using the XAI method `analyzer` and visualize it as a vision heatmap.