Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
platy-browser-data
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
Container Registry
Model registry
Operate
Environments
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
Christian Tischer
platy-browser-data
Commits
66bdc9bb
Commit
66bdc9bb
authored
5 years ago
by
Constantin Pape
Browse files
Options
Downloads
Patches
Plain Diff
Use proper scale factors in export_segmentation
parent
a49fb421
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitignore
+1
-0
1 addition, 0 deletions
.gitignore
scripts/export/export_segmentation.py
+23
-13
23 additions, 13 deletions
scripts/export/export_segmentation.py
scripts/export/to_bdv.py
+1
-1
1 addition, 1 deletion
scripts/export/to_bdv.py
with
25 additions
and
14 deletions
.gitignore
+
1
−
0
View file @
66bdc9bb
...
...
@@ -4,3 +4,4 @@ tmp*
*.DS_Store
data/dev-*
*.tif
*.swp
This diff is collapsed.
Click to expand it.
scripts/export/export_segmentation.py
+
23
−
13
View file @
66bdc9bb
...
...
@@ -5,23 +5,30 @@ import z5py
from
cluster_tools.downscaling
import
DownscalingWorkflow
from
paintera_tools
import
serialize_from_commit
,
postprocess
from
paintera_tools
import
set_default_shebang
as
set_ptools_shebang
from
.to_bdv
import
to_bdv
from
.map_segmentation_ids
import
map_segmentation_ids
from
..default_config
import
write_default_global_config
from
..default_config
import
write_default_global_config
,
get_default_shebang
from
..files
import
get_postprocess_dict
def
get_
n_
scales
(
paintera_path
,
paintera_key
):
def
get_scale
_factor
s
(
paintera_path
,
paintera_key
):
f
=
z5py
.
File
(
paintera_path
)
g
=
f
[
paintera_key
][
'
data
'
]
keys
=
list
(
g
.
keys
())
scales
=
[
key
for
key
in
keys
if
os
.
path
.
isdir
(
os
.
path
.
join
(
g
.
path
,
key
))
and
key
.
startswith
(
'
s
'
)]
return
len
(
scales
)
keys
=
[
int
(
k
[
1
:])
for
k
in
g
.
keys
()]
keys
=
sorted
(
keys
)
scale_factors
=
[[
1
,
1
,
1
]]
rel_scales
=
[[
1
,
1
,
1
]]
for
k
in
keys
[
1
:]:
factor
=
g
[
'
s%i
'
%
k
].
attrs
[
'
downsamplingFactors
'
]
rel_factor
=
[
int
(
sf
//
prev
)
for
sf
,
prev
in
zip
(
factor
,
scale_factors
[
-
1
])]
scale_factors
.
append
(
factor
)
rel_scales
.
append
(
rel_factor
[::
-
1
])
return
rel_scales
def
downscale
(
path
,
in_key
,
out_key
,
n_
scales
,
tmp_folder
,
max_jobs
,
target
):
scale
_factor
s
,
tmp_folder
,
max_jobs
,
target
):
task
=
DownscalingWorkflow
config_folder
=
os
.
path
.
join
(
tmp_folder
,
'
configs
'
)
...
...
@@ -34,15 +41,14 @@ def downscale(path, in_key, out_key,
with
open
(
os
.
path
.
join
(
config_folder
,
'
downscaling.config
'
),
'
w
'
)
as
f
:
json
.
dump
(
config
,
f
)
# for now we hard-code scale factors to 2, but it would be cleaner to infer this from the data
scales
=
[[
2
,
2
,
2
]]
*
n_scales
n_scales
=
len
(
scale_factors
)
halos
=
[[
0
,
0
,
0
]]
*
n_scales
t
=
task
(
tmp_folder
=
tmp_folder
,
config_dir
=
config_folder
,
target
=
target
,
max_jobs
=
max_jobs
,
input_path
=
path
,
input_key
=
in_key
,
output_key_prefix
=
out_key
,
scale_factors
=
scales
,
halos
=
halos
)
scale_factors
=
scale
_factor
s
,
halos
=
halos
)
ret
=
luigi
.
build
([
t
],
local_scheduler
=
True
)
if
not
ret
:
raise
RuntimeError
(
"
Downscaling the segmentation failed
"
)
...
...
@@ -85,13 +91,17 @@ def export_segmentation(paintera_path, paintera_key, folder, new_folder, name, r
n_threads
=
16
,
size_threshold
=
min_segment_size
,
label
=
label_segmentation
)
# set correct shebang for paintera tools
set_ptools_shebang
(
get_default_shebang
())
# NOTE map_to_background is needed for cilia, nee some way to enable it automatically
# export segmentation from paintera commit for all scales
serialize_from_commit
(
paintera_path
,
paintera_key
,
tmp_path
,
tmp_key0
,
tmp_folder
,
max_jobs
,
target
,
relabel_output
=
True
)
max_jobs
,
target
,
relabel_output
=
True
)
# , map_to_background=[1])
# downscale the segemntation
n_
scales
=
get_
n_
scales
(
paintera_path
,
paintera_key
)
downscale
(
tmp_path
,
tmp_key0
,
tmp_key
,
n_
scales
,
tmp_folder
,
max_jobs
,
target
)
scale
_factor
s
=
get_scale
_factor
s
(
paintera_path
,
paintera_key
)
downscale
(
tmp_path
,
tmp_key0
,
tmp_key
,
scale
_factor
s
,
tmp_folder
,
max_jobs
,
target
)
# convert to bdv
out_path
=
os
.
path
.
join
(
new_folder
,
'
segmentations
'
,
'
%s.h5
'
%
name
)
...
...
This diff is collapsed.
Click to expand it.
scripts/export/to_bdv.py
+
1
−
1
View file @
66bdc9bb
...
...
@@ -28,7 +28,7 @@ def to_bdv(in_path, in_key, out_path, resolution, tmp_folder, target='slurm'):
configs
=
PainteraToBdvWorkflow
.
get_config
()
config
=
configs
[
'
copy_volume
'
]
config
.
update
({
'
threads_per_job
'
:
8
,
'
mem_limit
'
:
32
,
'
time_limit
'
:
16
00
,
config
.
update
({
'
threads_per_job
'
:
32
,
'
mem_limit
'
:
64
,
'
time_limit
'
:
24
00
,
'
chunks
'
:
[
32
,
256
,
256
]})
with
open
(
os
.
path
.
join
(
config_folder
,
'
copy_volume.config
'
),
'
w
'
)
as
f
:
json
.
dump
(
config
,
f
)
...
...
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