Xilinx / Vitis-AI-Tutorials

MIT License
358 stars 144 forks source link

Tensor flow 2 Quantization #66

Open AfifaIshtiaq opened 2 years ago

AfifaIshtiaq commented 2 years ago

Hi I have the following error while quantization. I wrote the following script:

from future import absolute_import from future import division from future import print_function

import numpy as np

from tensorflow.python.keras.utils.data_utils import get_file from tensorflow.python.util.tf_export import keras_export

with np.load('data_capture_qpsk/frame_esn0_0-0.npz') as f: rx_data_input_real, rx_data_input_imag = f['rx_data_map_real'], f['rx_data_map_imag'] tx_pilot_input_real, tx_pilot_input_imag = f['tx_pilot_map_real'], f['tx_pilot_map_imag'] raw_ch_est_input_real, raw_ch_est_input_imag = f['raw_ch_map_real'], f['raw_ch_map_imag']

Concatenate real and imaginary channel

rx_data_input = np.concatenate((rx_data_input_real, rx_data_input_imag), axis=-1) tx_pilot_input = np.concatenate((tx_pilot_input_real, tx_pilot_input_imag), axis=-1) raw_ch_est_input = np.concatenate((raw_ch_est_input_real, raw_ch_est_input_imag), axis=-1)

inputs = [rx_data_input, tx_pilot_input, raw_ch_est_input]

from tensorflow import keras float_model = keras.models.load_model('float/deep_rx.h5') from tensorflow_model_optimization.quantization.keras import vitis_quantize quantizer = vitis_quantize.VitisQuantizer(float_model) quantized_model = quantizer.quantize_model(calib_dataset=inputs, calib_step=100, calib_batch_size=1)

Response

(vitis-ai-tensorflow2) Vitis-AI /workspace/models/ChEstModel > python3 Deep_RX_ptq.py 2022-05-04 08:28:37.972104: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /opt/xilinx/xrt/lib:/usr/lib:/usr/lib/x86_64-linux-gnu:/usr/local/lib:/opt/vitis_ai/conda/envs/vitis-ai-tensorflow/lib 2022-05-04 08:28:37.972124: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine. 2022-05-04 08:28:39.737146: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcuda.so.1'; dlerror: libcuda.so.1: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /opt/xilinx/xrt/lib:/usr/lib:/usr/lib/x86_64-linux-gnu:/usr/local/lib:/opt/vitis_ai/conda/envs/vitis-ai-tensorflow/lib 2022-05-04 08:28:39.737213: W tensorflow/stream_executor/cuda/cuda_driver.cc:269] failed call to cuInit: UNKNOWN ERROR (303) 2022-05-04 08:28:39.737257: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:156] kernel driver does not appear to be running on this host (dre-elbe-s04): /proc/driver/nvidia/version does not exist 2022-05-04 08:28:39.737915: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 FMA To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags. Traceback (most recent call last): File "Deep_RX_ptq.py", line 23, in float_model = keras.models.load_model('float/deep_rx.h5') File "/opt/vitis_ai/conda/envs/vitis-ai-tensorflow2/lib/python3.7/site-packages/keras/saving/save.py", line 201, in load_model compile) File "/opt/vitis_ai/conda/envs/vitis-ai-tensorflow2/lib/python3.7/site-packages/keras/saving/hdf5_format.py", line 199, in load_model_from_hdf5 training_config, custom_objects), from_serialized=True) File "/opt/vitis_ai/conda/envs/vitis-ai-tensorflow2/lib/python3.7/site-packages/keras/saving/saving_utils.py", line 202, in compile_args_from_training_config optimizer = optimizers.deserialize(optimizer_config) File "/opt/vitis_ai/conda/envs/vitis-ai-tensorflow2/lib/python3.7/site-packages/keras/optimizers.py", line 99, in deserialize printable_module_name='optimizer') File "/opt/vitis_ai/conda/envs/vitis-ai-tensorflow2/lib/python3.7/site-packages/keras/utils/generic_utils.py", line 660, in deserialize_keras_object config, module_objects, custom_objects, printable_module_name) File "/opt/vitis_ai/conda/envs/vitis-ai-tensorflow2/lib/python3.7/site-packages/keras/utils/generic_utils.py", line 561, in class_and_config_for_serialized_keras_object .format(printable_module_name, class_name)) ValueError: Unknown optimizer: Addons>LAMB. 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

bhargavin1872008 commented 1 year ago

when running the requirements.txt of keras-yolov3-modelset -i 'm getting error for coremltools.it is showing like "couldn't find a version that satisfies the requirement tensorflow<=1.14 and tensorflow >=1.5(from tfcoremltools -r requirements.txt).(from version :2.2.0,2.2..1, 2.2.2, ...2.7.0rc0,2.7.0.rc1............) like this .can someone help me regarding this. Also ,i have a doubt .can we use ubuntu 20.04 ,cuda 11.7 ,cudnn 8.4.0 for this project. or have to use ubuntu 18.04,cuda 10.0 only which only works.please help me regarding this,i have less time in my hand.