/// <summary> /// Add a Tensor information to the TensorsInfo instance. Note that we support up to 16 tensors in TensorsInfo. /// </summary> /// <param name="name">Name of Tensor.</param> /// <param name="type">Data element type of Tensor.</param> /// <param name="dimension">Dimension of Tensor. Note that we support up to 4th ranks.</param> /// <feature>http://tizen.org/feature/machine_learning.inference</feature> /// <exception cref="IndexOutOfRangeException">Thrown when the number of Tensor already exceeds the size limits (i.e. Tensor.SlzeLimit)</exception> /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception> /// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception> /// <since_tizen> 6 </since_tizen> public void AddTensorInfo(string name, TensorType type, int[] dimension) { NNStreamer.CheckNNStreamerSupport(); int idx = _infoList.Count; if (idx >= Tensor.SizeLimit) { throw new IndexOutOfRangeException("Max size of the tensors is " + Tensor.SizeLimit); } _infoList.Add(new TensorInfo(name, type, dimension)); if (_handle != IntPtr.Zero) { NNStreamerError ret = NNStreamerError.None; ret = Interop.Util.SetTensorsCount(_handle, _infoList.Count); NNStreamer.CheckException(ret, "unable to set the number of tensors"); ret = Interop.Util.SetTensorType(_handle, idx, type); NNStreamer.CheckException(ret, "fail to set TensorsInfo type"); ret = Interop.Util.SetTensorDimension(_handle, idx, dimension); NNStreamer.CheckException(ret, "fail to set TensorsInfo dimension"); } }
/// <summary> /// Sets the tensor type with given index and its type. /// </summary> /// <param name="idx">The index of the tensor to be updated.</param> /// <param name="type">The tensor type to be set.</param> /// <feature>http://tizen.org/feature/machine_learning.inference</feature> /// <exception cref="IndexOutOfRangeException">Thrown when the index is greater than the number of Tensor.</exception> /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception> /// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception> /// <since_tizen> 6 </since_tizen> public void SetTensorType(int idx, TensorType type) { CheckIndexBoundary(idx); _infoList[idx].Type = type; if (_handle != IntPtr.Zero) { NNStreamerError ret = NNStreamerError.None; ret = Interop.Util.SetTensorType(_handle, idx, type); NNStreamer.CheckException(ret, "unable to set the type of tensor: " + idx.ToString()); } }
private void UpdateInfoHandle(IntPtr handle, int idx, string name, TensorType type, int[] dimension) { if (handle != IntPtr.Zero) { NNStreamerError ret = NNStreamerError.None; ret = Interop.Util.SetTensorName(handle, idx, name); NNStreamer.CheckException(ret, "Failed to set the name of tensor at index " + idx.ToString()); ret = Interop.Util.SetTensorType(handle, idx, type); NNStreamer.CheckException(ret, "Failed to set the type of tensor at index " + idx.ToString()); ret = Interop.Util.SetTensorDimension(handle, idx, dimension); NNStreamer.CheckException(ret, "Failed to set the dimension of tensor at index " + idx.ToString()); } }
private static Layer ParseInputVariableNode(ValueInfoProto node, Dictionary <string, TensorType> types, Dictionary <string, OutputConnector> outputConns) { var desiredType = TensorType.From(node.Type); types.Add(node.Name, desiredType); if (desiredType.ElementType == typeof(double)) { var layer = new InputVariable <double>(node.Name, desiredType.Dimensions); outputConns.Add(node.Name, layer.Value); return(layer); } else { throw new NotSupportedException(); } }
private static Layer ParseConstantNode(NodeProto node, Dictionary <string, TensorType> types, Dictionary <string, OutputConnector> outputConns) { var value = node.Attribute.Single(o => o.Name == "value").T; var desiredType = TensorType.From(value); types.Add(node.Output[0], desiredType); if (desiredType.ElementType == typeof(double)) { Memory <double> mem; switch (value.DataType) { case TensorProto.Types.DataType.Float: mem = (from f in value.FloatData select(double) f).ToArray(); break; case TensorProto.Types.DataType.Double: mem = value.DoubleData.ToArray(); break; default: throw new NotSupportedException(); } var tensor = new DenseTensor <double>(mem, desiredType.Dimensions); var layer = new Constant <double>(tensor) { Name = node.Name }; outputConns.Add(node.Output[0], layer.Value); return(layer); } else { throw new NotSupportedException(); } }
/// <summary> /// Add a Tensor information to the TensorsInfo instance. Note that we support up to 16 tensors in TensorsInfo. /// </summary> /// <param name="type">Data element type of Tensor.</param> /// <param name="dimension">Dimension of Tensor. Note that we support up to 4th ranks.</param> /// <feature>http://tizen.org/feature/machine_learning.inference</feature> /// <exception cref="IndexOutOfRangeException">Thrown when the number of Tensor already exceeds the size limits (i.e. Tensor.SizeLimit)</exception> /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception> /// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception> /// <since_tizen> 6 </since_tizen> public void AddTensorInfo(TensorType type, int[] dimension) { NNStreamer.CheckNNStreamerSupport(); AddTensorInfo(null, type, dimension); }
public TensorInfo(string name, TensorType type, int[] dimension) { Name = name; Type = type; SetDimension(dimension); }
public TensorInfo(TensorType type, int[] dimension) { Type = type; SetDimension(dimension); }
public PseudoTensor(string n, int rank, int dim, TensorType tt) { Rank = rank; Dimension = dim; tensorType = tt; if (rank == 0) { Rank0Tensor = new PseudoRank0Tensor(n); Rank0Tensor.tensorType = this.tensorType; Rank0Tensor.Dimension = this.Dimension; Rank0Tensor.Rank = this.Rank; } if (rank == 1) { Rank1Tensor = new PseudoRank1Tensor(); Rank1Tensor.tensorType = this.tensorType; Rank1Tensor.Dimension = this.Dimension; Rank1Tensor.Rank = this.Rank; string strTensorType = (tensorType == TensorType.Contravariant) ? "^" : "_"; for (int i = 0; i < this.Dimension; i++) { string val = $"{n}{strTensorType}{(i + 1).ToString()}"; Symbol sym = new Symbol(); sym.Expression = val; sym.LatexString = val; Rank1Tensor.Add(sym); } } if (rank == 2) { Rank2Tensor = new PseudoRank2Tensor(Dimension, Dimension); Rank2Tensor.tensorType = this.tensorType; Rank2Tensor.Dimension = this.Dimension; Rank2Tensor.Rank = this.Rank; string strTensorType = "_{ij}"; if (tensorType == TensorType.Contravariant) { strTensorType = "^{ij}"; } if (tensorType == TensorType.Mixed) { strTensorType = "_i^j"; } for (int i = 0; i < Rank2Tensor.Rows; i++) { for (int j = 0; j < Rank2Tensor.Columns; j++) { string val = n + strTensorType; val = val.Replace("i", (i + 1).ToString()).Replace("j", (j + 1).ToString()); Symbol sym = new Symbol(); sym.Expression = val; sym.LatexString = val; Rank2Tensor[i, j] = sym; } } } }
internal static extern NNStreamerError GetTensorType(IntPtr info, int index, out TensorType type);
/// <summary> /// Add a Tensor information to the TensorsInfo instance. Note that we support up to 16 tensors in TensorsInfo. /// </summary> /// <param name="type">Data element type of Tensor.</param> /// <param name="dimension">Dimension of Tensor. Note that we support up to 4th ranks.</param> /// <feature>http://tizen.org/feature/machine_learning.inference</feature> /// <exception cref="IndexOutOfRangeException">Thrown when the number of Tensor already exceeds the size limits (i.e. Tensor.SlzeLimit)</exception> /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception> /// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception> /// <since_tizen> 6 </since_tizen> public void AddTensorInfo(TensorType type, int[] dimension) { AddTensorInfo(null, type, dimension); }