OlafenwaMoses / ImageAI

A python library built to empower developers to build applications and systems with self-contained Computer Vision capabilities
https://www.genxr.co/#products
MIT License
8.54k stars 2.19k forks source link

How can i convert my trained model (.h5) to darknet weight? #363

Open xiluzi opened 4 years ago

xiluzi commented 4 years ago

I only have two files. One is json, another is h5 model. So how can i convert these to darknet weight?

rola93 commented 4 years ago

What is exactly darknet weight?

It's very easy to follow the evaluation code and see how to load it on memory as a keras model. Then, all you need is to find how to convert a keras model darknet (whatever it is). You'll probably need to keep some pre/post processing operations from ImageAI library yet

xiluzi commented 4 years ago

What is exactly darknet weight?

It's very easy to follow the evaluation code and see how to load it on memory as a keras model. Then, all you need is to find how to convert a keras model darknet (whatever it is). You'll probably need to keep some pre/post processing operations from ImageAI library yet

hello. I would leave this company, and I need to give my training model to my workmate who uses java. I'm new in machine learning and I don't know how to convert my trained model to make it useful to him.

Krishnarohith10 commented 4 years ago

What is exactly darknet weight? It's very easy to follow the evaluation code and see how to load it on memory as a keras model. Then, all you need is to find how to convert a keras model darknet (whatever it is). You'll probably need to keep some pre/post processing operations from ImageAI library yet

hello. I would leave this company, and I need to give my training model to my workmate who uses java. I'm new in machine learning and I don't know how to convert my trained model to make it useful to him.

Hi, if you have .json or .h5 file of a trained model then you just have to give that file to your friend. And if you don't mind me asking you, what is darknet weights ? Are you using YOLO algorithm because darknet is used in their algorithm only ?

xiluzi commented 4 years ago

What is exactly darknet weight? It's very easy to follow the evaluation code and see how to load it on memory as a keras model. Then, all you need is to find how to convert a keras model darknet (whatever it is). You'll probably need to keep some pre/post processing operations from ImageAI library yet

hello. I would leave this company, and I need to give my training model to my workmate who uses java. I'm new in machine learning and I don't know how to convert my trained model to make it useful to him.

Hi, if you have .json or .h5 file of a trained model then you just have to give that file to your friend. And if you don't mind me asking you, what is darknet weights ? Are you using YOLO algorithm because darknet is used in their algorithm only ?

thanks for your reply! I find he can't use the keras model directly in java, and after google I find if want to use this model in java, must convert my trained model to darknet model. And darknet model is not end with .h5 or .json but end with .weights . So that is what i mean.

alexismailov2 commented 4 years ago

Yeah I have also this question. I will try to explain:

  1. A lot of code there are in the github with keras for yolov3 and it is may be good for some body but I need to use opencv with c++ only(faster variant)...
  2. Opencv supports darknet format and all info even anchors there is in config and downloaded automatically... And it it awesome but opencv does not support h5...
  3. I will try to convert h5 to tensorflow format and it is loaded but without yolo layer and anchors... Resume: the problem in handy realization of yolo layer which will not included to model that is why opencv can not load it you should hit you head of the wall to make it works... Or just use darknet framework and it will work good...
Krishnarohith10 commented 4 years ago

Hello again, see, obviously hoping you figured a way to handle that weights to him and thinking you left the company, solves the problem, TA-DA! Well if not, you should first get you weights from .h5 file, means, if can't save weights in keras you save the model trained. So get the weights first. You said you have two files, which means you saved weights in .h5 file and model to .json file, assuming this condition: with open('name_of_the_json_file.json', 'r') as f: load_json = f.read() model = tensorflow.python.keras.api.keras.models.model_from_json(load_json) model.load_weights('name_of_the_weights_saved.h5') You get your weights by getting: weights = model.get_weights() Now what you have to do is do some research about saving this weights as For ex: .txt file. See the variable weights, how the data is, how to store it in other formats and how use them from other format. It's like, think it's like learning a new thing about the weights and others. As you mentioned your new to machine learning, you even have a job and I having a 1 year experience in machine learning deep learning don't have a job. And not to mention, i am a under graduation, yet to complete my graduation this year so. It's never late for us to learn anything. Hope you will Innovate Inspire Intellect. If you got rid of this issue anyway, just update the comment on how you did it, whether you did it not just neglected it, if it doesn't bother you, please close this issue. Thank You