Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pseudo_image
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
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
Léo Schneider
pseudo_image
Commits
10edb8ba
Commit
10edb8ba
authored
1 week ago
by
Schneider Leo
Browse files
Options
Downloads
Patches
Plain Diff
clean : grad_cam
fix : error in E.COLI f_name
parent
f4753ec3
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
data/label_raw/230804_strain_peptides_antibiogram_Enterobacterales.xlsx
+0
-0
0 additions, 0 deletions
.../230804_strain_peptides_antibiogram_Enterobacterales.xlsx
image_ref/grad_cam.py
+12
-34
12 additions, 34 deletions
image_ref/grad_cam.py
with
12 additions
and
34 deletions
data/label_raw/230804_strain_peptides_antibiogram_Enterobacterales.xlsx
+
0
−
0
View file @
10edb8ba
No preview for this file type
This diff is collapsed.
Click to expand it.
image_ref/grad_cam.py
+
12
−
34
View file @
10edb8ba
...
...
@@ -2,15 +2,12 @@ import numpy as np
import
torch
import
cv2
from
torchvision.transforms
import
transforms
from
image_ref.config
import
load_args_contrastive
from
image_ref.dataset_ref
import
Threshold_noise
,
Log_normalisation
,
npy_loader
from
image_ref.main
import
load_model
from
image_ref.model
import
Classification_model_duo_contrastive
def
compute_class_activation_map
():
args
=
load_args_contrastive
()
def
compute_class_activation_map
(
path_aer
,
path_ana
,
path_ref
,
model_path
,
model_type
=
'
Resnet18
'
):
transform
=
transforms
.
Compose
(
[
transforms
.
Resize
((
224
,
224
)),
...
...
@@ -22,13 +19,8 @@ def compute_class_activation_map():
[
transforms
.
Resize
((
224
,
224
)),
transforms
.
Normalize
(
0.5
,
0.5
)])
model_path
=
'
../saved_model/baseline_resnet18_contrastive_prop_30_bis.pt
'
path_aer
=
'
../data/processed_data/npy_image/data_test_contrastive/Citrobacter freundii/CITFRE17_AER.npy
'
path_ana
=
'
../data/processed_data/npy_image/data_test_contrastive/Citrobacter freundii/CITFRE17_ANA.npy
'
# path_ref ='../image_ref/img_ref/Citrobacter freundii.npy' #positive
# path_ref = '../image_ref/img_ref/Enterobacter hormaechei.npy' #negative
path_ref
=
'
../image_ref/img_ref/Proteus mirabilis.npy
'
# negative
tensor_aer
=
npy_loader
(
path_aer
)
tensor_ana
=
npy_loader
(
path_ana
)
tensor_ref
=
npy_loader
(
path_ref
)
...
...
@@ -44,12 +36,11 @@ def compute_class_activation_map():
tensor_ref
=
torch
.
unsqueeze
(
tensor_ref
,
dim
=
0
)
model
=
Classification_model_duo_contrastive
(
model
=
args
.
model
,
n_class
=
2
)
model
=
Classification_model_duo_contrastive
(
model
=
model
_type
,
n_class
=
2
)
model
.
double
()
# load weight
if
args
.
pretrain_path
is
not
None
:
load_model
(
model
,
model_path
)
print
(
'
model loaded
'
)
load_model
(
model
,
model_path
)
print
(
'
model loaded
'
)
# Identify the target layer
target_layer
=
model
.
im_encoder
.
layer4
[
-
1
]
...
...
@@ -112,24 +103,11 @@ def compute_class_activation_map():
return
heatmap
if
__name__
==
'
__main__
'
:
# compute_class_activation_map()
transform
=
transforms
.
Compose
(
[
transforms
.
Resize
((
224
,
224
)),
Threshold_noise
(
500
),
Log_normalisation
(),
transforms
.
Normalize
(
0.5
,
0.5
)])
ref_transform
=
transforms
.
Compose
(
[
transforms
.
Resize
((
224
,
224
)),
Threshold_noise
(
0
),
Log_normalisation
(),
transforms
.
Normalize
(
0.5
,
0.5
)
])
path_ref
=
'
../image_ref/img_ref/Enterobacter hormaechei.npy
'
# negative
tensor_ref
=
npy_loader
(
path_ref
)
model_path
=
'
../saved_model/baseline_resnet18_contrastive_prop_30_bis.pt
'
path_aer
=
'
../data/processed_data/npy_image/data_test_contrastive/Citrobacter freundii/CITFRE17_AER.npy
'
path_ana
=
'
../data/processed_data/npy_image/data_test_contrastive/Citrobacter freundii/CITFRE17_ANA.npy
'
# path_ref ='../image_ref/img_ref/Citrobacter freundii.npy' #positive
# path_ref = '../image_ref/img_ref/Enterobacter hormaechei.npy' #negative
path_ref
=
'
../image_ref/img_ref/Proteus mirabilis.npy
'
# negative
ref_base
=
tensor_ref
.
squeeze
()
ref_false
=
transform
(
tensor_ref
).
squeeze
()
ref_true
=
ref_transform
(
tensor_ref
).
squeeze
()
\ No newline at end of file
compute_class_activation_map
(
path_aer
,
path_ana
,
path_ref
,
model_path
)
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