Giter VIP home page Giter VIP logo

kelpnet's People

Contributors

ajdude avatar harujoh avatar huwahuwa2017 avatar jinbeizame007 avatar nyatla avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kelpnet's Issues

Only Japanese Documents?

I am so happy to see this awesome deep learning library in C#.

But I have trouble to read Japanese documentation in code. Are there some documents that written in English? Or just should I use google translator?

Thanks for making this nice library @harujoh again.

Test9の64行目付近、int txにEOSが2回入力される件について

Test9.csについて、想定通りの動作なのか教えてください。

64行目付近、int txは、文字列id[i+1]の文字列を受け取る変数ですが、末端まで到達したとき、強制的にEOSがセットされるようになっています。

末端の文字列idは常にEOSであるので、ネットワークにはEOSが2回入力されてしまいますが、これは想定した動作でしょうか?

Feature Request: Add Mish activation

Mish is a novel activation function proposed in this paper.
It has shown promising results so far and has been adopted in several packages including:

TensorFlow-Addons SpaCy (Tok2Vec Layer) Thinc - SpaCy's official NLP based ML library
Eclipse's deeplearning4j Hasktorch Echo AI
CNTKX - Extension of Microsoft's CNTK FastAI-Dev Darknet
Yolov3 BeeDNN - Library in C++ Gen-EfficientNet-PyTorch
dnet ruby-dnn blackcat-tensors
DL4S HuggingFace Transformers PAGI
OpenCV Odin-AI Mini DNN
Efficient Segmentation Networks TF Semantic Segmentation Dynastes
DLib Copernicus AllenNLP
PyWick

All benchmarks, analysis and links to official package implementations can be found in this repository

Mish also was recently used for a submission on the Stanford DAWN Cifar-10 Training Time Benchmark where it obtained 94% accuracy in just 10.7 seconds which is the current best score on 4 GPU and second fastest overall. Additionally, Mish has shown to improve convergence rate by requiring less epochs. Reference -

0 (2)

Mish also has shown consistent improved ImageNet scores and is more robust. Reference -

0

Additional ImageNet benchmarks along with Network architectures and weights are avilable on my repository.

Summary of Vision related results:

Capture

It would be nice to have Mish as an option within the activation function group.

This is the comparison of Mish with other conventional activation functions in a SEResNet-50 for CIFAR-10:
se50_1

Too many times creating ComputeBuffer

Hi @harujoh

I found out allocate new ComputeBuffer took long CPU time (about 70% of running time). And I changed weight variable to only copy when GpuEnable changed. It makes GPU calculation 34x faster than before. Also, it's even 272x faster than CPU calculation.

So I think we need to allocate GPU memory when GpuEnable changed.

I added virtual OnGpuEnable() on Function class, and changed the GPU forward code of Linear layer only... How can I change code easily to allocate GPU memory when GpuEnable?

My current idea is adding OnGpuEnable() to NdArray, and then copy values depends on which device is using. Then in code, just use Weight.GpuData or Weight.GpuGrad to access GPU data. In public code, Weight.Data will be redirected into Weight.GpuData when GpuEnabled.

I apologize my poor English first ;-;

MnistDataの新しい構造について提案があります。

#13 で取り上げたMnistDataの配列構造についてです。

MnistData周りを再実装して問題を解決するというアプローチなのですが、MnistDataの提供する画像/ラベルデータを、MnistDataクラス内でKelpNetに適したNdArrayにまで加工してしまうことで、解決できそうです。

現状のMinstDataはデータ構造を反映したメンバ変数を保持していて、これをArrayやint[][]等に変換してアプリケーションに引き渡しています。アプリケーション側はそれらのデータをKelpNetにそのまま入力するため、KelpNetにはArray-NdArray変換などの本来不要な処理が必要です。また、アプリケーションは中間形式の配列構造を意識しなければなりません。

MinstDataが提供するデータをKelpNetにそのまま入力可能なNdArrayまで加工してしまうことで、KelpNet側のArray-NdArray変換処理を削除することができ、また、アプリケーションやKelpNet本体からMnistDataのデータ構造を隠ぺいすることができます。

このためには、KelpNetにNdArrayを入力するAPIを新たに作らなければなりませんが(以前はあった気がします)、元々内部処理はNdArrayベースでされているので大きな負担はないと思います。

