tensorflow / tfjs

A WebGL accelerated JavaScript library for training and deploying ML models.
https://js.tensorflow.org
Apache License 2.0
18.38k stars 1.92k forks source link

Keras H5 to Tensorflowjs model conversion #7728

Open dubrovin-sudo opened 1 year ago

dubrovin-sudo commented 1 year ago

This template is for miscellaneous issues not covered by the other issue categories.

I used the following command: !tensorflowjs_converter \ --input_format=keras \ --output_format=tfjs_graph_model \ --saved_model_tags=serve \ --quantize_float16=* \ /content/gdrive/MyDrive/deeplav_v3_plus/files/mobilenetv3large_20.h5 \ /content/gdrive/MyDrive/customTF2/models_to_prod/mobilenetv3large_20_float16

My keras model- Link Colab notebook(i use dice as a loss and dice_coeff as a metric) - Link

The full conversion log is: WARNING:tensorflow:Compiled the loaded model, but the compiled metrics have yet to be built.model.compile_metricswill be empty until you train or evaluate the model. WARNING:absl:Found untraced functions such as _jit_compiled_convolution_op, _jit_compiled_convolution_op, _jit_compiled_convolution_op, _jit_compiled_convolution_op, _jit_compiled_convolution_op while saving (showing 5 of 46). These functions will not be directly callable after loading. WARNING:tensorflow:Didn't find expected Conv2D or DepthwiseConv2dNative input to 'StatefulPartitionedCall/model_1/batch_normalization_11/FusedBatchNormV3' WARNING:tensorflow:Didn't find expected Conv2D or DepthwiseConv2dNative input to 'StatefulPartitionedCall/model_1/batch_normalization_11/FusedBatchNormV3' WARNING:tensorflow:Didn't find expected Conv2D or DepthwiseConv2dNative input to 'StatefulPartitionedCall/model_1/batch_normalization_12/FusedBatchNormV3' WARNING:tensorflow:Didn't find expected Conv2D or DepthwiseConv2dNative input to 'StatefulPartitionedCall/model_1/batch_normalization_12/FusedBatchNormV3' WARNING:tensorflow:Didn't find expected Conv2D or DepthwiseConv2dNative input to 'StatefulPartitionedCall/model_1/batch_normalization_13/FusedBatchNormV3' WARNING:tensorflow:Didn't find expected Conv2D or DepthwiseConv2dNative input to 'StatefulPartitionedCall/model_1/batch_normalization_13/FusedBatchNormV3' Traceback (most recent call last): File "/usr/local/bin/tensorflowjs_converter", line 8, in <module> sys.exit(pip_main()) File "/usr/local/lib/python3.10/dist-packages/tensorflowjs/converters/converter.py", line 827, in pip_main main([' '.join(sys.argv[1:])]) File "/usr/local/lib/python3.10/dist-packages/tensorflowjs/converters/converter.py", line 831, in main convert(argv[0].split(' ')) File "/usr/local/lib/python3.10/dist-packages/tensorflowjs/converters/converter.py", line 817, in convert _dispatch_converter(input_format, output_format, args, quantization_dtype_map, File "/usr/local/lib/python3.10/dist-packages/tensorflowjs/converters/converter.py", line 508, in _dispatch_converter dispatch_keras_h5_to_tfjs_graph_model_conversion( File "/usr/local/lib/python3.10/dist-packages/tensorflowjs/converters/converter.py", line 148, in dispatch_keras_h5_to_tfjs_graph_model_conversion tf_saved_model_conversion_v2.convert_tf_saved_model( File "/usr/local/lib/python3.10/dist-packages/tensorflowjs/converters/tf_saved_model_conversion_v2.py", line 976, in convert_tf_saved_model _convert_tf_saved_model(output_dir, saved_model_dir=saved_model_dir, File "/usr/local/lib/python3.10/dist-packages/tensorflowjs/converters/tf_saved_model_conversion_v2.py", line 851, in _convert_tf_saved_model optimized_graph = optimize_graph(frozen_graph, signature, File "/usr/local/lib/python3.10/dist-packages/tensorflowjs/converters/tf_saved_model_conversion_v2.py", line 204, in optimize_graph raise ValueError('Unsupported Ops in the model after optimization\n' + ValueError: Unsupported Ops in the model after optimization _FusedBatchNormEx

gaikwadrahul8 commented 1 year ago

Hi, @dubrovin-sudo

Apologize for the delayed response and If I'm not wrong, It seems like there is Unsupported Ops in the model after optimization _FusedBatchNormEx and it seems like we haven't implemented this Op _FusedBatchNormEx yet so it's causing the issue to convert that model into TFJs so most probably this issue will be considered as Feature request for that Op if we haven't implemented that Op yet so we'll update you soon. Thank you for noticing this issue, I really appreciate your time and efforts.

I have tried to replicate the same issue from my end and got below warning , For your reference I have added output log below and here is gist file :

2023-06-01 10:58:01.172519: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT
WARNING:tensorflow:Compiled the loaded model, but the compiled metrics have yet to be built. `model.compile_metrics` will be empty until you train or evaluate the model.
WARNING:absl:Found untraced functions such as _jit_compiled_convolution_op, _jit_compiled_convolution_op, _jit_compiled_convolution_op, _jit_compiled_convolution_op, _jit_compiled_convolution_op while saving (showing 5 of 46). These functions will not be directly callable after loading.
WARNING:tensorflow:Didn't find expected Conv2D or DepthwiseConv2dNative input to 'StatefulPartitionedCall/model_1/batch_normalization_11/FusedBatchNormV3'
WARNING:tensorflow:Didn't find expected Conv2D or DepthwiseConv2dNative input to 'StatefulPartitionedCall/model_1/batch_normalization_11/FusedBatchNormV3'
WARNING:tensorflow:Didn't find expected Conv2D or DepthwiseConv2dNative input to 'StatefulPartitionedCall/model_1/batch_normalization_12/FusedBatchNormV3'
WARNING:tensorflow:Didn't find expected Conv2D or DepthwiseConv2dNative input to 'StatefulPartitionedCall/model_1/batch_normalization_12/FusedBatchNormV3'
WARNING:tensorflow:Didn't find expected Conv2D or DepthwiseConv2dNative input to 'StatefulPartitionedCall/model_1/batch_normalization_13/FusedBatchNormV3'
WARNING:tensorflow:Didn't find expected Conv2D or DepthwiseConv2dNative input to 'StatefulPartitionedCall/model_1/batch_normalization_13/FusedBatchNormV3'

Thank you!

edge7Lux commented 6 months ago

any update on this?

edge7Lux commented 3 months ago

up

edge7Lux commented 3 months ago

Hi @pyu10055 do we have any news on this? Thanks