0

I have a keras model for image classification saved in a .h5 file or Json file, and then I created a C# desktop app ( in visual studio 2019) which contains two buttons one to load an image and an other to show the result of the prediction. Could any one tell me how can I load my model on the application and use it with the button to make predictions? Please help if you have any ideas. Thanks

Lema Zaidi
  • 31
  • 1
  • 5
  • a possible solution is to run python via a shell command from C# and get the output back in C# – Nikos M. Jun 14 '21 at 14:22
  • These open source libraries may be useful: [Keras.NET](https://github.com/SciSharp/Keras.NET) , [TensorFlowSharp](https://github.com/migueldeicaza/TensorFlowSharp) – noe Jun 14 '21 at 15:54
  • Ok, Thank you I will see that. – Lema Zaidi Jun 15 '21 at 07:08
  • @noe Is there a way to call my saved keras model (.h5 and .json file) using keras.NET ? I used modelfromjson but it doesn't work, this is used for sequential models but I'm not using sequential model. – Lema Zaidi Jun 15 '21 at 10:04
  • If Keras.NET did not work for you, I suggest you convert your .h5 Keras model to tensorflow format (.pb) (e.g. with [this](https://github.com/amir-abdi/keras_to_tensorflow)) and then you use [TensorFlowSharp](https://github.com/migueldeicaza/TensorFlowSharp) to load it. – noe Jun 15 '21 at 10:37
  • Okey, thanks. I want to know if it is possible to make predictions after loading that model. In my c# application, i want to load an image and than use a button to classify that image. I'm working for an internship project and I'm a beginner with this. Thanks for helping @noe – Lema Zaidi Jun 15 '21 at 11:00
  • Yes, the whole point of the [TensorFlowSharp](https://github.com/migueldeicaza/TensorFlowSharp) library is to use for inference a trained tensorflow model. – noe Jun 15 '21 at 11:08
  • @noe I tried to use keras.Net with a sequential model using var loaded_model = Sequential.ModelFromJson(File.ReadAllText(path)) and Now I have this error in visual studio: "Python.Runtime.PythonException : 'ImportError : Keras requires TensorFlow 2.2 or higher. Install TensorFlow via `pip install tensorflow`'" How can I check all the versions that visual studio uses python, tensorflow, keras...? – Lema Zaidi Jun 15 '21 at 13:48

0 Answers0