Beispiel #1
0
        /// <summary>
        /// Get the shape value of the attribute
        /// </summary>
        /// <param name="attrName">The name of the attribute</param>
        /// <param name="status">The status</param>
        /// <returns>The shape</returns>
        public Int64[] GetAttrShape(String attrName, Status status = null)
        {
            using (StatusChecker checker = new StatusChecker(status))
            {
                AttrMetadata meta = GetAttrMetadata(attrName, status);
                if (meta.Type != AttrType.Shape)
                {
                    throw new ArgumentException(String.Format("Attribute {0} ({1}) is not a shape", attrName, meta.Type));
                }

                if (meta.TotalSize == 0)
                {
                    return(null);
                }

                Int64[]  shape  = new Int64[meta.IsList? meta.ListSize : meta.TotalSize];
                GCHandle handle = GCHandle.Alloc(shape, GCHandleType.Pinned);
                try
                {
                    TfInvoke.tfeOperationGetAttrShape(_ptr, attrName, handle.AddrOfPinnedObject(), shape.Length,
                                                      checker.Status);
                }
                finally
                {
                    handle.Free();
                }

                return(shape);
            }
        }
Beispiel #2
0
 /// <summary>
 /// Get the metadata of the attribute
 /// </summary>
 /// <param name="attrName">The name of the attribute</param>
 /// <param name="status">The status</param>
 /// <returns>The attribute meta data</returns>
 public AttrMetadata GetAttrMetadata(String attrName, Status status = null)
 {
     using (StatusChecker checker = new StatusChecker(status))
     {
         AttrMetadata meta = new AttrMetadata();
         TfInvoke.tfeOperationGetAttrMetadata(_ptr, attrName, ref meta, checker.Status);
         return(meta);
     }
 }
Beispiel #3
0
        /// <summary>
        /// Get the attribute type
        /// </summary>
        /// <param name="attrName">The name of the attribute</param>
        /// <param name="status">The status</param>
        /// <returns>The type of the attribute</returns>
        public DataType GetAttrType(String attrName, Status status = null)
        {
            using (StatusChecker checker = new StatusChecker(status))
            {
                AttrMetadata meta = GetAttrMetadata(attrName, status);
                if (meta.Type != AttrType.Type)
                {
                    throw new ArgumentException(String.Format("Attribute {0} ({1}) is not a type", attrName, meta.Type));
                }

                return(TfInvoke.tfeOperationGetAttrType(_ptr, attrName, checker.Status));
            }
        }
Beispiel #4
0
        /// <summary>
        /// Get the value of the attribute that is a Tensor
        /// </summary>
        /// <param name="attrName">The name of the attribute</param>
        /// <param name="status">The status</param>
        /// <returns>The Tensor value of the attribute</returns>
        public Tensor GetAttrTensor(String attrName, Status status = null)
        {
            using (StatusChecker checker = new StatusChecker(status))
            {
                AttrMetadata meta = GetAttrMetadata(attrName, status);
                if (meta.Type != AttrType.Tensor)
                {
                    throw new ArgumentException(String.Format("Attribute {0} ({1}) is not a Tensor", attrName, meta.Type));
                }

                IntPtr tensorPtr = TfInvoke.tfeOperationGetAttrTensor(_ptr, attrName, checker.Status);
                return(new Tensor(tensorPtr));
            }
        }
Beispiel #5
0
        /// <summary>
        /// Get the tensor shape proto value of the attribute
        /// </summary>
        /// <param name="attrName">The name of the attribute</param>
        /// <param name="status">The status</param>
        /// <returns>The buffer that contains the TensorShapeProto </returns>
        public Buffer GetAttrTensorShapeProto(String attrName, Status status = null)
        {
            using (StatusChecker checker = new StatusChecker(status))
            {
                AttrMetadata meta = GetAttrMetadata(attrName, status);
                if (meta.Type != AttrType.Shape)
                {
                    throw new ArgumentException(String.Format("Attribute {0} ({1}) is not a shape", attrName, meta.Type));
                }

                Buffer buffer = new Buffer();
                TfInvoke.tfeOperationGetAttrTensorShapeProto(_ptr, attrName, buffer, checker.Status);
                return(buffer);
            }
        }
Beispiel #6
0
        /// <summary>
        /// Get the value of the attribute that is a String
        /// </summary>
        /// <param name="attrName">The name of the attribute</param>
        /// <param name="status">The status</param>
        /// <returns>The string value of the attribute</returns>
        public String GetAttrString(String attrName, Status status = null)
        {
            using (StatusChecker checker = new StatusChecker(status))
            {
                AttrMetadata meta = GetAttrMetadata(attrName, status);
                if (meta.Type != AttrType.String)
                {
                    throw new ArgumentException(String.Format("Attribute {0} ({1}) is not a String", attrName, meta.Type));
                }

                IntPtr s = Marshal.AllocHGlobal((int)meta.TotalSize);
                try
                {
                    TfInvoke.tfeOperationGetAttrString(_ptr, attrName, s, (int)meta.TotalSize, checker.Status);
                    return(Marshal.PtrToStringAnsi(s));
                }
                finally
                {
                    Marshal.FreeHGlobal(s);
                }
            }
        }
Beispiel #7
0
        /// <summary>
        /// Get the value of the attribute that is a list of Int64
        /// </summary>
        /// <param name="attrName">The name of the attribute</param>
        /// <param name="status">The status</param>
        /// <returns>A list ofInt64</returns>
        public Int64[] GetAttrIntList(String attrName, Status status = null)
        {
            using (StatusChecker checker = new StatusChecker(status))
            {
                AttrMetadata meta = GetAttrMetadata(attrName, status);
                if (!((meta.Type == AttrType.Int) && meta.IsList))
                {
                    throw new ArgumentException(String.Format("Attribute {0} ({1}) is not a List of Int", attrName, meta.Type));
                }

                Int64[]  list   = new Int64[meta.ListSize];
                GCHandle handle = GCHandle.Alloc(list, GCHandleType.Pinned);
                try
                {
                    TfInvoke.tfeOperationGetAttrIntList(_ptr, attrName, handle.AddrOfPinnedObject(), list.Length, checker.Status);
                }
                finally
                {
                    handle.Free();
                }
                return(list);
            }
        }
Beispiel #8
0
 internal static extern void tfeOperationGetAttrMetadata(
     IntPtr oper,
     [MarshalAs(TfInvoke.StringMarshalType)]
     String attrName,
     ref AttrMetadata meta,
     IntPtr status);