Skip to content

Instantly share code, notes, and snippets.

View constantinpape's full-sized avatar

Constantin Pape constantinpape

View GitHub Profile

Example for exporting Deep MIB ONNX model

  1. Export the model to the modelzoo format by running python export_onnx_model.py script. See the comments in there for the links to the files. This needs a python environment with bioimageio.core and onnx installed. See here for details. The script will create the zipped model in exported_model/model-onnx.zip.
  2. The model can then be tested by running bioimageio test-model exported_model/model-onnx.zip --decimal 2. It passes the test (see below). The --decimal 2 is necessary to run the test with a higher error tolerance than the default value, otherwise it fails due to a few values that disagree. (This is likely due to some inaccuracies in the onnx model conversion).
$ bioimageio test-model exported_model/model-onnx.zip --decimal 2
bioimageio.spec 0.4.9
@constantinpape
constantinpape / merge_non_touching.py
Created July 11, 2022 18:15
Merging non-touching objects after Mutex Watershed Segmentation
import elf.segmentation as eseg
import nifty.graph.rag as nrag
import nifty.ufd
import numpy as np
from elf.segmentation.mutex_watershed import mutex_watershed
def merge_non_touching(affinities, seg, offsets):
# compute the region adjacency graph
rag = eseg.compute_rag(seg)
@constantinpape
constantinpape / check_unit.py
Last active November 4, 2021 15:12
unit-validation
# install cfunits via conda:
# conda install -c conda-forge cfunits
from cfunits import Units
def check_unit(unit):
"""Check if a unit is valid according to udunits2"""
return Units(unit).isvalid
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import numpy as np
import zarr
def create_ome_zarr_datasets(
f,
shape,
chunks,
scale_factors,
dtype
from functools import partial
import os
from multiprocesing import Process, Queue
from shutil import move
import time
import matplotlib.pyplot as plt
from pynput import mouse, Button
from imageio import imread
@constantinpape
constantinpape / benchmark_unique_int.cxx
Created July 8, 2017 20:56
Benchmarking unique vectors in C++
#include <set>
#include <vector>
#include <algorithm>
#include <random>
#include <chrono>
#include <functional>
#include <iostream>
#include <unordered_set>