I’m trying to quantize a ViT network.
I found the onnx file in the model zoo repository.
The performance of the original network is ok , but not as high as expected: Top1 is 61% on Imagenet1K (80% expected)
When I run the runner.optimize(calib_dataset)
, the performance drops to 3.9%. So I try the noise analysis:
runner.analyze_noise(image_dataset, batch_size=2, data_count=32)
There, the program crashes, with the following traceback:
[info] Starting Layer Noise Analysis
Full Quant Analysis: 6%|███▎ | 1/16 [00:02<00:32, 2.17s/iterations]Traceback (most recent call last):
File "/local/workspace/FA/tests_quant/test.py", line 90, in <module>
runner.analyze_noise(image_dataset, batch_size=2, data_count=nimg)
File "/local/workspace/hailo_virtualenv/lib/python3.10/site-packages/hailo_sdk_common/states/states.py", line 16, in wrapped_func
return func(self, *args, **kwargs)
File "/local/workspace/hailo_virtualenv/lib/python3.10/site-packages/hailo_sdk_client/runner/client_runner.py", line 2072, in analyze_noise
self._analyze_noise(
File "/local/workspace/hailo_virtualenv/lib/python3.10/site-packages/hailo_sdk_common/states/states.py", line 16, in wrapped_func
return func(self, *args, **kwargs)
File "/local/workspace/hailo_virtualenv/lib/python3.10/site-packages/hailo_sdk_client/runner/client_runner.py", line 2094, in _analyze_noise
return self._sdk_backend.run_layer_analysis_tool(data, data_count, batch_size, analyze_mode, **kwargs)
File "/local/workspace/hailo_virtualenv/lib/python3.10/site-packages/hailo_sdk_client/sdk_backend/sdk_backend.py", line 1078, in run_layer_analysis_tool
analyzer.run()
File "/local/workspace/hailo_virtualenv/lib/python3.10/site-packages/hailo_model_optimization/algorithms/optimization_algorithm.py", line 54, in run
return super().run()
File "/local/workspace/hailo_virtualenv/lib/python3.10/site-packages/hailo_model_optimization/algorithms/algorithm_base.py", line 150, in run
self._run_int()
File "/local/workspace/hailo_virtualenv/lib/python3.10/site-packages/hailo_model_optimization/algorithms/hailo_layer_noise_analysis.py", line 86, in _run_int
self.analyze_full_quant_net()
File "/local/workspace/hailo_virtualenv/lib/python3.10/site-packages/hailo_model_optimization/algorithms/hailo_layer_noise_analysis.py", line 208, in analyze_full_quant_net
lat_model.predict_on_batch(inputs)
File "/local/workspace/hailo_virtualenv/lib/python3.10/site-packages/keras/engine/training.py", line 2603, in predict_on_batch
outputs = self.predict_function(iterator)
File "/local/workspace/hailo_virtualenv/lib/python3.10/site-packages/tensorflow/python/util/traceback_utils.py", line 153, in error_handler
raise e.with_traceback(filtered_tb) from None
File "/tmp/__autograph_generated_filey5gzfqgw.py", line 15, in tf__predict_function
retval_ = ag__.converted_call(ag__.ld(step_function), (ag__.ld(self), ag__.ld(iterator)), None, fscope)
File "/local/workspace/hailo_virtualenv/lib/python3.10/site-packages/keras/engine/training.py", line 2155, in step_function
outputs = model.distribute_strategy.run(run_step, args=(data,))
File "/local/workspace/hailo_virtualenv/lib/python3.10/site-packages/keras/engine/training.py", line 2143, in run_step
outputs = model.predict_step(data)
File "/local/workspace/hailo_virtualenv/lib/python3.10/site-packages/keras/engine/training.py", line 2111, in predict_step
return self(x, training=False)
File "/local/workspace/hailo_virtualenv/lib/python3.10/site-packages/keras/utils/traceback_utils.py", line 70, in error_handler
raise e.with_traceback(filtered_tb) from None
File "/tmp/__autograph_generated_filevaxh213w.py", line 188, in tf__call
ag__.for_stmt(ag__.converted_call(ag__.ld(self)._model.flow.toposort, (), None, fscope), None, loop_body_5, get_state_9, set_state_9, (), {'iterate_names': 'lname'})
File "/tmp/__autograph_generated_filevaxh213w.py", line 167, in loop_body_5
ag__.if_stmt(ag__.not_(continue__1), if_body_3, else_body_3, get_state_8, set_state_8, (), 0)
File "/tmp/__autograph_generated_filevaxh213w.py", line 163, in if_body_3
ag__.for_stmt(ag__.converted_call(ag__.ld(enumerate), (ag__.converted_call(ag__.ld(zip), (ag__.ld(output_native), ag__.ld(output_numeric), ag__.ld(output_partial_numeric)), None, fscope),), None, fscope), None, loop_body_4, get_state_7, set_state_7, (), {'iterate_names': '(i, (native, numeric, partial_numeric))'})
File "/tmp/__autograph_generated_filevaxh213w.py", line 162, in loop_body_4
ag__.for_stmt(ag__.ld(metrics), None, loop_body_3, get_state_6, set_state_6, (), {'iterate_names': 'metric'})
File "/tmp/__autograph_generated_filevaxh213w.py", line 161, in loop_body_3
ag__.converted_call(ag__.ld(metric).update_state, (ag__.ld(native), ag__.ld(numeric)), dict(partial_numeric=ag__.ld(partial_numeric)), fscope)
File "/tmp/__autograph_generated_file0p01gogs.py", line 10, in tf__update_state
ag__.converted_call(ag__.ld(self).noise_energy.assign_add, (ag__.converted_call(ag__.ld(tf).reduce_mean, ((ag__.ld(native) - ag__.ld(numeric)) ** 2,), None, fscope),), None, fscope)
ValueError: in user code:
File "/local/workspace/hailo_virtualenv/lib/python3.10/site-packages/keras/engine/training.py", line 2169, in predict_function *
return step_function(self, iterator)
File "/local/workspace/hailo_virtualenv/lib/python3.10/site-packages/keras/engine/training.py", line 2155, in step_function **
outputs = model.distribute_strategy.run(run_step, args=(data,))
File "/local/workspace/hailo_virtualenv/lib/python3.10/site-packages/keras/engine/training.py", line 2143, in run_step **
outputs = model.predict_step(data)
File "/local/workspace/hailo_virtualenv/lib/python3.10/site-packages/keras/engine/training.py", line 2111, in predict_step
return self(x, training=False)
File "/local/workspace/hailo_virtualenv/lib/python3.10/site-packages/keras/utils/traceback_utils.py", line 70, in error_handler
raise e.with_traceback(filtered_tb) from None
File "/tmp/__autograph_generated_filevaxh213w.py", line 188, in tf__call
ag__.for_stmt(ag__.converted_call(ag__.ld(self)._model.flow.toposort, (), None, fscope), None, loop_body_5, get_state_9, set_state_9, (), {'iterate_names': 'lname'})
File "/tmp/__autograph_generated_filevaxh213w.py", line 167, in loop_body_5
ag__.if_stmt(ag__.not_(continue__1), if_body_3, else_body_3, get_state_8, set_state_8, (), 0)
File "/tmp/__autograph_generated_filevaxh213w.py", line 163, in if_body_3
ag__.for_stmt(ag__.converted_call(ag__.ld(enumerate), (ag__.converted_call(ag__.ld(zip), (ag__.ld(output_native), ag__.ld(output_numeric), ag__.ld(output_partial_numeric)), None, fscope),), None, fscope), None, loop_body_4, get_state_7, set_state_7, (), {'iterate_names': '(i, (native, numeric, partial_numeric))'})
File "/tmp/__autograph_generated_filevaxh213w.py", line 162, in loop_body_4
ag__.for_stmt(ag__.ld(metrics), None, loop_body_3, get_state_6, set_state_6, (), {'iterate_names': 'metric'})
File "/tmp/__autograph_generated_filevaxh213w.py", line 161, in loop_body_3
ag__.converted_call(ag__.ld(metric).update_state, (ag__.ld(native), ag__.ld(numeric)), dict(partial_numeric=ag__.ld(partial_numeric)), fscope)
File "/tmp/__autograph_generated_file0p01gogs.py", line 10, in tf__update_state
ag__.converted_call(ag__.ld(self).noise_energy.assign_add, (ag__.converted_call(ag__.ld(tf).reduce_mean, ((ag__.ld(native) - ag__.ld(numeric)) ** 2,), None, fscope),), None, fscope)
ValueError: Exception encountered when calling layer 'lat_model_1' (type LATModel).
in user code:
File "/local/workspace/hailo_virtualenv/lib/python3.10/site-packages/hailo_model_optimization/algorithms/lat_utils/lat_model.py", line 392, in call *
metric.update_state(native, numeric, partial_numeric=partial_numeric)
File "/local/workspace/hailo_virtualenv/lib/python3.10/site-packages/hailo_model_optimization/algorithms/lat_utils/lat_model.py", line 22, in update_state *
self.noise_energy.assign_add(tf.reduce_mean((native - numeric) ** 2))
ValueError: Dimensions must be equal, but are 768 and 780 for '{{node lat_model_1/sub_45}} = Sub[T=DT_FLOAT](lat_model_1/conv_slice2/act_op/Identity, lat_model_1/conv_slice2/output_op/mul)' with input shapes: [2,1,197,768], [2,1,197,780].
Call arguments received by layer 'lat_model_1' (type LATModel):
• inputs=tf.Tensor(shape=(2, 224, 224, 3), dtype=float32)
Full Quant Analysis: 6%|▋ | 1/16 [00:07<01:57, 7.81s/iterations]
Can anyone help?
Thank you.