#14 で述べられていたように、今後Arrayを廃止するのであれば、KelpNetへの入力フォーマットはNdArrayに統一し、各種のデータからのNdArrayへの変換責務はアプリケーションやデータIOクラスに任せたほうが、構造的にすっきりするように思います。

Javaでの実装は既にありますので、よろしければC#のパッチを作成してコードを寄贈します。

Javaでの実装例は、

MnistDataの読み取り部分が
https://github.com/nyatla/Kelp.Java/tree/master/src/jp/nyatla/kelpjava/io
使用例が
https://github.com/nyatla/Kelp.Java/blob/master/src.test/jp/nyatla/kelpjava/test/Test4.java#L36

です。

本題とは関係ありませんが、RandomにXorShiftを使ってみてはいかがでしょうか。移植の際に乱数ジェネレータに差異があったので実装したものですが、処理系で値が変わらないのは便利ですよ。
https://github.com/nyatla/Kelp.Java/blob/master/src/jp/nyatla/kelpjava/common/XorShift31Rand.java

.Net Standard Supports?

Any plans for it yet?

This library seems nice to support it. Most of the codes are just depends on DotNet standard libraries. If we support DotNet standard, KelpNet will be runnable in mobile or Linux too.

Convolution2Dクラスの最適化について

KelpJavaでの話ですが、Convolution2Dの最適化をしてみました。
パフォーマンス計測はしていませんが、ループ最深部のバイトコードが減ってるので多分早いと思います。

https://github.com/nyatla/KelpJava/blob/master/src/jp/nyatla/kelpjava/functions/connections/Convolution2D_O1.java

変更点は関数内だけで完結しているので、C#への移植は難しくありません。
可読性は悪くなるので、元のコードといつでも切り替えられるように実装するとよいと思います。

最適化のポイントは以下の通りです。

  • ループ深部のif文の削除(計算対象のインデクスの事前計算)
  • メンバ変数アクセスをローカル変数に変更(バイトコードの削減)

Function#parameters変数について提案です

動作の問題ではありません。構造的な提案です。
Function#parameters変数を削除して、abstractなFunction#GetParameters()関数に置き換え、parametersの実体は各継承クラスで宣言するようにしてはいかがでしょうか。

現状でも問題はありませんが、継承クラス実装時にparametersの初期化を強制できません。継承クラス内でparameters変数を所有してabstractな関数でFunctionに提供すれば、parametersの生成を継承クラスに強制することができます。

paramertersをFunctionのコンストラクタの引数として渡す方法も考えましたが、parametersの生成手段が複雑なので、継承クラスが保持してベースクラスに提供する形がよいと思います。

後ほど具体的なコードをpull requestで示しますので、ご検討をお願いいたします。
(不要でしたらリジェクトしてください。)

How to use kelpNet to Identify containers ID

Hi guys
I want to use kelpNet to identify containers ID.

For example :UESU 300246 9
1.how to make data label
2. which module to use
3.how to trainning
4.how to testing
5.how to validate

NdArrayコンストラクタについて提案です

不具合ではありません。提案です。
NdArrayのコンストラクタNdArray(double[] data, int[] shape)についてですが、内部で配列の複製をしています。
まだ完全な調査したわけではありませんが、ほとんどの利用例で複製が必要なのはshapeのみにみえます。

例えばELU#NeedPreviousBackward関数の場合、dataは呼び出し元で新規に割り当てられており、shapeについては他のオブジェクトを参照していました。

不要な再割当を除去する目的で、次の変更を加えてみてはいかがでしょうか。

  1. コンストラクタをNdArray(double[] data, int[] shape,bool is_clone)のように変更する。is_cloneはtrueの場合にコンストラクタ内でオブジェクトを複製する。falseの場合は参照してセットする。

  2. NdArrayコンストラクタのうち、dataの複製が不要なものを、new NdArray(data,shape.clone(),false)のような呼び出しに変更する。

Kelp.Javaの場合は以下のような実装を行いました。
よろしければ参考にしてください。

https://github.com/nyatla/Kelp.Java/blob/master/src/jp/nyatla/kelpjava/common/NdArray.java#L26

