microsoft / CNTK

Microsoft Cognitive Toolkit (CNTK), an open source deep-learning toolkit
https://docs.microsoft.com/cognitive-toolkit/
Other
17.53k stars 4.28k forks source link

C# Evaluation of Models Trained in Python #3176

Open whitmark opened 6 years ago

whitmark commented 6 years ago

I am looking to train non-image DNN model in Python (3.6) but evaluate in C#. Is there some documentation or examples on how best to do this? Unclear what transformation is needed, if any, before saving the model in Python or after loading the model in C#.

ke1337 commented 6 years ago

No model transformation is needed. However, please note that in Python data are row-major following numpy convention, while in C++/C# they are col-major and tensor axis are reversed. So in Python when you are feeding a tensor with row-major of [batch_size, seq_len, sample_dimA, sample_dimB], the corresponding C++/C# data tensor would be col-major [sample_dimB, sample_dimA, seq_len, batch_size]. Please check C# eval examples here as references, or search for C# source in GitHub for tests/examples.

whitmark commented 6 years ago

Thanks @KeDengMS. I would prefer to train in C#, but there is so much more documentation, examples and perhaps functionality in Python, I am considering changing my development plans to train in Python but I still need to evaluate in C#. Are you suggesting the eval documentation and examples you recommended demonstrate how to make this tensor modification? If so, I didn't see a reference for this specifically but suspect it would be good to add to the C# Evaluation documentation along with how-to examples and any implementation caveats since others may take this path.

ke1337 commented 6 years ago

As for training in C#, you may create you model in Python and load in C# to train. We should definitely improve C# docs and examples. For the time being, please search for C# test code in repo that loads pretrained models.

jerusalemc commented 6 years ago

@KeDengMS can u give a file path in this repo about C# load pretrained models, I can't find yet

ke1337 commented 6 years ago

Here is a C# test for train and eval, and this shows how to load model in C#. Hope it helps.