-
Notifications
You must be signed in to change notification settings - Fork 5
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 #30 from HelmholtzAI-Consultants-Munich/integratio…
…n-tests Integration tests + Patch Model
- Loading branch information
Showing
17 changed files
with
1,015 additions
and
156 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
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
napari[pyqt5]>=0.4.17 | ||
bentoml[grpc]>=1.0.13 | ||
bentoml[grpc]>=1.0.13 | ||
pytest>=7.4.3 |
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 |
---|---|---|
@@ -1,62 +1,69 @@ | ||
import os | ||
import sys | ||
from skimage import data | ||
from skimage.io import imsave | ||
import unittest | ||
import pytest | ||
|
||
sys.path.append("../") | ||
|
||
from dcp_client.app import Application | ||
from dcp_client.utils.bentoml_model import BentomlModel | ||
from dcp_client.utils.fsimagestorage import FilesystemImageStorage | ||
from dcp_client.utils.sync_src_dst import DataRSync | ||
|
||
class TestApplication(unittest.TestCase): | ||
|
||
def test_run_train(self): | ||
pass | ||
|
||
def test_run_inference(self): | ||
pass | ||
|
||
def test_load_image(self): | ||
|
||
img = data.astronaut() | ||
img2 = data.cat() | ||
os.mkdir('in_prog') | ||
imsave('in_prog/test_img.png', img) | ||
imsave('in_prog/test_img2.png', img2) | ||
rsyncer = DataRSync(user_name="local", | ||
host_name="local", | ||
server_repo_path='.') | ||
self.app = Application(BentomlModel(), | ||
rsyncer, | ||
FilesystemImageStorage(), | ||
"0.0.0.0", | ||
7010) | ||
|
||
self.app.cur_selected_img = 'test_img.png' | ||
self.app.cur_selected_path = 'in_prog' | ||
|
||
img_test = self.app.load_image() # if image_name is None | ||
self.assertEqual(img.all(), img_test.all()) | ||
img_test2 = self.app.load_image('test_img2.png') # if a filename is given | ||
self.assertEqual(img2.all(), img_test2.all()) | ||
|
||
# delete everyting we created | ||
os.remove('in_prog/test_img.png') | ||
os.remove('in_prog/test_img2.png') | ||
os.rmdir('in_prog') | ||
|
||
def test_save_image(self): | ||
pass | ||
|
||
def test_move_images(self): | ||
pass | ||
|
||
def test_delete_images(self): | ||
pass | ||
|
||
def test_search_segs(self): | ||
pass | ||
|
||
@pytest.fixture | ||
def app(): | ||
img = data.astronaut() | ||
img2 = data.cat() | ||
os.mkdir('in_prog') | ||
|
||
imsave('in_prog/test_img.png', img) | ||
imsave('in_prog/test_img2.png', img2) | ||
|
||
rsyncer = DataRSync(user_name="local", host_name="local", server_repo_path='.') | ||
app = Application(BentomlModel(), rsyncer, FilesystemImageStorage(), "0.0.0.0", 7010) | ||
|
||
app.cur_selected_img = 'test_img.png' | ||
app.cur_selected_path = 'in_prog' | ||
|
||
return app, img, img2 | ||
|
||
def test_load_image(app): | ||
app, img, img2 = app # Unpack the app, img, and img2 from the fixture | ||
|
||
img_test = app.load_image() # if image_name is None | ||
assert img.all() == img_test.all() | ||
|
||
img_test2 = app.load_image('test_img2.png') # if a filename is given | ||
assert img2.all() == img_test2.all() | ||
|
||
# delete everything we created | ||
os.remove('in_prog/test_img.png') | ||
os.remove('in_prog/test_img2.png') | ||
os.rmdir('in_prog') | ||
|
||
def test_run_train(): | ||
pass | ||
|
||
def test_run_inference(): | ||
pass | ||
|
||
def test_save_image(): | ||
pass | ||
|
||
def test_move_images(): | ||
pass | ||
|
||
def test_delete_images(): | ||
pass | ||
|
||
def test_search_segs(): | ||
pass | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
if __name__=='__main__': | ||
unittest.main() |
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 |
---|---|---|
@@ -1,51 +1,46 @@ | ||
import os | ||
import pytest | ||
from skimage.io import imsave | ||
from skimage import data | ||
import unittest | ||
|
||
from dcp_client.utils.fsimagestorage import FilesystemImageStorage | ||
|
||
|
||
class TestFilesystemImageStorage(unittest.TestCase): | ||
|
||
def test_load_image(self): | ||
fis = FilesystemImageStorage() | ||
img = data.astronaut() | ||
fname = 'test_img.png' | ||
imsave(fname, img) | ||
img_test = fis.load_image('.', fname) | ||
self.assertEqual(img.all(), img_test.all()) | ||
os.remove(fname) | ||
|
||
def test_move_image(self): | ||
fis = FilesystemImageStorage() | ||
img = data.astronaut() | ||
fname = 'test_img.png' | ||
os.mkdir('temp') | ||
imsave(fname, img) | ||
fis.move_image('.', 'temp', fname) | ||
self.assertTrue(os.path.exists('temp/test_img.png')) | ||
os.remove('temp/test_img.png') | ||
os.rmdir('temp') | ||
|
||
def test_save_image(self): | ||
fis = FilesystemImageStorage() | ||
img = data.astronaut() | ||
fname = 'test_img.png' | ||
fis.save_image('.', fname, img) | ||
self.assertTrue(os.path.exists(fname)) | ||
os.remove(fname) | ||
|
||
def test_delete_image(self): | ||
fis = FilesystemImageStorage() | ||
img = data.astronaut() | ||
fname = 'test_img.png' | ||
os.mkdir('temp') | ||
imsave('temp/test_img.png', img) | ||
fis.delete_image('temp', fname) | ||
self.assertFalse(os.path.exists('temp/test_img.png')) | ||
os.rmdir('temp') | ||
|
||
|
||
if __name__=='__main__': | ||
unittest.main() | ||
@pytest.fixture | ||
def fis(): | ||
return FilesystemImageStorage() | ||
|
||
@pytest.fixture | ||
def sample_image(): | ||
# Create a sample image | ||
img = data.astronaut() | ||
fname = 'test_img.png' | ||
imsave(fname, img) | ||
return fname | ||
|
||
def test_load_image(fis, sample_image): | ||
img_test = fis.load_image('.', sample_image) | ||
assert img_test.all() == data.astronaut().all() | ||
os.remove(sample_image) | ||
|
||
def test_move_image(fis, sample_image): | ||
temp_dir = 'temp' | ||
os.mkdir(temp_dir) | ||
fis.move_image('.', temp_dir, sample_image) | ||
assert os.path.exists(os.path.join(temp_dir, 'test_img.png')) | ||
os.remove(os.path.join(temp_dir, 'test_img.png')) | ||
os.rmdir(temp_dir) | ||
|
||
def test_save_image(fis): | ||
img = data.astronaut() | ||
fname = 'output.png' | ||
fis.save_image('.', fname, img) | ||
assert os.path.exists(fname) | ||
os.remove(fname) | ||
|
||
def test_delete_image(fis, sample_image): | ||
temp_dir = 'temp' | ||
os.mkdir(temp_dir) | ||
fis.move_image('.', temp_dir, sample_image) | ||
fis.delete_image(temp_dir, 'test_img.png') | ||
assert not os.path.exists(os.path.join(temp_dir, 'test_img.png')) | ||
os.rmdir(temp_dir) |
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 |
---|---|---|
@@ -1,26 +1,66 @@ | ||
{ | ||
"setup":{ | ||
"segmentation": "GeneralSegmentation", | ||
"accepted_types": [".jpg", ".jpeg", ".png", ".tiff", ".tif"], | ||
"seg_name_string": "_seg" | ||
"setup": { | ||
"segmentation": "GeneralSegmentation", | ||
"accepted_types": [".jpg", ".jpeg", ".png", ".tiff", ".tif"], | ||
"seg_name_string": "_seg" | ||
}, | ||
"service":{ | ||
"model_to_use": "CustomCellposeModel", | ||
|
||
"service": { | ||
"model_to_use": "CellposePatchCNN", | ||
"save_model_path": "mytrainedmodel", | ||
"runner_name": "cellpose_runner", | ||
"service_name": "data-centric-platform", | ||
"port": 7010 | ||
}, | ||
"model": { | ||
"model_type":"cyto" | ||
|
||
"model": { | ||
"segmentor": { | ||
"model_type": "cyto" | ||
}, | ||
"classifier":{ | ||
"in_channels": 1, | ||
"num_classes": 3, | ||
"black_bg": "False", | ||
"include_mask": "False" | ||
} | ||
}, | ||
|
||
"data": { | ||
"data_root": "/home/ubuntu/dcp-data" | ||
"data_root": "data" | ||
}, | ||
|
||
"train":{ | ||
"n_epochs": 2, | ||
"channels":[0] | ||
"segmentor":{ | ||
"n_epochs": 7, | ||
"channels": [0,0], | ||
"min_train_masks": 1 | ||
}, | ||
"classifier":{ | ||
"train_data":{ | ||
"patch_size": 64, | ||
"noise_intensity": 5, | ||
"num_classes": 3 | ||
}, | ||
"n_epochs": 8, | ||
"lr": 0.001, | ||
"batch_size": 1, | ||
"optimizer": "Adam" | ||
} | ||
}, | ||
|
||
"eval":{ | ||
"segmentor": { | ||
"z_axis": null, | ||
"channel_axis": null, | ||
"rescale": 1, | ||
"batch_size": 1 | ||
}, | ||
"classifier": { | ||
"data":{ | ||
"patch_size": 64, | ||
"noise_intensity": 5 | ||
} | ||
}, | ||
"mask_channel_axis": 0 | ||
} | ||
} |
Oops, something went wrong.