Пример #1
0
    public static void SVD(float[,] covMat, out float[] s, out float[,] v)
    {
        TFShape shape       = new TFShape(covMat.GetLength(0), covMat.GetLength(1));
        var     reshaped    = covMat.Reshape();
        var     inputTensor = TFTensor.FromBuffer(shape, reshaped, 0, reshaped.Length);

        TFGraph  svdGraph  = new TFGraph();
        TFOutput input     = svdGraph.Placeholder(TFDataType.Float, shape);
        var      svdResult = (ValueTuple <TFOutput, TFOutput, TFOutput>)svdGraph.Svd(input, true);

        var sess   = new TFSession(svdGraph);
        var runner = sess.GetRunner();

        runner.AddInput(input, inputTensor);
        runner.Fetch(svdResult.Item1);
        runner.Fetch(svdResult.Item2);

        TFTensor[] results = runner.Run();
        s = (float[])results[0].GetValue();
        v = (float[, ])results[1].GetValue();
        TFStatus temp = new TFStatus();

        sess.CloseSession(temp);
        sess.DeleteSession(temp);
    }
Пример #2
0
        public void Dispose()
        {
            lock (this)
            {
                if (!IsDisposed)
                {
                    IsDisposed = true;

                    if (TensorSource != null)
                    {
                        foreach (var tensor in TensorSource)
                        {
                            tensor.Dispose();
                        }
                    }
                    if (TensorTarget != null)
                    {
                        foreach (var tensor in TensorTarget)
                        {
                            tensor.Dispose();
                        }
                    }

                    Session?.DeleteSession();
                }
            }
        }
Пример #3
0
        public void Dispose()
        {
            lock (this)
            {
                if (!IsDisposed)
                {
                    IsDisposed = true;

                    if (TensorMicTile != null)
                    {
                        foreach (var tensor in TensorMicTile)
                        {
                            tensor.Dispose();
                        }
                    }
                    if (TensorMicTilePredict != null)
                    {
                        foreach (var tensor in TensorMicTilePredict)
                        {
                            tensor.Dispose();
                        }
                    }
                    if (TensorTrainingLabels != null)
                    {
                        foreach (var tensor in TensorTrainingLabels)
                        {
                            tensor.Dispose();
                        }
                    }
                    if (TensorTrainingWeights != null)
                    {
                        foreach (var tensor in TensorTrainingWeights)
                        {
                            tensor.Dispose();
                        }
                    }

                    Session.DeleteSession();
                }
            }
        }
Пример #4
0
        public void Dispose()
        {
            lock (this)
            {
                if (!IsDisposed)
                {
                    IsDisposed = true;

                    foreach (var tensor in TensorSource)
                    {
                        tensor.Dispose();
                    }
                    foreach (var tensor in TensorWeightSource)
                    {
                        tensor.Dispose();
                    }

                    Session.DeleteSession();
                }
            }
        }
Пример #5
0
        public void Dispose()
        {
            lock (this)
            {
                if (!IsDisposed)
                {
                    IsDisposed = true;

                    foreach (var tensor in TensorMicTile)
                    {
                        tensor.Dispose();
                    }
                    foreach (var tensor in TensorTrainingLabels)
                    {
                        tensor.Dispose();
                    }

                    Session.DeleteSession();
                }
            }
        }