-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #347 from AllenCellModeling/feature/api_dataclass
Feature/api dataclass
- Loading branch information
Showing
3 changed files
with
73 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# goal: allow the API client to interact with CytoDLModel without | ||
# worrying about the actual values being used in config files | ||
from enum import Enum | ||
|
||
import skimage | ||
|
||
|
||
class ExperimentType(Enum): | ||
GAN = "gan" | ||
INSTANCE_SEG = "instance_seg" | ||
LABEL_FREE = "labelfree" | ||
SEGMENTATION_PLUGIN = "segmentation_plugin" | ||
SEGMENTATION = "segmentation" | ||
|
||
|
||
class HardwareType(Enum): | ||
CPU = "cpu" | ||
GPU = "gpu" | ||
# other hardware types available, but require more complicated config | ||
|
||
|
||
class PatchSize(Enum): | ||
"""Patch size for training, and their respective patch shapes.""" | ||
|
||
SMALL = [16, 32, 32] | ||
MEDIUM = [16, 64, 64] | ||
LARGE = [16, 128, 128] | ||
|
||
|
||
# importing skimage takes a while. | ||
# could speed it up by hardcoding this enum, but would have to update | ||
# if skimage adds/deletes threshold filters | ||
|
||
AutoThresholdMethod = Enum( | ||
"AutoThresholdMethod", | ||
{ | ||
func_name.split("threshold_")[-1].upper(): func_name | ||
for func_name in filter(lambda x: x.startswith("threshold_"), dir(skimage.filters)) | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
|
||
import cyto_dl.api.model | ||
from cyto_dl.api.data import ExperimentType | ||
from cyto_dl.api.model import CytoDLModel | ||
|
||
|
||
# mock these functions to avoid attempts to write to file system | ||
@patch("cyto_dl.api.model.OmegaConf.save") | ||
@patch("cyto_dl.api.model.Path.mkdir") | ||
def test_load_default_experiment_valid_exp_type(MockMkdir, MockSave): | ||
model: CytoDLModel = CytoDLModel() | ||
model.load_default_experiment(ExperimentType.SEGMENTATION.value, "fake_dir") | ||
MockMkdir.assert_called() | ||
MockSave.assert_called() | ||
|
||
|
||
@patch("cyto_dl.api.model.OmegaConf.save") | ||
@patch("cyto_dl.api.model.Path.mkdir") | ||
def test_load_default_experiment_invalid_exp_type(MockMkdir, MockSave): | ||
model: CytoDLModel = CytoDLModel() | ||
with pytest.raises(AssertionError): | ||
model.load_default_experiment("invalid_exp_type", "fake_dir") | ||
MockMkdir.assert_not_called() | ||
MockSave.assert_not_called() |