https://github.com/nyatla/Kelp.Java/blob/master/src/jp/nyatla/kelpjava/functions/activations/ReLU.java#L41

lossクラス関連の分離について

不具合報告ではありません。

KelpNetのloss関連の実装についてですが、今はstatic関数とdelegateで実装されています。
Javaに移植する過程で、delegateとpartial classが使えないのでアルゴリズム毎にクラス化することにしました。

https://github.com/nyatla/Kelp.Java/tree/master/src/jp/nyatla/kelpjava/loss

使い勝手はあまり変わりませんが、、気に入っていただけたらKelpNetの方も切り替えていただければと思います。

Linear.Grad is always NULL

Linear functions have NULL Grad when testing. Looks like the creation of the gradient object is commented out in all the Linear initialization functions.

Trainer クラスで使用される Array[] について

以下はnyatlaさんのこちらの指摘を抜粋したものです
#13

Trainerクラスの以下の関数でちょっと気がかりなことがあります。

       public static double Train(FunctionStack functionStack, Array input, Array teach, ILossFunction lossFunction, bool isUpdate = true)

public static double Train(FunctionStack functionStack, Array[] input, Array[] teach, ILossFunction lossFunction, bool isUpdate = true)

についてですが、引数として多次元配列を引き渡した場合に、呼び出される関数に混乱があるように見えます。
具体的には、input=double[][]とteach=double[]を引き渡した場合に、後者が選択されずに前者が選択されることがありました。
この例では当然そうなることは予測できるのですが、問題に感じるのはArrayがArray[]とArrayを区別できない点です。
やや面倒ですが、train関数は数値型ごとに次元数を固定した関数をオーバロードしたほうがよいかもしれません。

分岐のあるネットワークの書き方

KelpNetで分岐のあるニューラルネットを書くことは可能でしょうか.
FunctionStackの代わりにFunctionDictionaryというものを使えば書けるのでしょうか.
よろしければ簡単なサンプルコードをいただけると大変ありがたいです.
よろしくお願いいたします.

ModelIO<Real>.Save(nn, "test.nn"); is wrong.

