Load model with ML.NET saved with keras

2024/9/8 10:28:45

I have a Neural Network implemented in Python with Keras. Once I have trained it I have exported the model and I have got two files: model.js and model.h5. Now I want to classify in real time inside a .NET project and I want to use the trained Neural Network for it.

Is there a way in ML.NET of loading the model and trained weights exported with python into a model object?

I have seen in the documentation[1] that a previous saved model can be loaded, but apparently is storage in a .zip and I could not find the format (maybe to make a script that takes the model from python and 'translate' it to the ML.NET model.

Apparently the hdf5 format is a standard[2], there is a way to load it with ML.NET?

[1] https://learn.microsoft.com/en-us/dotnet/machine-learning/how-to-guides/consuming-model-ml-net

[2] https://support.hdfgroup.org/HDF5/doc1.6/UG/10_Datasets.html

Answer

ML.net supports ONNX models, as in this example.

You can convert your keras model to ONNX model via WinMLTools

https://en.xdnf.cn/q/72586.html

Related Q&A

unable to add spark to PYTHONPATH

I am struggling to add spark to my python path:(myenv)me@me /home/me$ set SPARK_HOME="/home/me/spark-1.2.1-bin-hadoop2.4" (myenv)me@me /home/me$ set PYTHONPATH=$PYTHONPATH:$SPARK_HOME:$SPARK_…

Is there a way to shallow copy an existing file-object?

The use case for this would be creating multiple generators based on some file-object without any of them trampling each others read state. Originally I (thought I) had a working implementation using s…

Python - Import package modules before as well as after setup.py install

Assume a Python package (e.g., MyPackage) that consists of several modules (e.g., MyModule1.py and MyModule2.py) and a set of unittests (e.g., in MyPackage_test.py).. ├── MyPackage │ ├── __ini…

Where can I find the _sre.py python built-in module? [closed]

Closed. This question is seeking recommendations for books, tools, software libraries, and more. It does not meet Stack Overflow guidelines. It is not currently accepting answers.We don’t allow questi…

When numba is effective?

I know numba creates some overheads and in some situations (non-intensive computation) it become slower that pure python. But what I dont know is where to draw the line. Is it possible to use order of …

How to launch a Windows shortcut using Python

I want to launch a shortcut named blender.ink located at "D://games//blender.ink". I have tryed using:-os.startfile ("D://games//blender.ink")But it failed, it only launches exe fil…

Providing context in TriggerDagRunOperator

I have a dag that has been triggered by another dag. I have passed through to this dag some configuration variables via the DagRunOrder().payload dictionary in the same way the official example has don…

Install gstreamer support for opencv python package

I have built my own opencv python package from source. import cv2 print(cv2.__version__)prints: 3.4.5Now the issue I am facing is regarding the use of gstreamer from the VideoCapture class of opencv. I…

How to use query function with bool in python pandas?

Im trying to do something like df.query("column == a").count()but withdf.query("column == False").count()What is the right way of using query with a bool column?

Text Extraction from image after detecting text region with contours

I want to build an OCR for an image using machine learning in python. I have preprocessed image by converting it to grayscale , applied otsu thresholding . I then used the contours to find the text re…