-
Notifications
You must be signed in to change notification settings - Fork 493
add better parameter validation for KIFEst #116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -80,9 +80,7 @@ def _get_model(self, label_cardinality): | |
| return model | ||
|
|
||
| def _get_estimator(self, model): | ||
| """ | ||
| Create a :py:obj:`KerasImageFileEstimator` from an existing Keras model | ||
| """ | ||
| """Create a :py:obj:`KerasImageFileEstimator` from an existing Keras model""" | ||
| _random_filename_suffix = str(uuid.uuid4()) | ||
| model_filename = os.path.join(self.temp_dir, 'model-{}.h5'.format(_random_filename_suffix)) | ||
| model.save(model_filename) | ||
|
|
@@ -105,7 +103,27 @@ def setUp(self): | |
| def tearDown(self): | ||
| shutil.rmtree(self.temp_dir, ignore_errors=True) | ||
|
|
||
| def test_validate_params(self): | ||
| """Test that `KerasImageFileEstimator._validateParams` method works as expected""" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we probably could be more thorough in making sure all the intersect/diff logic works but I think it's good enough. |
||
| kifest = KerasImageFileEstimator() | ||
|
|
||
| # should raise an error to define required parameters | ||
| # assuming at least one param without default value | ||
| self.assertRaisesRegexp(ValueError, 'defined', kifest._validateParams, {}) | ||
| kifest.setParams(imageLoader=_load_image_from_uri, inputCol='c1', labelCol='c2') | ||
| kifest.setParams(modelFile='/path/to/file.ext') | ||
|
|
||
| # should raise an error to define or tune parameters | ||
| # assuming at least one tunable param without default value | ||
| self.assertRaisesRegexp(ValueError, 'tuned', kifest._validateParams, {}) | ||
| kifest.setParams(kerasOptimizer='adam', kerasLoss='mse', kerasFitParams={}) | ||
| kifest.setParams(outputCol='c3', outputMode='vector') | ||
|
|
||
| # should pass test on supplying all parameters | ||
| self.assertTrue(kifest._validateParams({})) | ||
|
|
||
| def test_single_training(self): | ||
| """Test that single model fitting works well""" | ||
| # Create image URI dataframe | ||
| label_cardinality = 10 | ||
| image_uri_df = self._create_train_image_uris_and_labels(repeat_factor=3, | ||
|
|
@@ -123,6 +141,7 @@ def test_single_training(self): | |
| str(transformer.getOrDefault(p))) | ||
|
|
||
| def test_tuning(self): | ||
| """Test that multiple model fitting using `CrossValidator` works well""" | ||
| # Create image URI dataframe | ||
| label_cardinality = 2 | ||
| image_uri_df = self._create_train_image_uris_and_labels(repeat_factor=3, | ||
|
|
@@ -150,6 +169,7 @@ def test_tuning(self): | |
| "fit params must be copied") | ||
|
|
||
| def test_keras_training_utils(self): | ||
| """Test some Keras training utils""" | ||
| self.assertTrue(kmutil.is_valid_optimizer('adam')) | ||
| self.assertFalse(kmutil.is_valid_optimizer('noSuchOptimizer')) | ||
| self.assertTrue(kmutil.is_valid_loss_function('mse')) | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merge
model_paramsandoutput_paramsintotunable_paramsfor clarity