How to use csbdeep - 10 common examples

To help you get started, we’ve selected a few csbdeep examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github CSBDeep / CSBDeep / tests / test_models.py View on Github external
def _predict(imdims,axes):
        img = rng.uniform(size=imdims)
        if config.probabilistic:
            prob = model.predict_probabilistic(img, axes, factor, None, None)
            mean, scale = prob.mean(), prob.scale()
            assert mean.shape == scale.shape
        else:
            mean = model.predict(img, axes, factor, None, None)
        a = axes_dict(axes)['Z']
        assert imdims[a]*factor == mean.shape[a]
github CSBDeep / CSBDeep / tests / test_datagen.py View on Github external
patch_size[axes_dict(img_axes if patch_axes is None else patch_axes)[a]] = (
                None if red_none else img_size[axes_dict(img_axes)[a]]
            )
        X,Y,XYaxes = create_patches_reduced_target (
            raw_data            = raw_data,
            patch_size          = patch_size,
            patch_axes          = patch_axes,
            n_patches_per_image = n_patches_per_image,
            reduction_axes      = red_axes,
            target_axes         = rng.choice((None,img_axes)) if keepdims else ''.join(a for a in img_axes if a not in red_axes),
            #
            normalization       = lambda patches_x, patches_y, *args: (patches_x, patches_y),
            verbose             = False,
        )
        assert len(X) == n_images*n_patches_per_image
        _X = np.mean(X,axis=tuple(axes_dict(XYaxes)[a] for a in red_axes),keepdims=True)
        err = np.max(np.abs(_X-Y))
        assert err < 1e-5
github CSBDeep / CSBDeep / tests / test_models.py View on Github external
def _predict(imdims,axes):
        img = rng.uniform(size=imdims)
        if config.probabilistic:
            prob = model.predict_probabilistic(img, axes, factor, None, None)
            mean, scale = prob.mean(), prob.scale()
            assert mean.shape == scale.shape
        else:
            mean = model.predict(img, axes, factor, None, None)
        a = axes_dict(axes)['Z']
        assert imdims[a]*factor == mean.shape[a]
github CSBDeep / CSBDeep / tests / test_models.py View on Github external
from __future__ import print_function, unicode_literals, absolute_import, division
from six.moves import range, zip, map, reduce, filter

from itertools import product

# import warnings
import numpy as np
import pytest
from csbdeep.data import NoNormalizer, NoResizer
from csbdeep.internals.predict import tile_overlap
from csbdeep.utils.tf import keras_import
K = keras_import('backend')

from csbdeep.internals.nets import receptive_field_unet
from csbdeep.models import Config, CARE, UpsamplingCARE, IsotropicCARE
from csbdeep.models import ProjectionConfig, ProjectionCARE
from csbdeep.utils import axes_dict
from csbdeep.utils.six import FileNotFoundError



def config_generator(cls=Config, **kwargs):
    assert 'axes' in kwargs
    keys, values = kwargs.keys(), kwargs.values()
    values = [v if isinstance(v,(list,tuple)) else [v] for v in values]
    for p in product(*values):
        yield cls(**dict(zip(keys,p)))
github CSBDeep / CSBDeep / tests / test_models.py View on Github external
def test_model_train(tmpdir,config):
    rng = np.random.RandomState(42)
    K.clear_session()
    X = rng.uniform(size=(4,)+(32,)*config.n_dim+(config.n_channel_in,))
    Y = rng.uniform(size=(4,)+(32,)*config.n_dim+(config.n_channel_out,))
    model = CARE(config,basedir=str(tmpdir))
    model.train(X,Y,(X,Y))
github CSBDeep / CSBDeep / tests / test_models.py View on Github external
def _build():
        with pytest.raises(FileNotFoundError):
            CARE(None,basedir=str(tmpdir))

        CARE(config,name='model',basedir=None)
        with pytest.raises(ValueError):
            CARE(None,basedir=None)

        CARE(config,basedir=str(tmpdir)).export_TF()

        with pytest.warns(UserWarning):
            CARE(config,name='model',basedir=str(tmpdir))
            CARE(config,name='model',basedir=str(tmpdir))
            CARE(None,name='model',basedir=str(tmpdir))
    if config.is_valid():
github CSBDeep / CSBDeep / tests / test_models.py View on Github external
def _build():
        with pytest.raises(FileNotFoundError):
            CARE(None,basedir=str(tmpdir))

        CARE(config,name='model',basedir=None)
        with pytest.raises(ValueError):
            CARE(None,basedir=None)

        CARE(config,basedir=str(tmpdir)).export_TF()

        with pytest.warns(UserWarning):
            CARE(config,name='model',basedir=str(tmpdir))
            CARE(config,name='model',basedir=str(tmpdir))
            CARE(None,name='model',basedir=str(tmpdir))
    if config.is_valid():
github CSBDeep / CSBDeep / tests / test_models.py View on Github external
def _build():
        with pytest.raises(FileNotFoundError):
            CARE(None,basedir=str(tmpdir))

        CARE(config,name='model',basedir=None)
        with pytest.raises(ValueError):
            CARE(None,basedir=None)

        CARE(config,basedir=str(tmpdir)).export_TF()

        with pytest.warns(UserWarning):
            CARE(config,name='model',basedir=str(tmpdir))
            CARE(config,name='model',basedir=str(tmpdir))
            CARE(None,name='model',basedir=str(tmpdir))
    if config.is_valid():
github CSBDeep / CSBDeep / tests / test_models.py View on Github external
def test_model_predict(tmpdir,config):
    rng = np.random.RandomState(42)
    normalizer, resizer = NoNormalizer(), NoResizer()

    K.clear_session()
    model = CARE(config,basedir=str(tmpdir))
    axes = config.axes

    def _predict(imdims,axes):
        img = rng.uniform(size=imdims)
        # print(img.shape, axes, config.n_channel_out)
        if config.probabilistic:
            prob = model.predict_probabilistic(img, axes, normalizer, resizer)
            mean, scale = prob.mean(), prob.scale()
            assert mean.shape == scale.shape
        else:
            mean = model.predict(img, axes, normalizer, resizer)

        if 'C' not in axes:
            if config.n_channel_out == 1:
                assert mean.shape == img.shape
            else:
github CSBDeep / CSBDeep / tests / test_models.py View on Github external
(_with_channel('YX'),_with_channel('YX')),
        (_with_channel('XYZ'),_with_channel('XYZ')),
        (_with_channel('XTY'),_with_channel('XTY')),
        (_with_channel('SYX'),_with_channel('YX')),
        (_with_channel('STYX'),_with_channel('TYX')),
        (_with_channel('SXYZ'),_with_channel('XYZ')),
    ]

    for (axes,axes_ref) in axes_list:
        assert Config(axes).axes == axes_ref

    with pytest.raises(ValueError):
        Config('XYC')
        Config('CXY')
    with pytest.raises(ValueError):
        Config('XYZC')
        Config('CXYZ')
    with pytest.raises(ValueError):
        Config('XTYC')
        Config('CXTY')
    with pytest.raises(ValueError): Config('XYZT')
    with pytest.raises(ValueError): Config('tXYZ')
    with pytest.raises(ValueError): Config('XYS')
    with pytest.raises(ValueError): Config('XSYZ')