Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
mednet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
medai
software
mednet
Commits
ff6cd19c
Commit
ff6cd19c
authored
1 year ago
by
ogueler@idiap.ch
Committed by
Daniel CARRON
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
fixed and renamed comparevis
parent
cd85bb03
No related branches found
No related tags found
1 merge request
!12
Adds grad-cam support on classifiers
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/ptbench/scripts/cli.py
+2
-2
2 additions, 2 deletions
src/ptbench/scripts/cli.py
src/ptbench/scripts/compare_vis.py
+12
-5
12 additions, 5 deletions
src/ptbench/scripts/compare_vis.py
with
14 additions
and
7 deletions
src/ptbench/scripts/cli.py
+
2
−
2
View file @
ff6cd19c
...
...
@@ -8,7 +8,7 @@ from clapper.click import AliasedGroup
from
.
import
(
calculate_road
,
comparevis
,
compare
_
vis
,
config
,
database
,
evaluate
,
...
...
@@ -33,7 +33,7 @@ def cli():
cli
.
add_command
(
calculate_road
.
calculate_road
)
cli
.
add_command
(
comparevis
.
comparevis
)
cli
.
add_command
(
compare
_
vis
.
compare
_
vis
)
cli
.
add_command
(
config
.
config
)
cli
.
add_command
(
database
.
database
)
cli
.
add_command
(
evaluate
.
evaluate
)
...
...
This diff is collapsed.
Click to expand it.
src/ptbench/scripts/comparevis.py
→
src/ptbench/scripts/compare
_
vis.py
+
12
−
5
View file @
ff6cd19c
...
...
@@ -26,6 +26,13 @@ def _sorting_rule(folder_name):
else
:
# Everything else will be sorted alphabetically after fullgrad and before randomcam
return
(
3
,
folder_name
)
def
_get_images_from_directory
(
dir_path
):
image_files
=
[]
for
root
,
_
,
files
in
os
.
walk
(
dir_path
):
for
file
in
files
:
if
file
.
lower
().
endswith
((
"
.png
"
,
"
.jpg
"
,
"
.jpeg
"
)):
image_files
.
append
(
os
.
path
.
join
(
root
,
file
))
return
image_files
@click.command
(
epilog
=
"""
Examples:
...
...
@@ -37,7 +44,7 @@ def _sorting_rule(folder_name):
.. code:: sh
ptbench comparevis -i path/to/input_folder -o path/to/output_folder
ptbench compare
-
vis -i path/to/input_folder -o path/to/output_folder
"""
,
)
@click.option
(
...
...
@@ -56,7 +63,7 @@ def _sorting_rule(folder_name):
type
=
click
.
Path
(),
)
@verbosity_option
(
logger
=
logger
,
expose_value
=
False
)
def
comparevis
(
input_folder
,
output_folder
)
->
None
:
def
compare
_
vis
(
input_folder
,
output_folder
)
->
None
:
"""
Compares multiple visualization techniques by showing their results in
one image.
"""
...
...
@@ -126,13 +133,13 @@ def comparevis(input_folder, output_folder) -> None:
os
.
makedirs
(
output_directory
,
exist_ok
=
True
)
# Use a set (unordered collection of unique elements) for efficient membership tests
image_names
=
set
(
os
.
listdir
(
comparison_folders
[
0
]))
image_names
=
set
(
[
os
.
path
.
basename
(
img
)
for
img
in
_get_images_from_directory
(
comparison_folders
[
0
])
]
)
# Only keep image names that exist in all folders
for
folder
in
comparison_folders
[
1
:]:
# This is basically an intersection-check of contents of different folders
# Images that don't exist in all folders are removed from the set
image_names
&=
set
(
os
.
listdir
(
folder
))
image_names
&=
set
(
[
os
.
path
.
basename
(
img
)
for
img
in
_get_images_from_directory
(
folder
)
]
)
if
not
image_names
:
raise
ValueError
(
"
No common images found in the folders.
"
)
...
...
@@ -158,7 +165,7 @@ def comparevis(input_folder, output_folder) -> None:
)
axs
=
axs
.
ravel
()
for
i
,
folder
in
enumerate
(
comparison_folders
):
image_path
=
os
.
path
.
join
(
folder
,
image_name
)
image_path
=
[
img
for
img
in
_get_images_from_directory
(
folder
)
if
os
.
path
.
basename
(
img
)
==
image_name
][
0
]
try
:
img
=
cv2
.
imread
(
image_path
)
img
=
cv2
.
cvtColor
(
img
,
cv2
.
COLOR_BGR2RGB
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment