Commit a3019de0 authored by Philipp's avatar Philipp
Browse files

parameter adjustments, code refinements and bug fixes

parent 8fae7289
......@@ -13,25 +13,31 @@ Current features:
If you use parts of this code base in your academic projects, please cite the corresponding publication.
Documentation
--------------
To get started, please have a look at our [documentation](https://structuralneurobiologylab.github.io/SyConn/documentation/), but be aware that it is currently outdated and applies only to SyConn v1. We also present more general information about SyConn on our [Website](https://structuralneurobiologylab.github.io/SyConn/).
Documentation
-------------
The documentation for the refactored version is still work-in-progress and can be found [here](docs/doc.md). Alternatively see the latest [readthedocs build](https://syconn.readthedocs.io/en/latest/).
For SyConn v1, please have a look at the old [documentation](https://structuralneurobiologylab.github.io/SyConn/documentation/). We also present more general information about SyConn on our [Website](https://structuralneurobiologylab.github.io/SyConn/).
# The Team
The Team
--------
The Synaptic connectivity inference toolkit is developed at the Max-Planck-Institute of Neurobiology in Martinsried by
Philipp Schubert, Maria Kawula, Carl Constantin v. Wedemeyer, Atul Mohite, Gaurav Kumar and Joergen Kornfeld.
# Acknowledgements
We thank deepmind for providing egl extension code to handle multi-gpu rendering on the same machine, which is under the Apache License 2.0. The original code snippet used in our
project can be found [here](https://github.com/deepmind/dm_control/blob/30069ac11b60ee71acbd9159547d0bc334d63281/dm_control/_render/pyopengl/egl_ext.py).
Acknowledgements
----------------
We are especially grateful for the support by Winfried Denk who enabled this work in his department. We also want to thank Christian Guggenberger
and his group at the MPCDF for cluster support and deepmind for providing egl extension code to handle multi-gpu rendering on the same machine.
The original code snippet (under the Apache License 2.0) used for our project can be found
[here](https://github.com/deepmind/dm_control/blob/30069ac11b60ee71acbd9159547d0bc334d63281/dm_control/_render/pyopengl/egl_ext.py).
# References
\[1\] [Automated synaptic connectivity inference for volume electron microscopy][https://www.nature.com/articles/nmeth.4206]
References
----------
\[1\] [Automated synaptic connectivity inference for volume electron microscopy](https://www.nature.com/articles/nmeth.4206)
```
@ARTICLE{SyConn2017,
title = "Automated synaptic connectivity inference for volume electron
......@@ -53,7 +59,7 @@ We thank deepmind for providing egl extension code to handle multi-gpu rendering
```
\[2\] [Learning cellular morphology with neural networks][https://doi.org/10.1038/s41467-019-10836-3]
\[2\] [Learning cellular morphology with neural networks](https://doi.org/10.1038/s41467-019-10836-3)
```
@Article{Schubert2019,
author={Schubert, Philipp J.
......@@ -67,7 +73,15 @@ year={2019},
volume={10},
number={1},
pages={2736},
abstract={Reconstruction and annotation of volume electron microscopy data sets of brain tissue is challenging but can reveal invaluable information about neuronal circuits. Significant progress has recently been made in automated neuron reconstruction as well as automated detection of synapses. However, methods for automating the morphological analysis of nanometer-resolution reconstructions are less established, despite the diversity of possible applications. Here, we introduce cellular morphology neural networks (CMNs), based on multi-view projections sampled from automatically reconstructed cellular fragments of arbitrary size and shape. Using unsupervised training, we infer morphology embeddings (Neuron2vec) of neuron reconstructions and train CMNs to identify glia cells in a supervised classification paradigm, which are then used to resolve neuron reconstruction errors. Finally, we demonstrate that CMNs can be used to identify subcellular compartments and the cell types of neuron reconstructions.},
abstract={Reconstruction and annotation of volume electron microscopy data sets of brain tissue is challenging but
can reveal invaluable information about neuronal circuits. Significant progress has recently been made in automated
neuron reconstruction as well as automated detection of synapses. However, methods for automating the morphological
analysis of nanometer-resolution reconstructions are less established, despite the diversity of possible applications.
Here, we introduce cellular morphology neural networks (CMNs), based on multi-view projections sampled from automatically
reconstructed cellular fragments of arbitrary size and shape. Using unsupervised training, we infer morphology embeddings
(Neuron2vec) of neuron reconstructions and train CMNs to identify glia cells in a supervised classification paradigm,
which are then used to resolve neuron reconstruction errors. Finally, we demonstrate that CMNs can be used to identify
subcellular compartments and the cell types of neuron reconstructions.},
issn={2041-1723},
doi={10.1038/s41467-019-10836-3},
url={https://doi.org/10.1038/s41467-019-10836-3}
......
......@@ -186,6 +186,7 @@ if __name__ == '__main__':
time_stamps.append(time.time())
step_idents.append('SSD generation')
# TODO: launch steps 3 and 4 in parallel
log.info('Step 3/8 - Neuron rendering')
exec_multiview.run_neuron_rendering()
time_stamps.append(time.time())
......
......@@ -297,16 +297,16 @@ if __name__ == "__main__":
# axoness
if 1:
initial_run = False
initial_run = True
ws = (1024, 512)
comp_window = 40.96e3 * 1.5 # ~60nm pixel size
n_views = 6 # increase views per location due to higher pixel size, also increases GT
# diversity
dest_gt_dir = "/wholebrain/scratch/areaxfs3/ssv_semsegaxoness/gt_h5_files_60nm_{" \
"}/".format(ws[0])
# # Process original data
# dest_gt_dir = "/wholebrain/scratch/areaxfs3/ssv_semsegaxoness/gt_h5_files_80nm_{" \
# "}/".format(ws[0])
# global_params.wd = "/wholebrain/scratch/areaxfs3/"
# assert global_params.wd == "/wholebrain/scratch/areaxfs3/"
# label_file_folder = "/wholebrain/scratch/areaxfs3/ssv_semsegaxoness" \
......@@ -331,14 +331,23 @@ if __name__ == "__main__":
# GT_generation(file_paths, 'semsegaxoness', 'axgt', n_views, dest_dir=dest_gt_dir,
# ws=ws, comp_window=40.96e3*2, n_voting=0) # disable BFS smoothing on vertices (probalby not needed on cell compartment level)
# bouton GT
dest_gt_dir = "/wholebrain/scratch/areaxfs3/ssv_semsegaxoness/gt_h5_files_80nm_{" \
"}_with_BOUTONS/".format(ws[0])
global_params.wd = "/wholebrain/scratch/areaxfs3/"
assert global_params.wd == "/wholebrain/scratch/areaxfs3/"
# # bouton GT
# # BATCH 1
dest_gt_dir = "/wholebrain/scratch/areaxfs3/ssv_semsegaxoness/gt_h5_files_60nm_{" \
"}_with_BOUTONS_v2/".format(ws[0])
# global_params.wd = "/wholebrain/scratch/areaxfs3/"
# assert global_params.wd == "/wholebrain/scratch/areaxfs3/"
# label_file_folder = "/wholebrain/scratch/areaxfs3/ssv_semsegaxoness" \
# "/gt_axoness_semseg_skeletons/NEW_including_boutons/batch1_results/"
# file_paths = glob.glob(label_file_folder + '*.k.zip', recursive=False)
# GT_generation(file_paths, 'semsegaxoness', 'axgt', n_views, dest_dir=dest_gt_dir,
# ws=ws, comp_window=comp_window, n_voting=0) # disable BFS smoothing on
# # vertices (probalby not needed on cell compartment level)
global_params.wd = "/wholebrain/songbird/j0126/areaxfs_v6/"
assert global_params.wd == "/wholebrain/songbird/j0126/areaxfs_v6/"
label_file_folder = "/wholebrain/scratch/areaxfs3/ssv_semsegaxoness" \
"/gt_axoness_semseg_skeletons/NEW_including_boutons/batch1_results/"
"/gt_axoness_semseg_skeletons/NEW_including_boutons/batch2_results/"
file_paths = glob.glob(label_file_folder + '*.k.zip', recursive=False)
GT_generation(file_paths, 'semsegaxoness', 'axgt', n_views, dest_dir=dest_gt_dir,
ws=ws, comp_window=comp_window, n_voting=0) # disable BFS smoothing on
# vertices (probalby not needed on cell compartment level)
......@@ -37,12 +37,14 @@ for ix in ssv_ixs:
continue
# background label is 5 -> unpredicted is background_label + 1 = 6, average over 50 nearest
# vertex predictions
print(ix, len(sso.skeleton['nodes']), len(sso.mesh[1].reshape((-1, 3))))
node_preds = sso.semseg_for_coords(sso.skeleton['nodes'],
semseg_key=global_params.view_properties_semsegax['semseg_key'],
**map_properties)
pred_key = "axoness{}_k{}".format(pred_key_appendix, map_properties['k'])
sso.skeleton[pred_key] = node_preds
# this will save sso.skeleton, -> also saves `sso.skeleton[pred_key]`
# TODO: perform this only on 0, 1, 2 -> axon, dendrite and soma, not on bouton predictions
majority_vote_compartments(sso, pred_key)
......
......@@ -47,12 +47,11 @@ for ssv_ix in ch:
# locking is explicitly enabled when saving SV views, no need to enable it for reading data
sso = SuperSegmentationObject(ssv_ix, working_dir=wd,
enable_locking_so=False)
if len(sso.sample_locations()) > 1e3:
if len(sso.sample_locations()) > 1e3: # TODO: add as parameter to global_params.py
ssvs_large.append(sso)
else:
ssvs_small.append(sso)
# that
# this job is always started using half of the node and with one GPU
for ssv in ssvs_large:
render_sso_coords_multiprocessing(ssv, wd, n_parallel_jobs,
......
......@@ -50,8 +50,7 @@ for g in ch:
new_G.add_edge(sso.get_seg_obj("sv", e[0]),
sso.get_seg_obj("sv", e[1]))
sso._rag = new_G
if len(sso.sample_locations()) > np.inf: # TODO: adapt as soon as
# `render_sso_coords_multiprocessing` has correct sorting of returned views
if len(sso.sample_locations()) > 1e3: # TODO: add as parameter to global_params.py
ssvs_large.append(sso)
else:
ssvs_small.append(sso)
......
......@@ -117,11 +117,11 @@ gt_path_spineseg = '/wholebrain/scratch/areaxfs3/ssv_spgt/spgt_semseg/' # TODO:
# --------- COMPARTMENT PARAMETERS
DIST_AXONESS_AVERAGING = 10000
gt_path_axonseg = '/wholebrain/scratch/areaxfs3/ssv_semsegaxoness' \
'/gt_h5_files_80nm_1024_with_BOUTONS/' # TODO: add to config
'/all_bouton_data/' # TODO: add to config
view_properties_semsegax = dict(verbose=False, ws=(1024, 512), nb_views=3,
comp_window=40.96e3 * 1.5, semseg_key='axoness',
n_avg=0) # this will not map predictions to unpredicted vertices
map_properties_semsegax = dict(k=50, ds_vertices=10, ignore_labels=[6])
map_properties_semsegax = dict(k=50, ds_vertices=2, ignore_labels=[5, 6])
# --------- CELLTYPE PARAMETERS
......
......@@ -448,6 +448,7 @@ __many__ = string
[Paths]
__many__ = string
use_new_subfold = boolean
[Dataset]
scaling = float_list(min=3, max=3)
......
......@@ -621,7 +621,7 @@ def fallback_exec(cmd_exec):
reported = False
if 'error' in out.decode().lower() or \
'error' in err.decode().lower() or 'killed' in\
out.decode().lower() or 'killed' in err.decode.lower():
out.decode().lower() or 'killed' in err.decode().lower():
log_mp.error(out.decode())
log_mp.error(err.decode())
reported = True
......
......@@ -28,7 +28,6 @@ def qsub_glia_splitting():
glia SVs
"""
cc_dict = load_pkl2obj(global_params.config.working_dir + "/glia/cc_dict_rag_graphs.pkl")
print("LAIHGONLEGD" + str(1183536 in cc_dict))
huge_ssvs = [it[0] for it in cc_dict.items() if len(it[1]) > RENDERING_MAX_NB_SV]
if len(huge_ssvs):
log_proc.info("{} huge SSVs detected (#SVs > {})".format(len(huge_ssvs),
......
......@@ -1276,6 +1276,7 @@ def render_sso_coords_multiprocessing(ssv, wd, n_jobs, n_cores=1, rendering_loca
views = np.concatenate(views)
shutil.rmtree(os.path.abspath(path_to_out + "/../"), ignore_errors=True)
if svs is not None and return_views is False:
start_writing = time.time()
if render_kwargs_def['cellobjects_only']:
log_proc.warning('`cellobjects_only=True` in `render_sampled_sso` call, views '
'will be written to file system in serial (this is slow).')
......@@ -1290,7 +1291,9 @@ def render_sso_coords_multiprocessing(ssv, wd, n_jobs, n_cores=1, rendering_loca
dict(woglia=render_kwargs_def['woglia'],
index_views=render_kwargs_def["render_indexviews"],
view_key=view_key))
end_writing = time.time()
log_proc.debug('Writing SV renderings took {:.2f}s'.format(
end_writing - start_writing))
return
return views
......
......@@ -325,6 +325,8 @@ def colorcode_vertices(vertices, rep_coords, rep_values, colors=None,
log_reps.error(msg)
raise ValueError(msg)
hull_tree = spatial.cKDTree(rep_coords)
if k > len(rep_coords):
k = rep_coords
dists, ixs = hull_tree.query(vertices, n_jobs=nb_cpus, k=k)
hull_rep = np.zeros((len(vertices)), dtype=np.int)
for i in range(len(ixs)):
......
......@@ -23,8 +23,12 @@ def glia_pred_so(so, thresh, pred_key_appendix):
pred_key = "glia_probas" + pred_key_appendix
if not pred_key in so.attr_dict:
so.load_attr_dict()
preds = np.array(so.attr_dict[pred_key][:, 1] > thresh, dtype=np.int)
pred = np.mean(so.attr_dict[pred_key][:, 1]) > thresh
try:
preds = np.array(so.attr_dict[pred_key][:, 1] > thresh, dtype=np.int)
pred = np.mean(so.attr_dict[pred_key][:, 1]) > thresh
except KeyError:
raise KeyError('Could not find glia proba key `{}` in so,attr_dict (keys: {})'.format(
pred_key, so.attr_dict.keys()))
if pred == 0:
return 0
glia_votes = np.sum(preds)
......
......@@ -1633,8 +1633,11 @@ class SuperSegmentationObject(object):
if ignore_labels is None:
ignore_labels = []
coords = np.array(coords) * self.scaling
vertices = self.mesh[1].reshape((-1, 3))
if len(vertices) < 5e6:
ds_vertices = max(1, ds_vertices // 10)
vertex_labels = self.label_dict('vertex')[semseg_key][::ds_vertices]
vertices = self.mesh[1].reshape((-1, 3))[::ds_vertices]
vertices = vertices[::ds_vertices]
for ign_l in ignore_labels:
vertices = vertices[vertex_labels != ign_l]
vertex_labels = vertex_labels[vertex_labels != ign_l]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment