|
| 1 | +from tensorflow import keras |
| 2 | + |
| 3 | +from hls4ml.converters import convert_from_keras_model |
| 4 | + |
| 5 | + |
| 6 | +def test_repack_precision(): |
| 7 | + inp = keras.Input(shape=(3, 3), name='inp') |
| 8 | + out = keras.layers.Reshape((3, 3), name='reshape')(inp) |
| 9 | + out = keras.layers.Conv1D(2, 2, name='conv')(out) |
| 10 | + model = keras.Model(inp, out) |
| 11 | + |
| 12 | + layer_conf = { |
| 13 | + 'inp': {'Precision': 'fixed<20,10>'}, |
| 14 | + 'reshape': {'Precision': 'fixed<20,10>'}, |
| 15 | + 'conv': {'Precision': 'fixed<20,10>'}, |
| 16 | + } |
| 17 | + |
| 18 | + hls_config = {'Model': {'Precision': 'fixed<2,1>', 'ReuseFactor': 1}, 'LayerName': layer_conf} |
| 19 | + |
| 20 | + # Repack only happens in io_stream |
| 21 | + model_hls = convert_from_keras_model(model, hls_config=hls_config, io_type='io_stream') |
| 22 | + assert 'repack_reshape' in model_hls.graph, 'repack_reshape not found in graph' |
| 23 | + repack_precision = model_hls.graph['repack_reshape'].attributes['result_t'].precision |
| 24 | + assert repack_precision.integer == 10, 'Precision mismatch' |
| 25 | + assert repack_precision.fractional == 10, 'Precision mismatch' |
| 26 | + assert repack_precision.width == 20, 'Precision mismatch' |
| 27 | + assert repack_precision.signed is True, 'Precision mismatch' |
0 commit comments