Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
deepdraw
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
Model registry
Operate
Environments
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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
medai
software
deepdraw
Commits
a15d2d27
Commit
a15d2d27
authored
4 years ago
by
André Anjos
Browse files
Options
Downloads
Patches
Plain Diff
[engine.evaluator] Fix function to calculate patch performance
parent
c9d5d42c
No related branches found
No related tags found
No related merge requests found
Pipeline
#40754
failed
4 years ago
Stage: build
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bob/ip/binseg/engine/evaluator.py
+28
-7
28 additions, 7 deletions
bob/ip/binseg/engine/evaluator.py
with
28 additions
and
7 deletions
bob/ip/binseg/engine/evaluator.py
+
28
−
7
View file @
a15d2d27
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
"""
Defines functionality for the evaluation of predictions
"""
"""
Defines functionality for the evaluation of predictions
"""
import
os
import
os
import
itertools
import
PIL
import
PIL
import
numpy
import
numpy
...
@@ -11,6 +12,7 @@ import pandas
...
@@ -11,6 +12,7 @@ import pandas
from
tqdm
import
tqdm
from
tqdm
import
tqdm
import
torch
import
torch
import
torch.nn.functional
import
torchvision.transforms.functional
as
VF
import
torchvision.transforms.functional
as
VF
import
h5py
import
h5py
...
@@ -184,13 +186,32 @@ def _patch_measures(pred, gt, steps, size):
...
@@ -184,13 +186,32 @@ def _patch_measures(pred, gt, steps, size):
"""
"""
height
,
width
,
stride
=
window_size
height
,
width
,
stride
=
size
pred_patches
=
pred
.
unfold
(
0
,
height
,
stride
).
unfold
(
1
,
width
,
stride
)
gt_patches
=
unfold
(
0
,
height
,
stride
).
unfold
(
1
,
width
,
stride
)
# we calculate the required padding so that the last windows on the left
# and bottom size of predictions/ground-truth data are zero padded, and
# add patch number for each set of measures
# torch unfolding works exactly.
dfs
=
[
_sample_measures
(
p
,
g
,
step
)
for
p
,
g
in
zip
(
pred_patches
,
gt_patches
)]
padding
=
(
0
,
0
)
for
i
,
k
in
enumerate
(
dfs
):
k
[
'
patch
'
]
=
i
rem
=
(
pred
.
shape
[
1
]
-
width
)
%
stride
if
rem
!=
0
:
padding
=
(
0
,
(
stride
-
rem
))
rem
=
(
pred
.
shape
[
0
]
-
height
)
%
stride
if
rem
!=
0
:
padding
+=
(
0
,
(
stride
-
rem
))
pred_padded
=
torch
.
nn
.
functional
.
pad
(
pred
,
padding
)
gt_padded
=
torch
.
nn
.
functional
.
pad
(
gt
.
squeeze
(
0
),
padding
)
# this will create as many views as required
pred_patches
=
pred_padded
.
unfold
(
0
,
height
,
stride
).
unfold
(
1
,
width
,
stride
)
gt_patches
=
gt_padded
.
unfold
(
0
,
height
,
stride
).
unfold
(
1
,
width
,
stride
)
assert
pred_patches
.
shape
==
gt_patches
.
shape
ylen
,
xlen
,
_
,
_
=
pred_patches
.
shape
dfs
=
[]
for
j
,
i
in
itertools
.
product
(
range
(
ylen
),
range
(
xlen
)):
dfs
.
append
(
_sample_measures
(
pred_patches
[
j
,
i
,:,:],
gt_patches
[
j
,
i
,:,:],
steps
))
dfs
[
-
1
][
'
patch
'
]
=
i
+
(
j
*
xlen
)
return
pandas
.
concat
(
dfs
,
ignore_index
=
True
)
return
pandas
.
concat
(
dfs
,
ignore_index
=
True
)
...
...
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