Commit 3c32cc78 authored by Philipp Schubert's avatar Philipp Schubert
Browse files

added sem. segm. example for compartment prediction (examples/semseg_axon.py),...

added sem. segm. example for compartment prediction (examples/semseg_axon.py), fixed order mis-match between ssd.ssv_ids and arrays loaded from ssd.load_cached_data(..), updated docs
parent e6dd1bdd
......@@ -5,20 +5,21 @@ Refactored version of SyConn for automated synaptic connectivity inference based
see below or checkout the branch [dorkenwald2017nm](https://github.com/StructuralNeurobiologyLab/SyConn/tree/dorkenwald2017nm).
Current features:
- introduction of supervoxel and agglomerated supervoxel classes
- added support for (sub-) cellular compartment (spines, axon/dendrite/soma) and cell type classification with skeleton- [\[1\]](https://www.nature.com/articles/nmeth.4206) and multiview-based [\[2\]](https://www.nature.com/articles/s41467-019-10836-3) approaches
- cell organelle prediction, extraction and mesh generation
- object-oriented handler for supervoxels (e.g. cell fragments, predicted cellular organelles like mitochondria, vesicle clouds etc.)
- prediction of subcellular structures, supervoxel extraction and mesh generation
- (sub-) cellular compartment (spines, bouton and axon/dendrite/soma) and cell type classification with multiview- [\[2\]](https://www.nature.com/articles/s41467-019-10836-3) and with skeleton-based approaches [\[1\]](https://www.nature.com/articles/nmeth.4206)
- glia identification and separation [\[2\]](https://www.nature.com/articles/s41467-019-10836-3)
- generation of connectivity matrix
- connectivity matrix export
- KNOSSOS plugin for interactive exploration (work in progress)
If you use parts of this code base in your academic projects, please cite the corresponding publication.
If you use parts of this code base in your academic projects, please cite the corresponding publication(s).
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/).
For SyConn v1, please refer to 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
......@@ -35,8 +36,8 @@ The original code snippet (under the Apache License 2.0) used for our project ca
[here](https://github.com/deepmind/dm_control/blob/30069ac11b60ee71acbd9159547d0bc334d63281/dm_control/_render/pyopengl/egl_ext.py).
References
----------
Publications
------------
\[1\] [Automated synaptic connectivity inference for volume electron microscopy](https://www.nature.com/articles/nmeth.4206)
```
@ARTICLE{SyConn2017,
......
from syconn.reps.super_segmentation import *
from syconn.reps.super_segmentation_helper import semseg_of_sso_nocache
from syconn.proc.ssd_assembly import init_sso_from_kzip
from syconn.handler.prediction import get_semseg_axon_model
import os
import argparse
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='SyConn example run')
parser.add_argument('--working_dir', type=str,
default=os.path.expanduser("~/SyConn/example_cube1/"),
help='Working directory of SyConn')
parser.add_argument('--kzip', type=str, default='',
help='path to kzip file which contains a cell reconstruction (see '
'SuperSegmentationObject().export2kzip())')
args = parser.parse_args()
# path to working directory of example cube - required to load pretrained models
path_to_workingdir = os.path.expanduser(args.working_dir)
# path to cell reconstruction k.zip
cell_kzip_fn = os.path.abspath(os.path.expanduser(args.kzip))
if not os.path.isfile(cell_kzip_fn):
raise FileNotFoundError
# set working directory to obtain models
global_params.wd = path_to_workingdir
# get model for compartment detection
m = get_semseg_axon_model()
view_props = global_params.view_properties_semsegax
view_props["verbose"] = True
# load SSO instance from k.zip file
sso = init_sso_from_kzip(cell_kzip_fn, sso_id=1)
# run prediction and store result in new kzip
cell_kzip_fn_axon = cell_kzip_fn[:-6] + '_axon.k.zip'
semseg_of_sso_nocache(sso, dest_path=cell_kzip_fn_axon, model=m,
**view_props)
......@@ -21,8 +21,9 @@ if __name__ == '__main__':
path_to_workingdir = os.path.expanduser(args.working_dir)
# path to cell reconstruction k.zip
cell_kzip_fn = os.path.expanduser(args.kzip)
cell_kzip_fn = os.path.abspath(os.path.expanduser(args.kzip))
if not os.path.isfile(cell_kzip_fn):
raise FileNotFoundError
# set working directory to obtain models
global_params.wd = path_to_workingdir
......@@ -30,10 +31,11 @@ if __name__ == '__main__':
m = get_semseg_spiness_model()
# load SSO instance from k.zip file
sso = init_sso_from_kzip(cell_kzip_fn)
sso = init_sso_from_kzip(cell_kzip_fn, sso_id=1)
# run prediction and store result in new kzip
cell_kzip_fn_spines = cell_kzip_fn[:-6] + '_spines.k.zip'
semseg_of_sso_nocache(sso, dest_path=cell_kzip_fn_spines, semseg_key="spinesstest", n_avg=5,
ws=(256, 128), model=m, nb_views=2, comp_window=8e3, verbose=True)
semseg_of_sso_nocache(sso, dest_path=cell_kzip_fn_spines, verbose=True,
semseg_key="spinesstest", n_avg=5, ws=(256, 128),
model=m, nb_views=2, comp_window=8e3)
......@@ -927,6 +927,9 @@ def int2str_label_converter(label, gt_type):
l_dc_inv = dict(STN=0, DA=1, MSN=2, LMAN=3, HVC=4, GP=5, FS=6, TAN=7)
l_dc_inv["?"] = 8
l_dc = {v: k for k, v in l_dc_inv.items()}
# Do not distinguish between FS and INT/?
l_dc[8] = "INT"
l_dc[6] = "INT"
try:
return l_dc[label]
except KeyError:
......
......@@ -191,6 +191,9 @@ def int2str_converter(label, gt_type):
l_dc_inv = dict(STN=0, DA=1, MSN=2, LMAN=3, HVC=4, GP=5, FS=6, TAN=7)
l_dc_inv["?"] = 8
l_dc = {v: k for k, v in l_dc_inv.items()}
# Do not distinguish between FS and INT/?
l_dc[8] = "INT"
l_dc[6] = "INT"
try:
return l_dc[label]
except KeyError:
......
......@@ -215,13 +215,16 @@ class SuperSegmentationDataset(object):
@property
def ssv_ids(self):
if self._ssv_ids is None:
if len(self.mapping_dict) > 0:
# do not change the order of the if statements as it is crucial
# for the resulting ordering of self.ssv_ids (only ids.npy matches
# with all the other cached numpy arrays).
if os.path.exists(self.path + "/ids.npy"):
self._ssv_ids = np.load(self.path + "/ids.npy")
elif len(self.mapping_dict) > 0:
self._ssv_ids = np.array(list(self.mapping_dict.keys()))
elif self.mapping_dict_exists:
self.load_mapping_dict()
self._ssv_ids = np.array(list(self.mapping_dict.keys()))
elif os.path.exists(self.path + "/ids.npy"):
self._ssv_ids = np.load(self.path + "/ids.npy")
else:
paths = glob.glob(self.path + "/so_storage/*/*/*/")
self._ssv_ids = np.array([int(os.path.basename(p.strip("/")))
......@@ -250,6 +253,7 @@ class SuperSegmentationDataset(object):
return self._id_changer
def load_cached_data(self, name):
# TODO: remove this 's' concept
if os.path.exists(self.path + name + "s.npy"):
return np.load(self.path + name + "s.npy", allow_pickle=True)
......
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