sony / model_optimization

Model Compression Toolkit (MCT) is an open source project for neural network model optimization under efficient, constrained hardware. This project provides researchers, developers, and engineers advanced quantization and compression tools for deploying state-of-the-art neural networks.
https://sony.github.io/model_optimization/
Apache License 2.0
300 stars 49 forks source link

tensorboard writer error #1055

Closed YoshikiKato0220 closed 4 months ago

YoshikiKato0220 commented 4 months ago

Issue Type

Bug

Source

source

MCT Version

1.11.0

OS Platform and Distribution

Ubuntu 18.04

Python version

3.10.14

Describe the issue

Hello.
I tried to convert yolov8n in MCT with tensorboard.
When I called mct.ptq.keras_post_training_quantization_experimental,
I got the following error,
AttributeError: 'NoneType' object has no attribute '__name__'. Did you mean: '__ne__'?

I wonder if it would be possible to tell me how to address this error ?

Expected behaviour

I expect conversion succeed.

Code to reproduce the issue

docker image: ultralytics/ultralytics:latest

git clone https://github.com/sony/model_optimization.git local_mct
cd local_mct
git checkout refs/tags/v1.11.0
pip install -r requirements.txt

[base code]
https://github.com/sony/model_optimization/blob/v1.11.0/tutorials/notebooks/example_keras_yolov8n.ipynb

[add] 
mct.set_log_folder('./loggerv1_11')

[modify] I think tensorboard_writer.py don't support tf.image.combined_non_max_suppression
model = Model(model.input, outputs, name='yolov8n')
↓
model = Model(model.input, model.output, name='yolov8n')

Log output

Traceback (most recent call last):
  File "/usr/src/ultralytics/example_keras_yolov8n_v111_board.py", line 136, in <module>
    quant_model, _ = mct.ptq.keras_post_training_quantization_experimental(model,
  File "/usr/src/ultralytics/../local_mct_v1_11/model_compression_toolkit/ptq/keras/quantization_facade.py", line 139, in keras_post_training_quantization_experimental
    tg, bit_widths_config, _ = core_runner(in_model=in_model,
  File "/usr/src/ultralytics/../local_mct_v1_11/model_compression_toolkit/core/runner.py", line 99, in core_runner
    tg = quantization_preparation_runner(graph=graph,
  File "/usr/src/ultralytics/../local_mct_v1_11/model_compression_toolkit/core/quantization_prep_runner.py", line 119, in quantization_preparation_runner
    tb_w.add_graph(transformed_graph, 'after_shift_negative_correction')
  File "/usr/src/ultralytics/../local_mct_v1_11/model_compression_toolkit/core/common/visualization/tensorboard_writer.py", line 308, in add_graph
    main_node_def.device = n.type.__name__  # For coloring different ops differently
AttributeError: 'NoneType' object has no attribute '__name__'. Did you mean: '__ne__'?
YoshikiKato0220 commented 4 months ago

This error doesn't occur in MCT v2.0. But in MCT v2.0, I have a different error. I'll write in #1056

YoshikiKato0220 commented 4 months ago

in tesorboard_writer.py, add_graph

ipdb> node_sort[0] InputLayer:input_1 ipdb> node_sort[1] ZeroPadding2D:zero_padding2d ipdb> node_sort[2] Conv2D:model.0.conv_bn ipdb> node_sort[3] swish:tf.nn.silu ipdb> node_sort[4] AttributeError: 'NoneType' object has no attribute 'name'. Did you mean: 'ne'? ipdb> node_sort[5] AttributeError: 'NoneType' object has no attribute 'name'. Did you mean: 'ne'? ipdb> node_sort[6] Conv2D:model.1.conv_bn

reuvenperetz commented 4 months ago

Hi @YoshikiKato0220, We reproduced an issue with logging this layer, but a different error. A fix was merged, and the tutorial runs successfully on colab with logging. Please retry it and see if you encounter any issues.

https://colab.research.google.com/github/sony/model_optimization/blob/main/tutorials/notebooks/mct_features_notebooks/keras/example_keras_yolov8n.ipynb

Thanks

YoshikiKato0220 commented 4 months ago

Hi @reuvenperetz , In this colab (mct is latest version), I confirmed it works. Thanks