New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Serialization in .Net 5.0 #371
Comments
Try one of the other forms of serialization described at How to save distributions to disk. |
Thank you very much @tminka |
Hi @tminka I tried serializing using the Json Format as specified in the link you gave above. It serializes an object however said object cannot be deserialized. The type that BayesPointMachineClassifier.CreateBinaryClassifier() creates is a: CompoundBinaryStandardDataFormatBayesPointMachineClassifier<IList,Int32,.IList,Boolean> However CompoundBinaryStandardDataFormatBayesPointMachineClassifier is internal to the library and cannot be deserialized, and as far as I know the interface that it implements also cannot be deserialized: IBayesPointMachineClassifier<TInstanceSource, TInstance, TLabelSource, TStandardLabel, IDictionary<TStandardLabel, double>, TTrainingSettings, TPredictionSettings> here is the json for the document that gets serialized. can you provide further guidance
|
How were you able to serialize that type using Json? It isn't designed to do that. |
@tminka sorry for the delay I was out on PTO. here is what I did? `using Net.Json; var modelFile = "IdentifierSearchScoringModel.json"; class CollectionAsObjectResolver : DefaultContractResolver private static readonly ConcurrentDictionary<Type, JsonContract> ResolvedContracts = new ConcurrentDictionary<Type, JsonContract>(); var serializerSettings = new JsonSerializerSettings { var mapping = new ClassifierMapping(); // write to disk |
So if it isn't designed to do that how can I serialize a BPM model in .Net 5.0? |
Hi @tminka, Do you have any advice here? Not that it is any of your problem but I am coming up on a hard deadline and if I am not able to deserialize the model in .Net 5.0 I will have to scrap this approach. Best, |
The code that you sent doesn't work for me. As far as I can tell, Json.NET cannot serialize these classes at all. That is why I was confused how you got that output. The Learner classes all implement custom binary serialization. They would have to be changed to support any other form of serialization. |
Thanks. I rrun that code in a .Net notebook on Azure Machine Learning. It serializes all of the child classes but does not serilize the top level class. One final question since I have the MeanTimePRecision and Precision can I use the generated algorithm to do inference. |
Yes, if you are just making predictions then you can use the generated algorithm directly. |
I have created PR #373 which adds the ability to serialize BayesPointMachineClassifiers as text. |
@tminka Thank You. This is great. |
I will update the Nuget package this week. |
I have recently met with an issue where saving and serializating a model in .Net 5.0 (i.e. in .Net Notebooks or in Azure functions) is met with a Binary Serialization error. As far as I understand this error occurs due to the Security Concerns arround binary serialization. The recommended method of dealing with the Binary serailizer incompatibility is the implementation of the ISafeSerialization. After reviewing the code base in this repo that would require modifications all the way down to the Automaton to allow for safe serialization of models particularly for models that implement Incremental Learning hence need to be saved and serialized in the runtime environment. Is there a solution for this problem other than the obvious one I've mentioned above?
The text was updated successfully, but these errors were encountered: