Skip to content

Commit

Permalink
Merge pull request #30 from HelmholtzAI-Consultants-Munich/integratio…
Browse files Browse the repository at this point in the history
…n-tests

Integration tests + Patch Model
  • Loading branch information
christinab12 authored Nov 15, 2023
2 parents db1234c + 90e7b25 commit 6ccb734
Show file tree
Hide file tree
Showing 17 changed files with 1,015 additions and 156 deletions.
2 changes: 1 addition & 1 deletion src/client/dcp_client/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def search_segs(self, img_directory, cur_selected_img):
"""Returns a list of full paths of segmentations for an image"""
# Take all segmentations of the image from the current directory:
search_string = utils.get_path_stem(cur_selected_img) + '_seg'
seg_files = [file_name for file_name in os.listdir(img_directory) if search_string in file_name]
seg_files = [file_name for file_name in os.listdir(img_directory) if (search_string == utils.get_path_stem(file_name) or str(file_name).startswith(search_string))]
return seg_files


Expand Down
3 changes: 2 additions & 1 deletion src/client/requirements.txt
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
109 changes: 58 additions & 51 deletions src/client/test/test_app.py
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()
85 changes: 40 additions & 45 deletions src/client/test/test_fsimagestorage.py
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)
62 changes: 51 additions & 11 deletions src/server/dcp_server/config.cfg
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
}
}
Loading

0 comments on commit 6ccb734

Please sign in to comment.