-
Notifications
You must be signed in to change notification settings - Fork 474
Fix GlobalPooling1D Layers #399
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
6 commits
Select commit
Hold shift + click to select a range
fdb9606
add global_pooling1d_cl
jmduarte 445c56b
io_parallel global_pooling1d_cl
jmduarte e8f9c8d
add globalpooling1d testing; add missing include in nnet_conv_stream.h
jmitrevs 1b42183
update test
jmduarte d2dbbdd
Update test_globalpooling1d.py
jmduarte 6ce3244
Change project directory name
thesps 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
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,57 @@ | ||
import pytest | ||
from tensorflow.keras.models import Sequential | ||
from tensorflow.keras.layers import GlobalAveragePooling1D, GlobalMaxPooling1D | ||
import numpy as np | ||
import hls4ml | ||
|
||
|
||
in_shape = 8 | ||
in_feat = 4 | ||
atol = 5e-3 | ||
|
||
@pytest.fixture(scope='module') | ||
def data(): | ||
X = np.random.rand(100, in_shape, in_feat) | ||
return X | ||
|
||
|
||
@pytest.fixture(scope='module') | ||
def keras_model_max(): | ||
model = Sequential() | ||
model.add(GlobalMaxPooling1D(input_shape=(in_shape, in_feat))) | ||
model.compile() | ||
return model | ||
|
||
@pytest.fixture(scope='module') | ||
def keras_model_ave(): | ||
model = Sequential() | ||
model.add(GlobalAveragePooling1D(input_shape=(in_shape, in_feat))) | ||
model.compile() | ||
return model | ||
|
||
|
||
@pytest.mark.parametrize('io_type', ['io_parallel', 'io_stream']) | ||
@pytest.mark.parametrize('model_type', ['max', 'ave']) | ||
def test_global_pool1d(keras_model_max, keras_model_ave, data, model_type, io_type): | ||
if model_type == 'ave': | ||
model = keras_model_ave | ||
else: | ||
model = keras_model_max | ||
config = hls4ml.utils.config_from_keras_model(model, | ||
default_precision='ap_fixed<32,1>', | ||
granularity='name') | ||
if model_type == 'ave': | ||
config['LayerName']['global_average_pooling1d']['accum_t'] = 'ap_fixed<32,6>' | ||
|
||
hls_model = hls4ml.converters.convert_from_keras_model(model, | ||
hls_config=config, | ||
io_type=io_type, | ||
output_dir=f'hls4mlprj_globalplool1d_{model_type}_{io_type}', | ||
part='xcvu9p-flgb2104-2-i') | ||
hls_model.compile() | ||
|
||
|
||
# Predict | ||
y_keras = np.squeeze(model.predict(data)) | ||
y_hls = hls_model.predict(data) | ||
np.testing.assert_allclose(y_keras, y_hls, rtol=0, atol=atol, verbose=True) |
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.