예제 #1
0
def _model3d():
    from utils import path_model3d
    from stardist.models import StarDist3D
    model_path = path_model3d()
    return StarDist3D(None,
                      name=model_path.name,
                      basedir=str(model_path.parent))
예제 #2
0
def test_load_and_export_TF():
    model_path = path_model3d()
    model = StarDist3D(None,
                       name=model_path.name,
                       basedir=str(model_path.parent))
    model.export_TF(single_output=True, upsample_grid=False)
    model.export_TF(single_output=True, upsample_grid=True)
예제 #3
0
def test_load_and_export_TF():
    model_path = path_model3d()
    model = StarDist3D(None,
                       name=model_path.name,
                       basedir=str(model_path.parent))
    assert any(g > 1 for g in model.config.grid)
    # model.export_TF(single_output=False, upsample_grid=False)
    # model.export_TF(single_output=False, upsample_grid=True)
    model.export_TF(single_output=True, upsample_grid=False)
    model.export_TF(single_output=True, upsample_grid=True)
예제 #4
0
def test_load_and_predict_with_overlap():
    model_path = path_model3d()
    model = StarDist3D(None, name=model_path.name, basedir=str(model_path.parent))
    img, mask = real_image3d()
    x = normalize(img,1,99.8)
    prob, dist = model.predict(x, n_tiles=(1,2,2))
    assert prob.shape == dist.shape[:3]
    assert model.config.n_rays == dist.shape[-1]
    labels, _ = model.predict_instances(x, nms_thresh = .5,
                                        overlap_label = -3)
    assert np.min(labels) == -3
    return model, labels
예제 #5
0
def test_load_and_predict():
    model_path = path_model3d()
    model = StarDist3D(None, name=model_path.name, basedir=str(model_path.parent))
    img, mask = real_image3d()
    x = normalize(img,1,99.8)
    prob, dist = model.predict(x, n_tiles=(1,2,2))
    assert prob.shape == dist.shape[:3]
    assert model.config.n_rays == dist.shape[-1]
    labels, _ = model.predict_instances(x)
    assert labels.shape == img.shape[:3]
    stats = matching(mask, labels, thresh=0.5)
    assert (stats.fp, stats.tp, stats.fn) == (0, 30, 21)
    return model, labels
예제 #6
0
def test_predict_dense_sparse():
    model_path = path_model3d()
    model = StarDist3D(None,
                       name=model_path.name,
                       basedir=str(model_path.parent))
    img, mask = real_image3d()
    x = normalize(img, 1, 99.8)
    labels1, res1 = model.predict_instances(x, n_tiles=(1, 2, 2), sparse=False)
    labels2, res2 = model.predict_instances(x, n_tiles=(1, 2, 2), sparse=True)
    assert np.allclose(labels1, labels2)
    assert all(
        np.allclose(res1[k], res2[k])
        for k in set(res1.keys()).union(set(res2.keys())))
    return labels2, labels2
예제 #7
0
def test_optimize_thresholds():
    model_path = path_model3d()
    model = StarDist3D(None, name=model_path.name, basedir=str(model_path.parent))
    img, mask = real_image3d()
    x = normalize(img,1,99.8)
    def _opt(model):
        return model.optimize_thresholds([x],[mask],
                                    nms_threshs = [.3,.5],
                                    iou_threshs = [.3,.5],
                                    optimize_kwargs = dict(tol=1e-1),
                                    save_to_json = False)

    t1 = _opt(model)
    # enforce implicit tiling 
    model.config.train_batch_size = 1
    model.config.train_patch_size = tuple(s-1 for s in x.shape)
    t2 = _opt(model)
    assert all(np.allclose(t1[k],t2[k]) for k in t1.keys())         
    return model