Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
P
PAVEN
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Antonio Jesus Diaz Honrubia
PAVEN
Commits
22db3a48
Commit
22db3a48
authored
Mar 31, 2025
by
Antonio Jesus Diaz Honrubia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
ef98c8f0
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
85 additions
and
0 deletions
+85
-0
Process saliency map/utils.py
Process saliency map/utils.py
+85
-0
No files found.
Process saliency map/utils.py
0 → 100644
View file @
22db3a48
import
torch
import
torch.nn
as
nn
from
loss
import
*
import
cv2
from
torchvision
import
utils
from
PIL
import
Image
def
get_loss
(
pred_map
,
gt
,
args
):
loss
=
torch
.
FloatTensor
([
0.0
])
.
cuda
()
if
args
.
kldiv
:
loss
+=
args
.
kldiv_coeff
*
kldiv
(
pred_map
,
gt
)
if
args
.
cc
:
loss
+=
args
.
cc_coeff
*
cc
(
pred_map
,
gt
)
if
args
.
l1
:
loss
+=
args
.
l1_coeff
*
criterion
(
pred_map
,
gt
)
if
args
.
sim
:
loss
+=
args
.
sim_coeff
*
similarity
(
pred_map
,
gt
)
return
loss
def
loss_func
(
pred_map
,
gt
,
args
):
loss
=
torch
.
FloatTensor
([
0.0
])
.
cuda
()
criterion
=
nn
.
L1Loss
()
assert
pred_map
.
size
()
==
gt
.
size
()
if
len
(
pred_map
.
size
())
==
4
:
''' Clips: BxClXHxW '''
assert
pred_map
.
size
(
0
)
==
args
.
batch_size
pred_map
=
pred_map
.
permute
((
1
,
0
,
2
,
3
))
gt
=
gt
.
permute
((
1
,
0
,
2
,
3
))
for
i
in
range
(
pred_map
.
size
(
0
)):
loss
+=
get_loss
(
pred_map
[
i
],
gt
[
i
],
args
)
loss
/=
pred_map
.
size
(
0
)
return
loss
return
get_loss
(
pred_map
,
gt
,
args
)
class
AverageMeter
(
object
):
'''Computers and stores the average and current value'''
def
__init__
(
self
):
self
.
reset
()
def
reset
(
self
):
self
.
val
=
0
self
.
avg
=
0
self
.
sum
=
0
self
.
count
=
0
def
update
(
self
,
val
,
n
=
1
):
self
.
val
=
val
self
.
sum
+=
val
*
n
self
.
count
+=
n
self
.
avg
=
self
.
sum
/
self
.
count
def
blur
(
img
):
k_size
=
11
bl
=
cv2
.
GaussianBlur
(
img
,(
k_size
,
k_size
),
0
)
return
torch
.
FloatTensor
(
bl
)
def
img_save
(
tensor
,
fp
,
nrow
=
8
,
padding
=
2
,
normalize
=
False
,
range
=
None
,
scale_each
=
False
,
pad_value
=
0
,
format
=
None
,
save
=
True
):
grid
=
utils
.
make_grid
(
tensor
,
nrow
=
nrow
,
padding
=
padding
,
pad_value
=
pad_value
,
normalize
=
normalize
,
scale_each
=
scale_each
)
ndarr
=
torch
.
round
(
grid
.
mul
(
255
)
.
add_
(
0.5
)
.
clamp_
(
0
,
255
)
.
permute
(
1
,
2
,
0
))
.
to
(
'cpu'
,
torch
.
uint8
)
.
numpy
()
ndarr
=
ndarr
[:,:,
0
]
if
save
:
im
=
Image
.
fromarray
(
ndarr
)
exten
=
fp
.
split
(
'.'
)[
-
1
]
if
exten
==
"png"
:
im
.
save
(
fp
,
format
=
format
)
else
:
im
.
save
(
fp
,
format
=
format
,
quality
=
100
)
#for jpg
return
ndarr
def
num_params
(
model
):
return
sum
(
dict
((
p
.
data_ptr
(),
p
.
numel
())
for
p
in
model
.
parameters
())
.
values
())
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment