Skip to content
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

.NET Support #960

Open
StevenGann opened this issue Oct 27, 2016 · 125 comments
Open

.NET Support #960

StevenGann opened this issue Oct 27, 2016 · 125 comments
Assignees

Comments

@StevenGann
Copy link

Issue #817 was closed with this response:

We fell a little behind. The Python bindings are done in SWIG. I think that can be quickly repurposed into .Net bindings, once done. So it shouldn't be too far out.

That was September 6th. It's now late October and there's been neither an announcement regarding .NET, nor an update to the original issue.

I'm eager to finally work with deep learning on Windows with C# instead of on Linux with Python. I'm sure Python bindings were helpful to some devs, but frankly every other deep learning framework already supports Python and C++. I'm surprised .NET hasn't been a higher priority, since it's something no other system has been able to provide. Now's the chance to become the de facto deep learning library for OOP development!

@wolfma61
Copy link
Contributor

Yes Steven, we hear you and we are sorry for the delay.
This is now one of the highest priority items for us, no definite 'landing day yet', but we should be able to give you at least a date shortly, and you will some work on this topic materializing in branches ...

thx
Wolfgang

@StevenGann
Copy link
Author

That's fantastic, and thank you for the quick reply. I'm happy to wait, I just wanted some signal that it was still in progress.

@andrewfry
Copy link

Great news! I'm very excited for this.

On Oct 27, 2016 9:35 AM, "Steven Gann" notifications@github.com wrote:

That's fantastic, and thank you for the quick reply. I'm happy to wait, I
just wanted some signal that it was still in progress.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#960 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AHgBXmpKyUsZKcuUE0HFMcicK-AL3UZQks5q4KicgaJpZM4KiTg-
.

@ghost
Copy link

ghost commented Oct 27, 2016

+1 on C/C++ and C#

@gvoysey
Copy link

gvoysey commented Oct 27, 2016

Will support target .NET, .NET Core, or Mono? I am eager to do cross-platform learning in C#.

@ghost
Copy link

ghost commented Oct 29, 2016

python/R is great for research and prototyping - the general "lab settings". this is what alphabet is doing. CNTK extends further as platform and has to support the footprint of why it is being chosen in the first place.

small to medium scale commercial projects would benefit from the complete integrated API. For many, C# replaces VB and likes. this is different ML/AI sector - from phone apps to websites and small corporate projects.

C# leverages over 15 years of the entire DCOM/J++/COM+/DNA2000 etc effort around integrated windows platform development and is used from distributed applications development, transaction processing to desktop and phone applications.

@StevenGann
Copy link
Author

@zergxyz I'd like to see some numbers showing that more commercial production code uses R than .NET. I'd like to see some data showing more end-user applications and games using Python than .NET.

Can R even be compiled? I know it's basically an open source Matlab but to my knowledge it's still a scripting language. Python can technically be compiled, but compatibility and platform support is poor. Heaven help you if you need something more exotic than the stock Python 2.7 environment.

Academics may favor scripting languages like R and Python, but actual applications tend to be written in actual programming languages. Furthermore, the indie game community is largely dominated by C#, at least more so than Python or R, which means

the main stream in machine learning and deep learning community should be c++/python/R based

Am I addressing the Godking of Deep Learning? Is there an Asimov-style governing body determining what research can be done and how?

You have Python support. I'm sorry if you think R support is more important than C# but the numbers don't lie. C# is more popular than R by every metric. Besides, a quick Google search suggests R already has it's own RNN system, plus it already has support from Tensorflow. Go try Tensorflow instead.

@bklooste
Copy link

bklooste commented Nov 8, 2016

As these products become more mature they will have to use common languages/platforms , im sick of converting flakey lab code to something that customers can actually use. Large c# programs are everywhere outside of linux (which is used by only a small amount of desktop users).

@n17s
Copy link
Member

n17s commented Nov 11, 2016

We have started actual work on C# bindings.
A few questions to the folks that watch this issue:

  • for Python we relied heavily on NumPy as the way to pass tensors in and out. What is the most natural way of doing this in C# ? Especially if you need some simple preprocessing operations like transposing a 640x480x3 tensor to 3x480x640 ?
  • the issue says ".net" but everyone here has not mentioned anything other than C#. Is it safe to assume that C# should be the next language to cover?

@ghost
Copy link

ghost commented Nov 11, 2016

The best would be to clean-up and merge what had been developed for BrainScript with one of the OS libraries or branch it into separate .net development.

Math.NET Numerics : http://numerics.mathdotnet.com/ (http://www.mathdotnet.com/) could be a good starting point. It also supports using native library ie. MKL etc. There had been some effort within MSFT to use/expose it as well https://msdn.microsoft.com/en-us/library/hh304363(v=vs.100).aspx

There are some smaller tensor library specific porting projects like https://libraries.io/github/alex-weaver/TensorSharp .

Not sure I understand your second question. .NET is a framework and leaves the choice of language free. What is the CNTK strategy over the long term ?

Is to provide a class library targeting all CLI compliant languages? If yes, then you need to choose the actual framework - for instance .NET CORE which is cross-platform and open source. The language is then only relevant for documentation and QA.

Alternatives:

  • provide dll/com libraries targeting C++/CLI
  • standalone C++ "unmanaged code" libraries with interfaces for both .net (System.Runtime.InteropServices) and unmanaged code.

This is TensorFlow discussion about C# API - who face similar strategy choice:
tensorflow/tensorflow#18

@n17s
Copy link
Member

n17s commented Nov 11, 2016

Thanks for the pointer to the TF issue and the pointers to the libraries.

User convenience is the main reason we are doing the bindings. The library is in C++ so if you are determined enough you can program like this, and call it from C# with unsafe code. But that would be ugly, error prone, and hardly deserving to be called "support for .net".

@ghost
Copy link

ghost commented Nov 11, 2016

You are facing some strategic choices for the platform you are building. A lot of CNTK code is redundant or/and dependent on some specific non-easily portable (platform/language) libraries. Looks like you want to re-package the added value over a couple of different directions.

