Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SVLT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
ALMF
SVLT
Commits
b4693d69
Commit
b4693d69
authored
8 months ago
by
Christopher Randolph Rhodes
Browse files
Options
Downloads
Patches
Plain Diff
Renamed dataframe maker and moved derivative dataframe columns into separate method
parent
3bf6161c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
model_server/base/roiset.py
+48
-44
48 additions, 44 deletions
model_server/base/roiset.py
tests/base/test_roiset.py
+0
-1
0 additions, 1 deletion
tests/base/test_roiset.py
with
48 additions
and
45 deletions
model_server/base/roiset.py
+
48
−
44
View file @
b4693d69
...
@@ -129,6 +129,51 @@ def _filter_overlap_bbox(df: pd.DataFrame) -> pd.DataFrame:
...
@@ -129,6 +129,51 @@ def _filter_overlap_bbox(df: pd.DataFrame) -> pd.DataFrame:
return
sdf
return
sdf
def
_df_insert_slices
(
df
:
pd
.
DataFrame
,
shape
:
tuple
,
expand_box_by
)
->
pd
.
DataFrame
:
h
,
w
,
c
,
nz
=
shape
df
[
'
h
'
]
=
df
[
'
y1
'
]
-
df
[
'
y0
'
]
df
[
'
w
'
]
=
df
[
'
x1
'
]
-
df
[
'
x0
'
]
ebxy
,
ebz
=
expand_box_by
df
[
'
ebb_y0
'
]
=
(
df
.
y0
-
ebxy
).
apply
(
lambda
x
:
max
(
x
,
0
))
df
[
'
ebb_y1
'
]
=
(
df
.
y1
+
ebxy
).
apply
(
lambda
x
:
min
(
x
,
h
))
df
[
'
ebb_x0
'
]
=
(
df
.
x0
-
ebxy
).
apply
(
lambda
x
:
max
(
x
,
0
))
df
[
'
ebb_x1
'
]
=
(
df
.
x1
+
ebxy
).
apply
(
lambda
x
:
min
(
x
,
w
))
df
[
'
ebb_z0
'
]
=
(
df
.
zi
-
ebz
).
apply
(
lambda
x
:
max
(
x
,
0
))
df
[
'
ebb_z1
'
]
=
(
df
.
zi
+
ebz
).
apply
(
lambda
x
:
min
(
x
,
nz
))
df
[
'
ebb_h
'
]
=
df
[
'
ebb_y1
'
]
-
df
[
'
ebb_y0
'
]
df
[
'
ebb_w
'
]
=
df
[
'
ebb_x1
'
]
-
df
[
'
ebb_x0
'
]
df
[
'
ebb_nz
'
]
=
df
[
'
ebb_z1
'
]
-
df
[
'
ebb_z0
'
]
+
1
# compute relative bounding boxes
df
[
'
rel_y0
'
]
=
df
.
y0
-
df
.
ebb_y0
df
[
'
rel_y1
'
]
=
df
.
y1
-
df
.
ebb_y0
df
[
'
rel_x0
'
]
=
df
.
x0
-
df
.
ebb_x0
df
[
'
rel_x1
'
]
=
df
.
x1
-
df
.
ebb_x0
assert
np
.
all
(
df
[
'
rel_x1
'
]
<=
(
df
[
'
ebb_x1
'
]
-
df
[
'
ebb_x0
'
]))
assert
np
.
all
(
df
[
'
rel_y1
'
]
<=
(
df
[
'
ebb_y1
'
]
-
df
[
'
ebb_y0
'
]))
df
[
'
slice
'
]
=
df
.
apply
(
lambda
r
:
np
.
s_
[
int
(
r
.
y0
):
int
(
r
.
y1
),
int
(
r
.
x0
):
int
(
r
.
x1
),
:,
int
(
r
.
zi
):
int
(
r
.
zi
+
1
)],
axis
=
1
,
result_type
=
'
reduce
'
,
)
df
[
'
expanded_slice
'
]
=
df
.
apply
(
lambda
r
:
np
.
s_
[
int
(
r
.
ebb_y0
):
int
(
r
.
ebb_y1
),
int
(
r
.
ebb_x0
):
int
(
r
.
ebb_x1
),
:,
int
(
r
.
ebb_z0
):
int
(
r
.
ebb_z1
)
+
1
],
axis
=
1
,
result_type
=
'
reduce
'
,
)
df
[
'
relative_slice
'
]
=
df
.
apply
(
lambda
r
:
np
.
s_
[
int
(
r
.
rel_y0
):
int
(
r
.
rel_y1
),
int
(
r
.
rel_x0
):
int
(
r
.
rel_x1
),
:,
:],
axis
=
1
,
result_type
=
'
reduce
'
,
)
return
df
def
_safe_add
(
a
,
g
,
b
):
def
_safe_add
(
a
,
g
,
b
):
assert
a
.
dtype
==
b
.
dtype
assert
a
.
dtype
==
b
.
dtype
assert
a
.
shape
==
b
.
shape
assert
a
.
shape
==
b
.
shape
...
@@ -165,7 +210,7 @@ class RoiSet(object):
...
@@ -165,7 +210,7 @@ class RoiSet(object):
self
.
params
=
params
self
.
params
=
params
self
.
_df
=
self
.
filter_df
(
self
.
_df
=
self
.
filter_df
(
self
.
make_df
(
self
.
make_df
_from_object_ids
(
self
.
acc_raw
,
self
.
acc_obj_ids
,
expand_box_by
=
params
.
expand_box_by
self
.
acc_raw
,
self
.
acc_obj_ids
,
expand_box_by
=
params
.
expand_box_by
),
),
params
.
filters
,
params
.
filters
,
...
@@ -203,7 +248,7 @@ class RoiSet(object):
...
@@ -203,7 +248,7 @@ class RoiSet(object):
# call e.g. static adder
# call e.g. static adder
@staticmethod
@staticmethod
def
make_df
(
acc_raw
,
acc_obj_ids
,
expand_box_by
)
->
pd
.
DataFrame
:
def
make_df
_from_object_ids
(
acc_raw
,
acc_obj_ids
,
expand_box_by
)
->
pd
.
DataFrame
:
"""
"""
Build dataframe associate object IDs with summary stats
Build dataframe associate object IDs with summary stats
:param acc_raw: accessor to raw image data
:param acc_raw: accessor to raw image data
...
@@ -231,48 +276,7 @@ class RoiSet(object):
...
@@ -231,48 +276,7 @@ class RoiSet(object):
})
})
df
[
'
zi
'
]
=
df
[
'
label
'
].
apply
(
lambda
x
:
(
acc_obj_ids
.
data
==
x
).
sum
(
axis
=
(
0
,
1
,
2
)).
argmax
())
df
[
'
zi
'
]
=
df
[
'
label
'
].
apply
(
lambda
x
:
(
acc_obj_ids
.
data
==
x
).
sum
(
axis
=
(
0
,
1
,
2
)).
argmax
())
# compute expanded bounding boxes
df
=
_df_insert_slices
(
df
,
acc_raw
.
shape
,
expand_box_by
)
h
,
w
,
c
,
nz
=
acc_raw
.
shape
df
[
'
h
'
]
=
df
[
'
y1
'
]
-
df
[
'
y0
'
]
df
[
'
w
'
]
=
df
[
'
x1
'
]
-
df
[
'
x0
'
]
ebxy
,
ebz
=
expand_box_by
df
[
'
ebb_y0
'
]
=
(
df
.
y0
-
ebxy
).
apply
(
lambda
x
:
max
(
x
,
0
))
df
[
'
ebb_y1
'
]
=
(
df
.
y1
+
ebxy
).
apply
(
lambda
x
:
min
(
x
,
h
))
df
[
'
ebb_x0
'
]
=
(
df
.
x0
-
ebxy
).
apply
(
lambda
x
:
max
(
x
,
0
))
df
[
'
ebb_x1
'
]
=
(
df
.
x1
+
ebxy
).
apply
(
lambda
x
:
min
(
x
,
w
))
df
[
'
ebb_z0
'
]
=
(
df
.
zi
-
ebz
).
apply
(
lambda
x
:
max
(
x
,
0
))
df
[
'
ebb_z1
'
]
=
(
df
.
zi
+
ebz
).
apply
(
lambda
x
:
min
(
x
,
nz
))
df
[
'
ebb_h
'
]
=
df
[
'
ebb_y1
'
]
-
df
[
'
ebb_y0
'
]
df
[
'
ebb_w
'
]
=
df
[
'
ebb_x1
'
]
-
df
[
'
ebb_x0
'
]
df
[
'
ebb_nz
'
]
=
df
[
'
ebb_z1
'
]
-
df
[
'
ebb_z0
'
]
+
1
# compute relative bounding boxes
df
[
'
rel_y0
'
]
=
df
.
y0
-
df
.
ebb_y0
df
[
'
rel_y1
'
]
=
df
.
y1
-
df
.
ebb_y0
df
[
'
rel_x0
'
]
=
df
.
x0
-
df
.
ebb_x0
df
[
'
rel_x1
'
]
=
df
.
x1
-
df
.
ebb_x0
assert
np
.
all
(
df
[
'
rel_x1
'
]
<=
(
df
[
'
ebb_x1
'
]
-
df
[
'
ebb_x0
'
]))
assert
np
.
all
(
df
[
'
rel_y1
'
]
<=
(
df
[
'
ebb_y1
'
]
-
df
[
'
ebb_y0
'
]))
df
[
'
slice
'
]
=
df
.
apply
(
lambda
r
:
np
.
s_
[
int
(
r
.
y0
):
int
(
r
.
y1
),
int
(
r
.
x0
):
int
(
r
.
x1
),
:,
int
(
r
.
zi
):
int
(
r
.
zi
+
1
)],
axis
=
1
,
result_type
=
'
reduce
'
,
)
df
[
'
expanded_slice
'
]
=
df
.
apply
(
lambda
r
:
np
.
s_
[
int
(
r
.
ebb_y0
):
int
(
r
.
ebb_y1
),
int
(
r
.
ebb_x0
):
int
(
r
.
ebb_x1
),
:,
int
(
r
.
ebb_z0
):
int
(
r
.
ebb_z1
)
+
1
],
axis
=
1
,
result_type
=
'
reduce
'
,
)
df
[
'
relative_slice
'
]
=
df
.
apply
(
lambda
r
:
np
.
s_
[
int
(
r
.
rel_y0
):
int
(
r
.
rel_y1
),
int
(
r
.
rel_x0
):
int
(
r
.
rel_x1
),
:,
:],
axis
=
1
,
result_type
=
'
reduce
'
,
)
# TODO: make this contingent on whether seg is included
# TODO: make this contingent on whether seg is included
df
[
'
binary_mask
'
]
=
df
.
apply
(
df
[
'
binary_mask
'
]
=
df
.
apply
(
...
...
This diff is collapsed.
Click to expand it.
tests/base/test_roiset.py
+
0
−
1
View file @
b4693d69
...
@@ -71,7 +71,6 @@ class TestOverlapLogic(unittest.TestCase):
...
@@ -71,7 +71,6 @@ class TestOverlapLogic(unittest.TestCase):
def
test_overlap_bbox
(
self
):
def
test_overlap_bbox
(
self
):
res
=
_filter_overlap_bbox
(
self
.
df
)
res
=
_filter_overlap_bbox
(
self
.
df
)
print
(
res
)
self
.
assertEqual
(
len
(
res
),
2
)
self
.
assertEqual
(
len
(
res
),
2
)
self
.
assertTrue
((
res
.
loc
[
0
,
'
overlaps_with
'
]
==
1
).
all
())
self
.
assertTrue
((
res
.
loc
[
0
,
'
overlaps_with
'
]
==
1
).
all
())
self
.
assertTrue
((
res
.
loc
[
1
,
'
overlaps_with
'
]
==
2
).
all
())
self
.
assertTrue
((
res
.
loc
[
1
,
'
overlaps_with
'
]
==
2
).
all
())
...
...
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