def test_BroadNucleusDataBinarized(cache_path):
    spec_path = Path(
        __file__
    ).parent / "../../../specs/readers/BroadNucleusDataBinarized.reader.yaml"
    pybio_reader = load_spec_and_kwargs(str(spec_path),
                                        kwargs={},
                                        cache_path=cache_path)
    reader = utils.get_instance(pybio_reader)
    assert isinstance(reader, BroadNucleusDataBinarized)

    roi = ((slice(2), slice(4), slice(6)), (slice(3), slice(5), slice(7)))
    x, y = reader[roi]

    assert numpy.equal(
        x,
        [
            [
                [138.0, 130.0, 140.0, 141.0, 138.0, 139.0],
                [134.0, 134.0, 135.0, 137.0, 139.0, 136.0],
                [127.0, 132.0, 140.0, 137.0, 130.0, 140.0],
                [131.0, 134.0, 136.0, 135.0, 141.0, 141.0],
            ],
            [
                [133.0, 136.0, 134.0, 134.0, 130.0, 135.0],
                [125.0, 132.0, 136.0, 133.0, 132.0, 127.0],
                [135.0, 132.0, 137.0, 127.0, 138.0, 131.0],
                [135.0, 129.0, 133.0, 138.0, 139.0, 133.0],
            ],
        ],
    ).all()
    assert numpy.equal(y, numpy.zeros((3, 5, 7), dtype=bool)).all()
Esempio n. 2
0
def test_load_specs_from_manifest(cache_path, category, spec_path, required_spec_kwargs):
    kwargs = required_spec_kwargs.get(spec_path, {})

    spec_path = MANIFEST_PATH.parent / spec_path
    assert spec_path.exists()

    loaded_spec = load_spec_and_kwargs(str(spec_path), **kwargs, cache_path=cache_path)
    instance = utils.get_instance(loaded_spec)
    assert instance
Esempio n. 3
0
def test_exemplum(data_path, cache_path):
    spec_path = data_path / "unet2d/UNet2DNucleiBroad.model.yaml"
    assert spec_path.exists(), spec_path.absolute()
    pybio_model = load_spec_and_kwargs(str(spec_path), cache_path=cache_path)

    exemplum = Exemplum(pybio_model=pybio_model, _devices=[torch.device("cpu")])
    test_ipt = numpy.load(pybio_model.spec.test_input)  # test input with batch dim
    out = exemplum.forward(test_ipt[0])  # todo: exemplum.forward should get batch with batch dim
    # assert isinstance(out_seq, (list, tuple)) # todo: forward should return a list
    # assert len(out_seq) == 1
    # out = out_seq
    expected_out = numpy.load(pybio_model.spec.test_output)[
        0
    ]  # todo: remove [0], exemplum.forward should return batch with batch dim
    assert numpy.isclose(out, expected_out).all()
def test_load_non_existing_spec(cache_path):
    spec_path = "some/none/existing/path/to/spec.model.yaml"

    with pytest.raises(FileNotFoundError):
        load_spec_and_kwargs(spec_path, cache_path=cache_path)
def test_load_non_valid_spec_name(cache_path):
    spec_path = "some/none/existing/path/to/spec.not_valid.yaml"

    with pytest.raises(ValueError):
        load_spec_and_kwargs(spec_path, cache_path=cache_path)