Error in converting SageMaker XGBoost model to ONNX model - python

I'm trying to convert a SageMaker XGBoost model to ONNX, in order to use the ONNX model in .Net application using ML.NET. I've tried to convert the model using winmltools and onnxmltools but both tools are returned similar error.
There is a good resource to use machine learning in business area. I've tried Using Machine Learning to Improve Sales in SageMaker to create the model and then convert the model to ONNX model. The example is working well in SageMaker.
After running the example, I got a model and the type of the model is sagemaker.estimator.Estimator. I've tried to convert the model by using winmltools and onnxmltools. But both are returned same error.
ValueError: No proper operator name found for '<class 'sagemaker.estimator.Estimator'>'
I've tried to follow Convert ML models to ONNX with WinMLTools and ONNXMLTools enables conversion of models to ONNX to convert the SageMaker model to ONNX model.
After that, I used xgb.create_model() command to create SageMaker model. Then used the tools to convert the model to ONNX. but no luck. I got same error this time. Just the model is different.
ValueError: No proper operator name found for '<class 'sagemaker.model.Model'>'
Then I load the model using pickle and tried to convert the model. I got same error, just the model is different.
ValueError: No proper operator name found for '<class 'xgboost.core.Booster'>'
At this moment, I have no idea about the issues. How should I solve the issues. I've attached the Improve Sales Classification to ONNX notebook file for reference.
Could you please take a look at the issues and let me know a way to solve the issues?
Thanks in advance!

Related

Converting onnx model to sklearn

I Originally trained the model with sklearn, which was then converted to onnx. I now want to get the Sklearn model back. The only related thing I can find online is converting onnx to tf-lite.
Thanks in advance!

Couldn't convert pytorch model to ONNX

I used this repo : https://github.com/Turoad/lanedet
to convert a pytorch model that use mobilenetv2 as backbone To ONNX but I didn't succeeded.
i got a Runtime error that says:
RuntimeError: Exporting the operator eye to ONNX opset version 12 is
not supported. Please open a bug to request ONNX export support for
the missing operator.
it's really disappointing, looking to the good result that this model gives and the quick performance that it provides,
is there any way that I can fix this bug? because I need to convert it to ONNX and then to TF lite model to use it in Android App
I will provide the pretrained model that I have used and the way that I follow in converting..
Thank you so much for helping!
my colab notebook:
https://colab.research.google.com/drive/18udIh8tNJvti7jKmR4jRaRO-oYDgRmvA?usp=sharing
the pretrained model that I use:
https://drive.google.com/file/d/1o3-BgLIQesurIyDCKGliqbo2inUA5cPw/view?usp=sharing
Use torch>=1.7.0 to convert the model, because operation Eye is added.

Keras ASR model validation steps

I am a newbie in Machine learning. I would like to design a model of ASR(Automatic speech recognition), so I came across the following link is:
https://keras.io/examples/audio/transformer_asr/
I am able to understand the training model concept. I also saved the above model using the following code:
model.save_weights('data_sa',save_format='hdf5')
then I load it again using:
model.load_weights('/content/data_sa')
Now, I would like to predict the model, by giving the validation data set. But I am facing an issue.
I am using the following step for prediction:
model.predict(np.array(val_ds)) #this is the validation dataset
It is giving an error of tensor conversion.
I tried to search the possible solution to this step but couldn't able to find the it.
tf.cast() and tf.to_float() are TensorFlow functions, so you'd get them using import tensorflow as tf.

Tensorflow: Convert Save_mode.pb to a freeze_graph.pb with Tensorflow 2.5.0

I recently trained my own custom object detector model using mobilenetssd as my pretrained model. I have been following this tutorial to train my model, and used exporter_main_v2.py program in TensorFlow/models/research/object_detection/ to generate my save_model.pb file. I would like to use OpenCV DNN module where it requires a frozen model and the pbtext. In order to generate the pbtext file, I would need to convert it from the frozen_graph.pb. I would like to convert my save_model.pb to a frozen_graph.pb file, but it looks like freezing graphs has been deprecated in tensorflow 2.X. I tried this solution but I get this error:
AttributeError: '_UserObject' object has no attribute 'inputs'
Does anyone have recommendations or solutions on how I can covert my save_model.pb to a freeze_graph.pb? I would really appreciate the help!

Can I convert all the tensorflow slim models to tflite?

I'm training tensorflow slim based models for image classification on a custom dataset. Before I invest a lot of time training such huge a dataset, I wanted to know whether or not can I convert all the models available in the slim model zoo to tflite format.
Also, I know that I can convert my custom slim-model to a frozen graph. It is the step after this which I'm worried about i.e, conversion to .tflite from my custom trained .pb model.
Is this supported ? or is there anyone who is facing conversion problems that has not yet been resolved ?
Thanks.
Many Slim models can be converted to TFLite, but it isn't a guarantee since some models might have ops not supported by TFLite.
What you could do, is try and convert your model to TensorFlow Lite using TFLiteConverter in Python before training. If the conversion succeeds, then you can train your TF model and convert it once again.

Categories

Resources