Skip to content
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

Tutorial file for Convolutional Networks #14

Closed
rajeshpandit107 opened this issue Apr 29, 2021 · 13 comments
Closed

Tutorial file for Convolutional Networks #14

rajeshpandit107 opened this issue Apr 29, 2021 · 13 comments
Assignees

Comments

@rajeshpandit107
Copy link

Please post a tutorial for cnn.

@rajeshpandit107
Copy link
Author

Hi,
When I run synthesis of CNN, the step where the tool starts converting partioning array.v in 1 dimenstion completely, RAM usage into the systems increase drastically and it fills up the entire RAM of 16 GB in my PC, after that vivado_hls automatically gets killed. Is there any workaround for this ? @thaarres @thesps @vloncar, Please let me know.
vivado_hls.log

@thaarres
Copy link
Contributor

Hi @rajeshpandit107! Can you have a look through the notebook here part6_cnns.ipynb, specifically the section "CNNs in hls4ml", and make sure you are using the correct configuration settings?

@ynozik
Copy link

ynozik commented Jul 9, 2021

@thaarres Thanks a lot for the cnn tutorial. When I try to run the notebook I run into an error on the codeblock under "CNNs in hls4ml" (where the trained models are loaded and strip_pruning is called).

The error is:


ValueError Traceback (most recent call last)
in
13 'QDense': QDense,
14 'QConv2DBatchnorm': QConv2DBatchnorm,
---> 15 'QActivation': QActivation})
16 qmodel = strip_pruning(qmodel)

~/.local/lib/python3.6/site-packages/tensorflow/python/keras/saving/save.py in load_model(filepath, custom_objects, compile, options)
200 (isinstance(filepath, h5py.File) or h5py.is_hdf5(filepath))):
201 return hdf5_format.load_model_from_hdf5(filepath, custom_objects,
--> 202 compile)
203
204 filepath = path_to_string(filepath)

[... cut out intermediate calls ...]

~/.local/lib/python3.6/site-packages/tensorflow/python/keras/utils/generic_utils.py in class_and_config_for_serialized_keras_object(config, module_objects, custom_objects, printable_module_name)
559 'https://www.tensorflow.org/guide/keras/save_and_serialize'
560 '#registering_the_custom_object for details.'
--> 561 .format(printable_module_name, class_name))
562
563 cls_config = config['config']

ValueError: Unknown config_item: quantized_bits. Please ensure this object is passed to the custom_objects argument. See https://www.tensorflow.org/guide/keras/save_and_serialize#registering_the_custom_object for details.


I was able to run all cells before this successfully without modification, the only difference being I trained for fewer epochs to save time. The cell that causes the error is also marked uneditable, not sure why; I made it modifiable to try to pass quantized_bits as an activation but that didn't seem to work. Any idea what the issue might be?

@ynozik
Copy link

ynozik commented Jul 9, 2021

Sorry - seems that was likely fixed by adding an entry of 'quantized_bits': quantized_bits to custom_objects. I'm not completely sure if it did since I now get an error when trying to run the line hls_config_q = hls4ml.utils.config_from_keras_model(qmodel, granularity='name'), with error:


Exception Traceback (most recent call last)
in
4 hls4ml.model.optimizer.OutputRoundingSaturationMode.saturation_mode = 'AP_SAT'
5
----> 6 hls_config_q = hls4ml.utils.config_from_keras_model(qmodel, granularity='name')
7 hls_config_q['Model']['ReuseFactor'] = 1
8 hls_config['Model']['Precision'] = 'ap_fixed<16,6>'

~/.local/lib/python3.6/site-packages/hls4ml/utils/config.py in config_from_keras_model(model, granularity, default_precision, default_reuse_factor)
127 for keras_layer in keras_layer_config:
128 if keras_layer['class_name'] not in supported_layers:
--> 129 raise Exception('ERROR: Unsupported layer type: {}'.format(keras_layer['class_name']))
130 if keras_layer['class_name'] in skip_layers:
131 continue

Exception: ERROR: Unsupported layer type: QConv2DBatchnorm


