akusok / scikit-elm

Extreme Learning Machine (ELM) with Scikit-Learn compatibility
MIT License
29 stars 11 forks source link

Can the Keras model be converted to elm by using scikit-elm? #11

Closed njuptlht closed 7 months ago

njuptlht commented 7 months ago

I saw in "6.4 Export to Keras and iOS.ipynb" that you converted the ELM model to Keras. Assuming I first created the same Keras model, can you convert it to ELM by using scikit-elm?

akusok commented 7 months ago

There is no function for this, and Scikit-ELM is too complex (my bad) for a reasonable conversion. I can suggest you to use the HPELM (https://github.com/akusok/hpelm) because you can pass Keras weights and biases in function "add_neuron" (https://github.com/akusok/hpelm/blob/52cb0fafd08401d96bb160bbf1d4647351d8452e/hpelm/elm.py#L235C14-L235C14)

akusok commented 7 months ago

If Keras model has output weights computed too, you can set them in HPELM by using "self.nnet.set_B(B)" where "B" is the matrix of output weights.

njuptlht commented 7 months ago

Thank you for your prompt reply.I have one more question. In scikit elm, there is a function called "partial_fit" to teach ELM the new classes. Is there a related function in HPELM?

---- Replied Message ---- | From | Anton @.> | | Date | 12/15/2023 14:28 | | To | @.> | | Cc | @.> , @.> | | Subject | Re: [akusok/scikit-elm] Can the Keras model be converted to elm by using scikit-elm? (Issue #11) |

If Keras model has output weights computed too, you can set them in HPELM by using "self.nnet.set_B(B)" where "B" is the matrix of output weights.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

akusok commented 7 months ago

HPELM cannot learn new classes. It requires some advanced logic, and only written for Scikit-ELM.

If you know the total number of classes from the beginning, you can create the outputs for all classes from the beginning (even if some classes will have no training samples). Then you can add more training data by calling "hpelm.add_data(X, Y)" several times, followed by "hpelm.nnet.solve()" once all data is added.

Feel free to contact me by email with questions or your code examples. I will be happy to help!

njuptlht commented 7 months ago

I really appreciate your time and help. I have solved the problem of learning new classes in HPELM. I still have some doubts about converting Keras model into ELM with HPELM. Based on your guide " Export to Keras and iOS", I have written a simple code to create a Keras model. Can you continue this to convert Keras model to ELM by using HPELM? I couldn't distinguish the difference between output matrix "B" and "W_out" and "bias_out". Here is the code file:

---- Replied Message ---- | From | Anton @.> | | Date | 12/15/2023 16:56 | | To | @.> | | Cc | @.> , @.> | | Subject | Re: [akusok/scikit-elm] Can the Keras model be converted to elm by using scikit-elm? (Issue #11) |

HPELM cannot learn new classes. It requires some advanced logic, and only written for Scikit-ELM.

If you know the total number of classes from the beginning, you can create the outputs for all classes from the beginning (even if some classes will have no training samples). Then you can add more training data by calling "hpelm.add_data(X, Y)" several times, followed by "hpelm.nnet.solve()" once all data is added.

Feel free to contact me by email with questions or your code examples. I will be happy to help!

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

akusok commented 7 months ago

I did not get your file, could you please send it again to akusok.a(at)gmail.com?

njuptlht commented 7 months ago

Since I am not sure if the email address I sent is correct, I sent code file to @.*** and akusok. @ gmail.com. If you haven't received it or the email address is incorrect, please let me know and I apologize for this.

| ---- Replied Message ---- | From | Anton @.> | | Date | 12/16/2023 17:02 | | To | @.> | | Cc | @.> , @.> | | Subject | Re: [akusok/scikit-elm] Can the Keras model be converted to elm by using scikit-elm? (Issue #11) |

I did not get your file, could you please send it again to akusok.a(at)gmail.com?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>