-
Notifications
You must be signed in to change notification settings - Fork 462
Make binary CNN match between Keras and hls4ml #804
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
19 commits
Select commit
Hold shift + click to select a range
30eb824
make normalize_binary_tanh match qkeras
jmitrevs c813eec
make normalize_binary_tanh match qkeras (stream)
jmitrevs 59149b3
Make maxpooling copy over XnorPrecision
jmitrevs 4840388
enable actual checking
jmitrevs 5e5d705
Fix for io-parallel latency for Vivado and Vitis backends
jmitrevs c1cdbee
make same > to >= change for quartus as for vivado
jmitrevs a5dfaaa
fix normalize_tanh for io_stream
jmitrevs eacabe0
remove softmax from test since that complicates the test and it's not…
jmitrevs ed1e0ba
Merge branch 'main' into binary_match
jmitrevs 1aa3cb6
fix assertion limit for RF for im2col implementation
jmitrevs 56f08e1
fix both_binary product for Quartus
jmitrevs 5874bef
turn off winograd in tests since it doesn't support binary
jmitrevs 2886a31
remove TODO that is done
jmitrevs f498be7
Merge branch 'main' into binary_match
jmitrevs 96da216
increase size of accumulator in pytest
jmitrevs b57526a
update test_binary with suggestions, without adding bias
jmitrevs 8e879be
Add bias to CNN where both the input and weights are not binary
jmitrevs 2e03dbf
change the default precision of the test
jmitrevs 9c1d905
Merge branch 'main' into binary_match
jmitrevs 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from hls4ml.model.layers import GlobalPooling1D, GlobalPooling2D, Pooling1D, Pooling2D | ||
from hls4ml.model.optimizer import OptimizerPass | ||
from hls4ml.model.types import XnorPrecisionType | ||
|
||
|
||
class XnorPooling(OptimizerPass): | ||
''' | ||
For correct behavior, for MaxPooling and similar, for XnorPrecisionType, have to propagate | ||
the type to the output. | ||
''' | ||
|
||
def match(self, node): | ||
if isinstance(node, (Pooling1D, Pooling2D, GlobalPooling1D, GlobalPooling2D)) and node.get_attr('pool_op') == 'Max': | ||
return isinstance(node.get_input_variable().type.precision, XnorPrecisionType) and not isinstance( | ||
node.get_output_variable().type.precision, XnorPrecisionType | ||
) | ||
return False | ||
|
||
def transform(self, model, node): | ||
outvar = node.get_output_variable() | ||
outvar.type.precision = XnorPrecisionType() | ||
return True |
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
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
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.