Skip to main content

A python package for the segmentation of organelles in volume electron microscopy data

Project description

Volume Electron Microscopy SEGmentation

tests

A package for the segmentation of volume electron microscopy images using XGBoost.

Installation

You can install vemseg via pip:

pip install vemseg

Usage

Shown below are some example uses of the VEMClassifier and some other functionality provided by the vemseg package.

import vemseg as vem
from skimage.io import imread

X = imread("train_image.tiff")
y = imread("train_labels.tiff")
mask = imread('train_mask.tiff')

clf = vem.VEMClassifier(max_depth=4,
                         n_estimators=400,
                         learning_rate=0.01,
                         verbosity=0)

features = clf.set_features(
    ["sobel_of_gaussian_blur","laplace_box_of_gaussian_blur", "original"], 
    range(1, 4)
)

clf.fit(X, y, mask=mask)

We then use clf.predict to get the prediction from the trained classifier. We can use the show flag to generate an image of the predictions.

prediction = clf.predict(X, show=True, mask=mask)

We can then plot the features importance like so, with fig size indicating the size of the plot.

clf.feature_importance(fig_size=(20, 10))

Deciding what hyperparameters to use can often be very difficult, so we can use an adaptation of sklearns GridSearchCV to determine which hyperparameters work best.

parameters = {
    'max_depth': range(2, 5, 1),
    'n_estimators': range(200, 500, 100)
}

grid_search = clf.GridSearchCV(
    X,
    y,
    param_grid=parameters,
    n_jobs=10,
    cv=10,
    verbose=True,
    update_params=True,
    mask=mask,
)

print(grid_search.best_estimator_)

Will output

Fitting 10 folds for each of 9 candidates, totalling 90 fits
VEMClassifier(base_score=0.5, booster='gbtree', callbacks=None,
              colsample_bylevel=1, colsample_bynode=1, colsample_bytree=1,
              early_stopping_rounds=None, enable_categorical=False,
              eval_metric=None, feature_types=None, gamma=0, gpu_id=-1,
              grow_policy='depthwise', importance_type=None,
              interaction_constraints='', learning_rate=0.300000012,
              max_bin=256, max_cat_threshold=64, max_cat_to_onehot=4,
              max_delta_step=0, max_depth=3, max_leaves=0, min_child_weight=1,
              missing=nan, monotone_constraints='()', n_estimators=200,
              n_jobs=0, num_parallel_tree=1, objective='binary:logistic',
              predictor='auto', ...)

After completing training one can save the model to be reused like so.

clf.save_model('model.json')

And to reload the model from the JSON file one simply has to initialise a new VEMClassifier and then load the model.

import vemseg

pre_trained_model = vem.VEMClassifier()
pre_trained_model.load_model('model.json')

License

Distributed under the terms of the BSD-3 license, "napari-vemseg" is free and open source software

Contribute to VEMseg

Contributions are very welcome.

Similar Software

Full credit to the following software for inspiration and use within this tool.

Reference

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vemseg-0.0.3.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

vemseg-0.0.3-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file vemseg-0.0.3.tar.gz.

File metadata

  • Download URL: vemseg-0.0.3.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.15

File hashes

Hashes for vemseg-0.0.3.tar.gz
Algorithm Hash digest
SHA256 773dba4576aff5ff774247d2e8cbebe8b0650e7d64d768b42930a2945233a903
MD5 9c2ab73a980a8a9ffcb810e00cb69a3f
BLAKE2b-256 18ac48aabd90a880a8e1a5f8d92395128b30d7a3a0f1352b4c3265876afa56d2

See more details on using hashes here.

File details

Details for the file vemseg-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: vemseg-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.15

File hashes

Hashes for vemseg-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5421b11e6faa156763c40b50f4a1b6df07b76170fc96a687e3926c816fc48c71
MD5 6bc68428747ba887ea64608c1b004639
BLAKE2b-256 f165fdb4bc6436636abcfa6d07acb26f7868a7d6863b2db449b2af96ba156741

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page