When I carry out Sample01.cs, there are a wrong about save the model nn.
The sentence is ModelIO.Save(nn, "test.nn"); and the error is
System.Runtime.Serialization.InvalidDataContractException:“Virtual Method 'Void InitFunc(System.Runtime.Serialization.StreamingContext)' of type 'KelpNet.CPU.Linear`1[[System.Single, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' cannot be marked with 'System.Runtime.Serialization.OnDeserializingAttribute' attribute.”
(at file ModelIO.cs, line 63, bf.WriteObject(stream, function);
please help me, thanks.

MnistDataクラスのメンバ変数の配列構成について質問です。

以下の2変数について、配列の構造に疑問があります。

        private double[][,,] X;
        private double[][,,] Y;

変数は、[N][1,28,28]の配列になっていますが、一番先頭の要素数1が何のためのものかわかりませんでした。
(Mnistのデータ構造を走査するためか、カラーチャンネル?等の意味があるのかなとも思いましたが、今のところよくわかりません。)

この1を削除して二次元配列にすることで、何か問題を引き起こすことはありますか?なければ削除して2次元配列にしてもよいと思います。

また、以下の2変数についても同様に一時配列でよいと思います。

        private int[][] Tx;
        private int[][] Ty;

FunctionStack#optimizers変数とSetOptimizer関数について提案

FunctionStack#optimizers変数とSetOptimizer関数について提案です。

SetOptimizerを廃止し、FunctionStackのコンストラクタとSetOptimizerを統合してはいかがでしょうか。
具体的には、

 public FunctionStack(params Function[] functions) 

 public FunctionStack(Function[] functions,Optimizer[] optimizers)  //学習用
 public FunctionStack(params Function[] functions)  //予測用

の2つに変更する提案です。

SetOptimizer関数はFunctionStackのコンストラクタの直後で呼び出される使い方をされていますが、他の使い方をしている部分がなさそうです。

動作中にoptimizersを切り替えを許容しているかにもよりますが、もし許容していないならば、コンストラクタで固定してしまったほうが、実装時にSetOptimizerの呼び出し忘れを防ぐことを期待できます。

予測時にはコンストラクタ内でoptimizers変数をnullで固定しても差し支えない?と思いますが、如何でしょうか。

Such a phenomenal library

Hi - This appears to be such a phenomenal library. Sadly, I can find very few people actually using it, and very little documentation or discussion about how to use it. This library would appear to fill a HUGE gap in the c# ecosystem with regards to NN, but without a Wiki or some active discussion space, it seems its uptake is very small. The author did an amazing job putting it all together as far as I can see. I realise English is not his first tongue and perhaps that is part of the issue with regards to people like myself trying to find good examples. If anyone can suggest any resources for English discussion/examples using the library, that would be much appreciated. I've not found another library that appears to be as complete, or easily implemented. It seems to me that with a few pages on the Wiki, this library use would explode.

BatchNormalizationの分割について

改善提案です。

BatchNormalizationクラスについてですが、学習ありと学習なしが同一クラスに実装されているために見通しが悪くなっているように見えます。

共通部分が多いので1つのクラスにまとめたものと思われますが、BatchNormalizationWithoutTrainとBatchNormalizationのように、2つのクラスに分けてみてはいかがでしょうか。

IsTrainの分岐が削除できると、いくつかのメンバ変数が削除できて、全体の見通しが良くなると思います。

RNN系のテストが失敗する

いつもライブラリ作成お疲れ様です。
既知の問題かもしれませんが、Sample08(LSTMによるSin関数の学習)、Sample10(LSTMによるRNNLM)のサンプルを動かすとBackwardの途中でSystem.ArgumentOutOfRangeExceptionが発生してしまい困っています。

具体的には
SingleInputFunction.cs(25行目)の
NdArray[] xs = PrevInputs[PrevInputs.Count - 1];
でPrevInputs.Countが0のときがありインデックスが-1となりエラーになります。
Sample08は即座に発生し、Sample10は十数分動かすと発生します。
Sample09は30分程度動かした限りは問題なく動いていそうです。

環境依存の問題ではなさそうに思えますがそちらの環境で再現できない場合は動作環境の詳細情報を追記したいと思います。

以上よろしくお願いします。

How can this be achieved?

XOR tutorial is like this
X -> [[1,0], [0,1], [0,0], [1,1]]
Y -> [[1], [0], [0], [1]]

I want this, how should I achieve it?

X -> [[1,0,0], [0,1,0], [0,0,1], [1,1,1]]
Y -> [[1,0], [0,1], [0,0], [1,1]]

How to set up FunctionStack?

thank you very much!

Waifu2x example is not working.

The program is crashing at DynamicJsom:257 with System.InvalidCastException (Cannot convert Double to KelpNet.Common.Real). And I changed it to return (Real)(double)value; when elementType is Real like this.

After then, the program makes another problem in FormMain:61. In the program, it said just ignore errors, but if then all data indexing skipped. So I fixed it to like this

And then, it has still problem in indexing too. Some of conv weight data formatted into [preCh, nextCh, kW, kH], not [nextCh, preCh, kW, kH]. So I just right some hard code patches like this

After all, result images are wrong. It produced just some glitched images.
I have no idea my model json is wrong or program is wrong.

Unityで学習済みモデルのロードに失敗する

Unityで使用する際モデルのロードにXmlExceptionで失敗する。

NetDataContractSerializerをBinaryFormatterに置き換えることで回避が可能。
したがってUnityで使用されているNetDataContractSerializerの使用に問題がありそう。

sample links have expired

The training is slow and can't put the GPU under heavy load.

The training is slow and can't put the GPU under heavy load.
cpu load 18% I7 9700K
gpu load 3% RTX 2070

release mode.

How should I improve the performance? Thanks.

    [STAThread]
    static void Main()
    {
          OpenCL.Initialize(ComputeDeviceTypes.Gpu, 0);
          
          //Test6を連結してFashion-MNISTを学習
          Sample14.Run();
    }

How to use KelpNet in C# project

Hi ,It is very nice to know your Team use C# to AI.
I have the following quesion
1.In my VS 2017, build your project error
The feature "unmanaged generic type constraint" is not supported in C # 7.0. Please use language version 7.3 or higher
image
but I cannot to choose the other platform, the hightest is only 2.0

2.Do you have some doccument to let me know how to using your dll files in ourself project.
I cannot find any sample in your project. So ,cloud you please share more sample .

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.