If you target the .net framework (for example .NET CORE) you will have python support free with it on par with other CLI languages (https://github.com/IronLanguages). Not targeting .net means exactly what you had said - poor penetration of potential CNTK users who face hurdles of complexity of interfacing with unmanaged code from their .net environment.

My point of view is product/platform and the necessary resources. It is clear that anything is feasible and usable right now with a given effort. The core of the platform works well - distributed training using GPU/CPU etc.

I would of thought that for model training BrainScript should be enough (with parallel bindings in python). For training via .net applications you could integrate BrainScript into .net or provide a .net library that interprets BrainScript files. You dont have to re-invenent the function by function brainscript binding for model training!

The key area is for the model evaluation. Python users would not notice any difference, while people targeting commercial applications (providing a trained model and an application built on top of the model) would benefit from robust model loading and evaluation via managed code support. There is also less of a performance impact - and smaller percentage of use cases requiring HPC like latencies in evaluation.

I will have a lot more feedback over the next few weeks as we check various CNTK areas - including real-time usage of CNTK Evaluation (C unmanaged code interfacing with native win C++ DLL that uses CNTK Evaluation)

@ghost
Copy link

ghost commented Nov 16, 2016

@bklooste
Copy link

@n17s I would wrap the C++ tensor. C# has unsafe pointers for exactly this reason and you don't want large amounts of memory in C# when the lib doing the work is C++ , you especially dont want to move the memory from to C# and then copy it into C++ thats a killer often seen in network stacks. So id provide access to the C++ tensor , pin it to modify . A lot of C# network apis do that as well they hold the packet in native and allow the reading into C# only when desired. Probably consider to just write the wrapper in C++CLI as it fits better with the project however C++ CLI will not fit with core ( and core on Linux) .

Agree on brain script only for training , it makes C# a much lighter easier to keep up to date wrapper. Agree on good support here to load and save brain script files. Some methods to construct a brain script file , maybe via expression tree. ( though an extern c call in brainscript would be nice) .

@n17s
Copy link
Member

n17s commented Nov 20, 2016

Sure, the C++ stuff will be wrapped but I believe that's not sufficient. To make this discussion more concrete let's look at this wiki page. An image is loaded, transposed (width x height x channels to channels x height x width), and 128 is subtracted all in one line. This has nothing to do with the CNTK TensorView class, this is all preprocessing to put the input into the right format and numpy is super helpful here. If there's a good library like this in C# we should be leveraging it.

@ghost
Copy link

ghost commented Nov 21, 2016

If this is the immediate orientation... whats wrong with using R.NET? https://rdotnet.codeplex.com/ or looking at the msft R roadmap to see if it fits?

@StevenGann
Copy link
Author

@avader906 To me, the problem with using R is that if I'm going to use an interpreted scripting language inside my native application, I might as well use Python since it's a lot more developed and supported than R.

@bklooste
Copy link

@n17s Its data in C# and there are a number of image processing libraries , ImageProcessor nuget may do - I dont think this should be part of CNTK project at best a community extension to existing image processing . That said my personal project is for the network to do this .

@deviousasti
Copy link

Um, I'm only asking since it's been a while - rather than a date, could you confirm if .NET support is indeed planned?

@andrewfry
Copy link

Any news or updates on this one? I saw a new release was out, but nothing noted regarding .NET/C# support.

@asdfgasdfsafgsdfa
Copy link

2017 now... no love for .net yet? :(

@zhouwangzw
Copy link
Member

We have just released the beta version of CNTK Library .NET/C# Eval API. https://github.com/Microsoft/CNTK/releases/tag/v2.0.beta8.0.

@aiunderstand
Copy link

Thanks for this important update @zhouwangzw, we are looking forward to see .NET/C# as a first class citizen with both eval and training API's.

@andrewfry
Copy link

Definitely a good start.

@lefig
Copy link

lefig commented Mar 30, 2017

What is the current status of the .NET interface support? Is it live now..? Thanks

@andrewfry
Copy link

There is no API to create networks/train - not that I am aware. They have a beta version of the C# evaluated after you've already trained your network. Personally I have given up hope for .NET support and have been doing all my ML development with TF & Python. The only selling point for me with CNTK was the fact they were talking about support C#, which I love versus Python. Since that does seem to even be a consideration I have moved on. Hopefully they will reconsider ... one day.

@lefig
Copy link

lefig commented Mar 31, 2017

Thanks for that. I see. Well I guess its worth trying to use a pythonnet interface between python and .net. I bet the performance would be a dog though.

@SuperDaveOsbourne
Copy link

I have just downloaded the RC 2 from April 21st and made a .net c# project with it. Not much there. Is this conformation that c# will be a red headed step child of Python support?

@ghost
Copy link

ghost commented Apr 29, 2017

@SuperDaveOsbourne There is everything needed in C# API to evaluate models trained in Brainscript or Python. However, training models vs evaluating models requires a different ecosphere of support libraries and infrastructure.

The core of CNTK is C++ codebase - it is possible to extend the managed API further. From the number of commits it does not look that wider community is participating much in that direction. One has to accept the fact that the product originated from MSFT research, and without much of an external drive, it would be driven by the commercial priorities of the company funding that research.

What might impact those priorities?

  • Python is the default "glue" choice for DNN across all open source projects. A lot had been developed in terms of libraries and specific support required for scientific computing. Python is overtaking R in terms of statistics and data warehouse / big data applications too. Arguably, C# does not have the same facilities and the required workload to offer them might not be commercially viable without community participation.

  • Python is taught widely - providing steady pool of junior people to join the industry. This could not be said for C# - which remains specialized to middleware and windows applications. It would be logical for C# to focus on model evaluation - easy to integrate with existing systems to run pre-trained models.

You can read between the lines from the recent MSFT announcements regarding the future of SQL Server platform and its satellite products (R Server, PolyBase, PDW/APS) as well as Azure. Python will be brought in on par with R and ML libraries will be broaden. Under that view, Python related commits can be interpreted as priority.

@normanhh3
Copy link

@sethjuarez maybe you can go join this team and give them a leg up!? NuML has some great ideas!

@n17s
Copy link
Member

n17s commented Sep 16, 2017

CNTK 2.2 has a C# API. We welcome feedback and contributions for enhancements.

@SuperDaveOsbourne
Copy link

<CNTK 2.2 has a C# API. We welcome feedback and contributions for enhancements.>

That's one small step for C#, one giant leap for .net mankind.

A hello-world example to train and evaluate a logistic regression model using C#/API: https://github.com/Microsoft/CNTK/tree/master/Examples/TrainingCSharp/Common/LogisticRegression.cs

@SuperDaveOsbourne
Copy link

I have created a slack channel for CNTK for dot net. This is a public link.

https://join.slack.com/t/cntkdotnet/shared_invite/enQtMjQyMzE0MTA3MzYzLWEwNjZlYWFmMTI2NzZhZGE3YmQzOTNkY2VkZGM3NDFjODMxNTUwY2M5ZGU4NDQxZDUxZDk5MTdmYWQ4MjY4ZWM

Workspace URL: cntkdotnet.slack.com

@veikkoeeva
Copy link

@SuperDaveOsbourne Why not use the CNTK Gitter channel?

@danielsc
Copy link
Contributor

As Nikos pointed out, we now have a C# API that allows for both training and inference. It covers a reasonably broad set of scenarios (including RNNs and Transfer Learning), but it will require further improvements to reach parity with the Python API at a good performance.

Also, we have built this API as a pretty direct mapping to the C++ API using SWIG. This allowed us to move pretty fast, but does not make for a pretty API that follows well established C# design conventions. Our intention here is to build a high-level API on top of this low-level one that would offer easy composition of layers, like the python layers API does.

On both aspects (improve the low-level API, design the high-level API) we are looking to the community to participate and help. Please open issues for improvements to the newly published APIs, and, if you see a way for you to fix them, do let us now, so we can coordinate.
For the high-level API, we would like have some design discussions in the coming weeks -- we will open a new issue for it and will post the link here. At that point, I would also close this issue as resolved -- please let me know if you disagree.

@vermorel
Copy link
Contributor

@danielsc The .NET/C# lib draft is indeed a very good news, and it's very cool to see the CNTK team moving in the right direction for the .NET ecosystem. However, at this time, issues like /issues/2374 (a design flaw severely impacting performance) prevents most production uses of the library (except for small datasets). This design problem cannot be fixed by layers on top.

@deepakkumar1984
Copy link

deepakkumar1984 commented Nov 6, 2017

Could be useful project: https://github.com/deepakkumar1984/SiaNet
A wrapper on CNTK for easy building of network and train them

@laygr
Copy link

laygr commented Nov 11, 2017

Skip C# and prioritize F#, it can be easily advertised as a better Python. Honestly, what is good about C# for ML? If you want to do ML and .Net, lookout for F#.

@mikhail-barg
Copy link
Contributor

@laygr I think it's a matter of language preference and have nothing to do with ML. I'd easily say "what's good about F#, do C#!" but there's no point in starting a functional vs. imperative holywar.
As for us we've choosen CNTK mostly because it had native support for .Net (meaning C#) so we could use it seamelessly in production code.

@deepakkumar1984
Copy link

@laygr I agree with mikhail-barg. F#, C#, VB all under .NET hood. You can load CNTK in F#. I think the .NET community need to build more libraries similar to python for machine learning.

@laygr
Copy link

laygr commented Nov 11, 2017

@mikhail-barg, @deepakkumar1984. I should have given an example to be more convincing; let's look at the case of Solver Foundation. Microsoft wrote not too long ago a truly great optimization framework called Solver Foundation. It supported .Net, but its design was centered around C# and OOP. However, they also wrote a simple DSL for F# which allowed to define the models in a very succinct way. Lets look at how a model is defined in C# and how it's defined in F# via the DSL. (More on the evident superiority of F# at modeling for Solver Foundation: Units of Measure demo blog post, DSL Demo, check out how constraints are defined.
Clearly, the F# idiom is superior, really, no subjectivity going on, except that by not centering the design of Solver Foundation around F#, the DSL was lacking on functionality, I guess it was not a priority; so if you wanted to use the full power of Solver Foundation, you couldn't use the DSL and you had to write code in the clumsy OO way.
Today you can't use Solver Foundation at all because it is a dead project. Will history repeat?

@deepakkumar1984 I agree that we need more libraries to remain competitive against Python. For a quick fix, we can use IronPython, which allows us tu use Python's libraries in .Net.

@mikhail-barg
Copy link
Contributor

@laygr Do you really mean that this Solver Foundation project is dead because MS designed it more for C# not for F#?

For me personally it would be a huge downside if CNTK would switch it's focus from C# to F# just because I live more on imperative side of programming universe, and I would have to learn another language just to be able to configure CNTK models (learning another language is not bad by itself, but it looks like an overkill for a modelling task) and it would probably be another DSL built upon F#, right? So why bother, there's already a DSL for these models — BrainScript (and we invested time in learning it already).
So I rather then learn more of Python (which I kinda hate) and it would be a better investment of time because Python is a lingua franca in ML society (sadly).

@deepakkumar1984 I aslo agree on the lack of ML libraries for .Net — I've spent some time just to find that there's no real sound processing library for .Net that is capable to reproduce scipy.signal.spectrogram out of the box.

@laygr As far as I know IronPython is rather dead as well. And I'm not sure on the performance side of the C#-IronPyhon-Python-Cython stack (and most of ML Python libraries are built upon native Cython code).

@vermorel
Copy link
Contributor

Referencing here the Tensor<T> type coming to .NET which would be a great addition for CNTK.

@veikkoeeva
Copy link

Cross-referecing discussion at #2352 since it's about .NET Standard 2.0.

@MgSam
Copy link

MgSam commented Nov 26, 2017

I tried going through the C# CTNKLibraryCSharpTrainingExamples today. I think its a great start!

I have some feedback, please keep in mind while reading this that it's all from the point-of-view from a complete ML novice who doesn't understand much about what goes on under the hood, only about the general ML workflow of training, validating, and applying a model.

Feedback:

  • I think there should be a higher-level API than what currently seems to be available (at least as far as I can tell). For example, the Azure Machine-Learning Studio provides a Training Model step that requires literally only three inputs- a model, a dataset (which can be of hybrid types like strings and floats), and what the output variable(s) are. Everything else is set using what I assume are sensible defaults. I'd imagine that for the majority of users (who are not statisticians or ML experts), this is how they want to get started. Tutorial I used
  • Why is the logistic regression network linear model defined explicitly in the code (create LinearModel method) rather than part of the library? According to the CNTK tutorial it has been a staple for the past decade. Under what circumstances would a non-statistician be knowledgeable enough to define a different model?
  • I understand the convenience of generating random data for testing out the library, but its not a good way to help people learn. I think you should put a CSV with real-world data (ideally with mixed strings, dates, and floats) in the example solution, and in the example Program.cs, load it into memory and pass it into the TrainAndEvaluate methods. Seeing the code work on actual data instead of random numbers would be a lot more helpful in helping to understand how its working.

Thanks for all your hard work on the C# API!

@fwaris
Copy link

fwaris commented Jan 20, 2018

Bravely or foolishly taking matters into own hand see issue #2863

(functional nature of F# better suited for math modeling - at the end of the day the DL toolkits are Math languages)

@veikkoeeva
Copy link

@ivannp
Copy link
Contributor

ivannp commented Mar 4, 2018

Another proof-of-concept Keras-like approach - NativeKeras.

@sgf
Copy link

sgf commented Jun 3, 2018

CNTK developers have no belief.
Actually, Microsoft, many developers alike.
They are no longer capable of creating great works like Windows, Make history.
And now they are just doing the same like others.
Just Follow the footsteps of others.

@veikkoeeva
Copy link

I'll add here for the benefit of passers-by, the .NET kid on the block seems to MachineLearning.Net. It should be able to use CNTK binaries also.

@Jiuyong
Copy link

Jiuyong commented Nov 13, 2018

多好的 Windows Mobile ,非要东施效颦,
把 WP 弄成这个死样子还不够?
机器学习还要这样搞?
18年 .Net/C# ,非要这样自寻死路?
人家公司坑用户,
M$现在不吭用户,只坑粉丝。

@Gregor959
Copy link

F# is still .net. if F# support is given and works fully ( e.g. it's not patchy) then it would be possible
to write a F# library of function that use CNTK. This F# library that can be called from c#. It does not even need to be compiled, since it can be used directly in your C# project. The functions and classes can be called from C#.
So as long as F# is functioning, we have .net support .

I have not coded F# for a few years and only tried it for two week, but it certainly did not hurt my coding to read and write a few functions in F#. ( My C# and coding in general actually improved a lot by doing that) So if you are a C# coder don't be afraid to read a few F# function or classes , it will not kill you. You don't even need to learn a new IDE or a new set of libraries .

So this is what I am hoping for - that the F# will be supported as well as the Python language is supported.

@GuntaButya
Copy link

GuntaButya commented May 10, 2019

C# and CNTK are currently very poorly Wrapped!

The CNTK Core I really want to use, but I am not a fan of Python, nor F#, I like the C Style, Java Style. After all, this is the original Programming Language structure, how C++ and C are constructed, like the C++ CNTK Core...

So WHY such a terrible job of wrapping the CNTK Core with C#?

I am frustrated, C# is an absolutely ideal Graphing Language, CNTK is based of Numerical Graphing, we have an Ideal Match!

Sparse Tensors, or Vectors are not working, Value Class or the Binding to the Core is messing with Values.

I just think a better job should have been done before releasing this! I am appreciative, don't get me wrong! But what's the point of releasing something when it has so many Buggs!

@GuntaButya
Copy link

C# Programmers unite!

Show MSFT we are in need of more! Mean while I have started a website: www.cntking.com for a little push.

@zhongkaifu
Copy link

I developed some C# projects for deep learning and they are widely used in different projects and areas. Currently, I mainly focus on this project: https://github.com/zhongkaifu/Seq2SeqSharp It can be used for sequence to sequence task. It's tensor based, supports multi-GPUs, automatic differentiation, built-in Transformer, LSTM network and many other features. You can try it and let me know your feedback if you like. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests