Skip to main content

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

Metadata

Release files for vemseg 0.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for vemseg 0.0.5
File Size Uploaded Provenance Actions
vemseg-0.0.5.tar.gz 9.4 kB Without provenance Details for vemseg-0.0.5.tar.gz

Release files / vemseg-0.0.5.tar.gz

Download URL vemseg-0.0.5.tar.gz
Size 9.4 kB
Tags Source
SHA-256 checksum
How to use checksums
1cd6a4b34fd81089c5c5149d721408066b11b4003a39690ed71ef0162cd33237
BLAKE2b-256 checksum
How to use checksums
5675f1b56b596aedf08b3826f9ee07885565042e56dccb8ec0a3f73e82b2936c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.15

Security for vemseg 0.0.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page