-
Notifications
You must be signed in to change notification settings - Fork 4
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 #96 from christophbrgr/master
Fixes label list return error
- Loading branch information
Showing
23 changed files
with
196 additions
and
36 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 |
---|---|---|
|
@@ -8,3 +8,4 @@ | |
.coverage | ||
.vscode | ||
*.code-workspace | ||
/framework/htmlcov/ |
File renamed without changes.
File renamed without changes.
43 changes: 43 additions & 0 deletions
43
framework/modelhubapi_tests/mockmodels/contrib_src_mi/inference.py
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,43 @@ | ||
""" | ||
Implementation of several mock models to test the API. Each model has a | ||
slightly different behaviour, which should be properly handled by the API. | ||
Also most models are not fully valid, e.g. they do not comply to the mock | ||
config. This is ok for unit testing, most models are only used for a small | ||
set of specific tests requiring that model's specific behavioural aspect. | ||
These models test absed on the multi input mock model (contrib_src_mi) with | ||
a single output. | ||
""" | ||
|
||
import os | ||
import numpy as np | ||
from modelhublib.model import ModelBase | ||
|
||
|
||
class Model(ModelBase): | ||
|
||
def __init__(self): | ||
pass | ||
|
||
def infer(self, input): | ||
pass | ||
|
||
class ModelReturnsOneLabelList(ModelBase): | ||
|
||
def __init__(self): | ||
pass | ||
|
||
def infer(self, input): | ||
if os.path.isfile(input): | ||
# Return a constant classification result no matter what's the input | ||
label_list = [{"label": "class_0", "probability": 0.3}, | ||
{"label": "class_1", "probability": 0.7}] | ||
return label_list | ||
else: | ||
raise IOError("File " + input + " does not exist.") | ||
|
||
|
||
class ModelReturnsListOfOneLabelList(ModelReturnsOneLabelList): | ||
|
||
def infer(self, input): | ||
return [super(ModelReturnsListOfOneLabelList, self).infer(input)] |
57 changes: 57 additions & 0 deletions
57
framework/modelhubapi_tests/mockmodels/contrib_src_mi/model/config.json
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,57 @@ | ||
{ | ||
"id": "MockId", | ||
"meta": { | ||
"name": "MockNet", | ||
"application_area": "UnitTest", | ||
"task": "Mock for Unit Testing", | ||
"task_extended": | ||
"Simple mock model for unit testing the APIs", | ||
"data_type": "Image", | ||
"data_source": "None" | ||
}, | ||
"publication": { | ||
"title": | ||
"Mock Title", | ||
"journal": "None", | ||
"year": 1111, | ||
"authors": | ||
"No One", | ||
"email": "mock@mock.org", | ||
"abstract": | ||
"Mock abstract", | ||
"url": "https://modelhub.ai", | ||
"google_scholar": | ||
"", | ||
"bibtex": | ||
"" | ||
}, | ||
"model": { | ||
"description": | ||
"Mock description", | ||
"architecture": "Empty", | ||
"learning_type": "None", | ||
"io": { | ||
"input": { | ||
"format": ["image/png"], | ||
"dim_limits": [ | ||
{ | ||
"min": 1, | ||
"max": 4 | ||
}, | ||
{ | ||
"min": 1 | ||
}, | ||
{ | ||
"min": 1 | ||
} | ||
] | ||
}, | ||
"output": [ | ||
{ | ||
"name": "probabilities", | ||
"type": "label_list" | ||
} | ||
] | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
framework/modelhubapi_tests/mockmodels/contrib_src_mi/model/model.txt
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,3 @@ | ||
EMPTY MOCK MODEL FOR UNIT TESTING | ||
|
||
This model has only one return format |
Empty file.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
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
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
27 changes: 27 additions & 0 deletions
27
framework/modelhublib_tests/imageconverters_tests/numpyToNumpyConverter_test.py
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 @@ | ||
import unittest | ||
import os | ||
import json | ||
import PIL | ||
import numpy as np | ||
|
||
from modelhublib.imageconverters import NumpyToNumpyConverter | ||
|
||
class TestNumpyImageConverter(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self.imageConverter = NumpyToNumpyConverter() | ||
|
||
def tearDown(self): | ||
pass | ||
|
||
def test_convert_success_on_arr(self): | ||
baseline = np.asarray([[1,2,3,4],[2,0,0,0],[1,2,3,4]]) | ||
npArr = self.imageConverter.convert(baseline) | ||
self.assertEqual(baseline.shape, npArr.shape) | ||
|
||
def test_convert_fails_on_image_as_input(self): | ||
image = PIL.Image.new("RGB", (64,32)) | ||
self.assertRaises(IOError, self.imageConverter.convert, image) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
Oops, something went wrong.