The layer seems to use use_bias=True when the qKeras model is initially defined (again I didn't modify any code except for fewer training epochs), so not sure why that would be, maybe unless my adding quantized_bits earlier messed something up - I'm not too familiar with the qKeras / hls4ml workings, though.

@thaarres
Copy link
Contributor

thaarres commented Jul 9, 2021 via email

@ynozik
Copy link

ynozik commented Jul 9, 2021

Hi @thaarres, running pip show hls4ml does show that I'm on version 0.5.0. To clarify, 0.5.0 is the latest stable release but doesn't reflect the most recent layer compatibilities?

I haven't been using a conda environment, so I suppose I should probably try that.

@ynozik
Copy link

ynozik commented Jul 9, 2021

Hi @thaarres - apologies for the repeated mentions. I revisited the notebook in the proper conda environment and was able to synthesize the default models (I did have to reduce the number of filters/neurons per layer to reduce the memory usage on my machine). However, there seems to be some error with modifying the models to use the resource strategy, since all my attempts to use it have resulted in the following:


***** C/RTL SYNTHESIS *****
INFO: [SCHED 204-61] Option 'relax_ii_for_timing' is enabled, will increase II to preserve clock frequency constraints.
INFO: [HLS 200-10] Analyzing design file 'firmware/myproject.cpp' ...
WARNING: [HLS 214-114] Since the only kind of statements allowed in a dataflow region are variable declarations and function calls, the compiler may not be able to correctly handle the region: firmware/nnet_utils/nnet_dense_latency.h:64:9
WARNING: [HLS 214-104] Only for-loops and functions support the dataflow: firmware/nnet_utils/nnet_dense_latency.h:76:9
WARNING: [HLS 214-114] Since the only kind of statements allowed in a dataflow region are variable declarations and function calls, the compiler may not be able to correctly handle the region: firmware/myproject.cpp:35:2
WARNING: [HLS 200-471] Dataflow form checks found 3 issue(s) in file firmware/myproject.cpp
ERROR: [HLS 200-70] '#pragma HLS STABLE variable=&layer2_out' is not a valid pragma.
ERROR: [HLS 200-70] '#pragma HLS STABLE variable=&layer5_out' is not a valid pragma.
ERROR: [HLS 200-70] '#pragma HLS STABLE variable=&layer6_out' is not a valid pragma.
ERROR: [HLS 200-70] '#pragma HLS STABLE variable=&layer7_out' is not a valid pragma.
ERROR: [HLS 200-70] '#pragma HLS STABLE variable=&layer10_out' is not a valid pragma.
ERROR: [HLS 200-70] '#pragma HLS STABLE variable=&layer11_out' is not a valid pragma.
ERROR: [HLS 200-70] '#pragma HLS STABLE variable=&layer12_out' is not a valid pragma.
ERROR: [HLS 200-70] '#pragma HLS STABLE variable=&layer15_out' is not a valid pragma.
ERROR: [HLS 200-70] '#pragma HLS STABLE variable=&layer16_out' is not a valid pragma.
ERROR: [HLS 200-70] '#pragma HLS STABLE variable=&layer17_out' is not a valid pragma.
ERROR: [HLS 200-70] '#pragma HLS STABLE variable=&layer20_out' is not a valid pragma.
ERROR: [HLS 200-70] '#pragma HLS STABLE variable=&layer21_out' is not a valid pragma.
ERROR: [HLS 200-70] '#pragma HLS STABLE variable=&layer24_out' is not a valid pragma.
ERROR: [HLS 200-70] '#pragma HLS STABLE variable=&layer25_out' is not a valid pragma.
Pragma processor failed:
while executing
"source [lindex $::argv 1] "
("uplevel" body line 1)
invoked from within
"uplevel #0 { source [lindex $::argv 1] } "


This appears to happen regardless of whether I set the overall model strategy to resource or on a per-layer basis. It also seems to happen regardless of the associated ReuseFactor. IOType is still set to io_stream, of course.

Although I have no idea if it's related, I tried to omit setting the output_softmax strategy to Stable, but that doesn't seem to have an effect either.

Keeping the latency strategy while increasing the ReuseFactor results in successful synthesis, but without too much of an effect on the results. I'm not sure what the expected synthesis behavior is of hls4ml is when you specify high reuse with a latency strategy (e.g. can it mostly ignore the ReuseFactor or does ReuseFactor take priority).

Do you happen to know if specifying the resource strategy requires any additional modifications besides simply changing Strategy?

Thanks very much.

@thaarres
Copy link
Contributor

Hi @ynozik !
Sorry for the delay in following up on this! I saw you submitted an issue to the main hls4ml repository as well, did you pin this error down to the Vivado version?

@ynozik
Copy link

ynozik commented Jul 16, 2021

Hi @thaarres, yes, that was resolved by changing the Vivado version.

@lclee0577
Copy link

Hi @rajeshpandit107! Can you have a look through the notebook here part6_cnns.ipynb, specifically the section "CNNs in hls4ml", and make sure you are using the correct configuration settings?

output

Hi @thaarres ,in part6_cnns.inpy, the accuracy was quite low after convert to hls model(about 80% -> 20%).
Since the flatten layer was skipped, the output shape stuck with (2,2,*) .
I added another MaxPooling2D layer before Flatten layer may solve the problem. But it still confuse me why the Flatten layer was skipped.

@vloncar
Copy link

vloncar commented Aug 15, 2021

Fixed in fastmachinelearning/hls4ml#378

@lclee0577
Copy link

Fixed in fastmachinelearning/hls4ml#378

sorry ,I just reinstall the hls4ml,and thanks a lot !

@thesps
Copy link
Collaborator

thesps commented Nov 12, 2021

The CNN tutorial notebook is now online with the new hls4ml release: closing this issue

@thesps thesps closed this as completed Nov 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants