-
Notifications
You must be signed in to change notification settings - Fork 0
Basic model inference #48
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
10 commits
Select commit
Hold shift + click to select a range
ae3c960
add tests
Zain-Mahmoud 0de35c4
create model interface
Zain-Mahmoud dadec33
update formatting
Zain-Mahmoud 8c31061
fix formatting
Zain-Mahmoud 1c26fcf
fix comment formatting
Zain-Mahmoud 27f7362
update dependencies
Zain-Mahmoud a9b088c
update classes and tests
Zain-Mahmoud 1ea31b2
update logic
Zain-Mahmoud f5cda68
update class structure
Zain-Mahmoud 0e95895
add fail tests
Zain-Mahmoud 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| """ | ||
| Tests inference interface by instantiating mock models | ||
| and implementing the `generate` function | ||
| """ | ||
|
|
||
| import numpy as np | ||
| import pytest | ||
|
|
||
| from terrain_diffusion.inference import ( | ||
| LATENT_MAP_SIZE, | ||
| PATCH_SIZE, | ||
| MockCoreModel, | ||
| MockCoreModelInput, | ||
| MockCoreModelOutput, | ||
| MockDecoderModel, | ||
| MockDecoderModelInput, | ||
| MockDecoderModelOutput, | ||
| load_model, | ||
| ) | ||
|
|
||
|
|
||
| class TestTerrainModel: | ||
|
Zain-Mahmoud marked this conversation as resolved.
|
||
| @pytest.fixture | ||
| def initial_decoder(self) -> MockDecoderModel: | ||
| return MockDecoderModel() | ||
|
|
||
| @pytest.fixture | ||
| def initial_core(self) -> MockCoreModel: | ||
| return MockCoreModel() | ||
|
|
||
| def test_core_input_generation(self): | ||
| with pytest.raises(AssertionError): | ||
| MockCoreModelInput(np.ones((1, 1))) | ||
|
|
||
| def test_core_output_generation(self): | ||
| with pytest.raises(AssertionError): | ||
| MockCoreModelOutput(np.ones((1, 1)), np.ones(LATENT_MAP_SIZE)) | ||
| with pytest.raises(AssertionError): | ||
| MockCoreModelOutput(np.ones((PATCH_SIZE[0] // 8, PATCH_SIZE[1] // 8)), np.ones((1, 1))) | ||
|
|
||
| def test_decoder_input_generation(self): | ||
| with pytest.raises(AssertionError): | ||
| MockDecoderModelInput(np.ones((1, 1))) | ||
|
|
||
| def test_decoder_output_generation(self): | ||
| with pytest.raises(AssertionError): | ||
| MockDecoderModelOutput(np.ones((1, 1))) | ||
|
|
||
| def test_load_model(self): | ||
| assert isinstance(load_model("decoder"), MockDecoderModel), ( | ||
| "model does not load correct decoder" | ||
| ) | ||
| assert isinstance(load_model("core"), MockCoreModel), "model does not load correct core" | ||
|
|
||
| def test_predict_core(self, initial_core): | ||
| input = MockCoreModelInput(np.ones(PATCH_SIZE)) | ||
|
|
||
| actual = initial_core.predict(input) | ||
| actual_2 = initial_core.predict(input) | ||
|
|
||
| expected_low_res = np.ndarray((PATCH_SIZE[0] // 8, PATCH_SIZE[1] // 8)) | ||
| expected_latent = np.ndarray(LATENT_MAP_SIZE) | ||
|
|
||
| expected_low_res.fill(2) | ||
| expected_latent.fill(2) | ||
|
|
||
| expected = MockCoreModelOutput(expected_low_res, expected_latent) | ||
|
|
||
| assert actual == expected, "predictions are not equal" | ||
| assert actual == actual_2, "model return different predictions on same input" | ||
| assert actual.low_res_grid.shape == (PATCH_SIZE[0] // 8, PATCH_SIZE[1] // 8), ( | ||
| "low resolution map shape is not patch size // 8" | ||
| ) | ||
| assert actual.latent_map.shape == LATENT_MAP_SIZE, "latent map size is not correct" | ||
|
|
||
| def test_predict_decoder(self, initial_decoder): | ||
| input = MockDecoderModelInput(np.ones(LATENT_MAP_SIZE)) | ||
|
|
||
| actual = initial_decoder.predict(input) | ||
| actual_2 = initial_decoder.predict(input) | ||
|
|
||
| expected_full_res = np.ndarray(PATCH_SIZE) | ||
| expected_full_res.fill(2) | ||
|
|
||
| expected = MockDecoderModelOutput(expected_full_res) | ||
|
|
||
| assert actual == expected, "predictions are not equal" | ||
| assert actual == actual_2, "model return different predictions on same input" | ||
| assert actual.full_res_grid.shape == PATCH_SIZE, ( | ||
| "full resolution map does not match patch size" | ||
| ) | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.