-
Notifications
You must be signed in to change notification settings - Fork 426
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 #919 from vloncar/fetch_example
Fix fetching models from example-models repo
- Loading branch information
Showing
2 changed files
with
49 additions
and
18 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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import ast | ||
import io | ||
from contextlib import redirect_stdout | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
import hls4ml | ||
|
||
test_root_path = Path(__file__).parent | ||
|
||
|
||
@pytest.mark.parametrize('backend', ['Vivado', 'Vitis', 'Quartus']) | ||
def test_fetch_example_utils(backend): | ||
f = io.StringIO() | ||
with redirect_stdout(f): | ||
hls4ml.utils.fetch_example_list() | ||
out = f.getvalue() | ||
|
||
model_list = ast.literal_eval(out) # Check if we indeed got a dictionary back | ||
|
||
assert 'qkeras_mnist_cnn.json' in model_list['keras'] | ||
|
||
# This model has an example config that is also downloaded. Stored configurations don't set "Backend" value. | ||
config = hls4ml.utils.fetch_example_model('qkeras_mnist_cnn.json', backend=backend) | ||
config['KerasJson'] = 'qkeras_mnist_cnn.json' | ||
config['KerasH5'] | ||
config['Backend'] = backend | ||
config['OutputDir'] = str(test_root_path / f'hls4mlprj_fetch_example_{backend}') | ||
|
||
hls_model = hls4ml.converters.keras_to_hls(config) | ||
hls_model.compile() # For now, it is enough if it compiles, we're only testing downloading works as expected |