示例#1
0
 public AveragePooling2D(PyArray <T> kSize, PyArray <T> stride, PyArray <T> pad)
 {
     this._kSize   = kSize;
     this._stride  = stride;
     this._pad     = pad;
     _maxPooling2D = Chainer.Functions["average_pooling_2d"];
 }
示例#2
0
 public MaxPooling2D(PyArray <T> kSize, PyArray <T> stride, PyArray <T> pad, bool coverAll = true)
 {
     this._kSize    = kSize;
     this._stride   = stride;
     this._pad      = pad;
     this._coverAll = coverAll;
     _maxPooling2D  = Chainer.Functions["max_pooling_2d"];
 }
示例#3
0
        private IntPtr WriteDataPort(IntPtr self, IntPtr args)
        {
            var argTuple = new PyTuple(new PyObject(args, false));
            var data     = new PyArray(argTuple.Get(0));
            var portName = argTuple.Get(1).GetString();
            var dataPort = OutputPorts.First(port => port.Name == portName) as NodeSystemLib2.FormatData1D.OutputPortData1D;

            var result = data.ToArrayDouble();

            dataPort.Buffer.Write(result, 0, result.Length);

            return(new PyLong(1, false).Handle);
        }
示例#4
0
 public Deconvolution2D(int inChannels, int outChannels, PyArray <T> kSize, PyArray <T> stride, PyArray <T> pad, bool nobias, PyObject[] outSize, PyArray <T> initialW, PyArray <T> initialBias)
 {
     _deconvolution2D = Chainer.Links["Deconvolution2D"].Call(inChannels, outChannels, kSize, stride, pad, nobias, PyTuple.Pack(outSize), initialW, initialBias);
     _deconvolution2D["cleargrads"].Call();
 }
示例#5
0
 public EmbedID(int inSize, int outSize, PyArray <T> initialW = default(PyArray <T>))
 {
     _embedID = Chainer.Links["EmbedID"].Call(inSize, outSize, initialW);
     _embedID["cleargrads"].Call();
 }
示例#6
0
 public Linear(int inSize, int outSize, bool noBias, PyArray <T> initialW, PyArray <T> initialBias)
 {
     _linear = Chainer.Links["Linear"].Call(inSize, outSize, noBias, initialW, initialBias);
     _linear["cleargrads"].Call();
 }
示例#7
0
 public Variable(PyArray <T> array)
 {
     _rawData = Chainer.Variable.Call(array);
 }
示例#8
0
 public LSTM(int inSize, int outSize, PyArray <T> lateralInit = default(PyArray <T>), PyArray <T> upwardInit = default(PyArray <T>), PyArray <T> biasInit = default(PyArray <T>), PyArray <T> forgetBiasInit = default(PyArray <T>))
 {
     _lstm = Chainer.Links["LSTM"].Call(inSize, outSize, lateralInit, upwardInit, biasInit, forgetBiasInit);
     _lstm["cleargrads"].Call();
 }
示例#9
0
 public Convolution2D(int inChannels, int outChannels, PyArray <T> kSize, PyArray <T> stride, PyArray <T> pad, bool nobias, PyArray <T> initialW, PyArray <T> initialBias)
 {
     _convolution2D = Chainer.Links["Convolution2D"].Call(inChannels, outChannels, kSize, stride, pad, nobias, initialW, initialBias);
     _convolution2D["cleargrads"].Call();
 }
示例#10
0
        static void Main(string[] args)
        {
            Python py = new Python();

            TestType[,] array =
            {
                { 0, 1,  2,  3 },
                { 4, 5,  6,  7 },
                { 8, 9, 10, 11 }
            };

            //arrayの内容をPythonに送信
            PyArray <TestType> x = array;

            //pythonで受信したxを表示する
            Python.Print(x);

            Console.WriteLine("\n> pyBuffer[2, 1] += 100 From C#");

            //Pythonの値をC#から変更するクラスを作成
            x[2, 1] += 100;

            //c#から変更した結果を表示する
            Python.Print(x);

            //xをPythonのyに転送
            py["y"] = x;

            Console.WriteLine("\n> pyBuffer += 1000 From C#");

            //xのすべての値に1000を加算する
            x += 1000;

            //加算したxを表示する
            Python.Print(x);

            Console.WriteLine("\n> pytest(x) in Python");

            //pytest.pyを読み込む
            dynamic pyTest = new PyDynamicModule("pytest");

            //test内の関数calcを呼び出す
            x = pyTest.calc(x);

            //関数の結果を表示する
            Python.Print(x);

            Console.WriteLine("\n> Add array From C#");

            //加算用の配列を作る
            TestType[] addArray = { 10000, 20000, 30000, 40000 };

            //xのすべての値にaddArrayを加算する
            x += addArray;

            //加算したxを表示する
            Python.Print(x);

            Console.WriteLine("\n> Set array From C#");

            //セット用の配列を作る
            TestType[] setArray = { 1111, 2222, 3333, 4444 };

            //Pythonの値をC#から変更するクラスを作成
            PyArray <TestType[]> pyArrayBuffer = new PyArray <TestType[]>(x);

            //x[1]にsetArrayを設定する
            pyArrayBuffer[1] = setArray;

            //加算したxを表示する
            Python.Print(x);

            //計算したxをC#で取得
            TestType[,] destArrayX = (TestType[, ])x;

            //Pythonで宣言したyをC#で取得
            PyArray <TestType> pyNdArrayBuffer = py["y"];

            TestType[,] destArrayY = (TestType[, ])pyNdArrayBuffer;

            //取得したXの中身を表示
            Console.WriteLine("\n> Console.WriteLine(x[i, j]) from C#");
            for (int i = 0; i < destArrayX.GetLength(0); i++)
            {
                for (int j = 0; j < destArrayX.GetLength(1); j++)
                {
                    Console.WriteLine(i * destArrayX.GetLength(1) + j + " : " + destArrayX[i, j]);
                }
            }

            //取得したYの中身を表示
            Console.WriteLine("\n> Console.WriteLine(y[i, j]) from C#");
            for (int i = 0; i < destArrayY.GetLength(0); i++)
            {
                for (int j = 0; j < destArrayY.GetLength(1); j++)
                {
                    Console.WriteLine(i * destArrayY.GetLength(1) + j + " : " + destArrayY[i, j]);
                }
            }

            Console.WriteLine("Done.");
            Console.Read();
        }
 public override string GetPyCode(PyEmitStyle style)
 {
     return(string.Format("{0}[{1}]", PyArray.GetPyCode(style), Index.GetPyCode(style)));
 }
示例#12
0
 public PyObject[] Forward(PyObject x, PyArray <int> indices, int axis = 1)
 {
     return(PyTuple.UnPack(_splitAxis.Call(x, indices, axis)));
 }
示例#13
0
文件: Linear.cs 项目: ohisama/KelpNet
 public Linear(int inSize, int outSize, bool noBias = false, PyArray <T> initialW = default(PyArray <T>), PyArray <T> initialBias = default(PyArray <T>))
 {
     _linear = Chainer.Links["Linear"].Call(inSize, outSize, noBias, initialW, initialBias);
     ClearGrads();
 }