Ejemplo n.º 1
0
        public static string to_numpy_string(Tensor tensor)
        {
            var dtype = tensor.dtype;

            if (dtype == TF_DataType.TF_STRING)
            {
                if (tensor.rank == 0)
                {
                    return("'" + string.Join(string.Empty, tensor.StringBytes()[0]
                                             .Take(25)
                                             .Select(x => x < 32 || x > 127 ? "\\x" + x.ToString("x") : Convert.ToChar(x).ToString())) + "'");
                }
                else
                {
                    return($"['{string.Join("', '", tensor.StringData().Take(25))}']");
                }
            }
            else if (dtype == TF_DataType.TF_VARIANT)
            {
                return("<unprintable>");
            }
            else if (dtype == TF_DataType.TF_RESOURCE)
            {
                return("<unprintable>");
            }

            var nd = tensor.numpy();

            if (nd.size == 0)
            {
                return("[]");
            }

            return(nd.ToString());
        }
Ejemplo n.º 2
0
        public static string to_numpy_string(Tensor tensor)
        {
            var dtype = tensor.dtype;

            if (dtype == TF_DataType.TF_STRING)
            {
                if (tensor.rank == 0)
                {
                    return("'" + string.Join(string.Empty, tensor.StringBytes()[0]
                                             .Take(25)
                                             .Select(x => x < 32 || x > 127 ? "\\x" + x.ToString("x") : Convert.ToChar(x).ToString())) + "'");
                }
                else
                {
                    return($"['{string.Join("', '", tensor.StringData().Take(25))}']");
                }
            }

            var nd = tensor.numpy();

            if (nd.size == 0)
            {
                return("[]");
            }

            switch (dtype)
            {
            case TF_DataType.TF_STRING:
                return(string.Join(string.Empty, nd.ToArray <byte>()
                                   .Select(x => x < 32 || x > 127 ? "\\x" + x.ToString("x") : Convert.ToChar(x).ToString())));

            case TF_DataType.TF_BOOL:
                return(nd.GetBoolean(0).ToString());

            case TF_DataType.TF_VARIANT:
            case TF_DataType.TF_RESOURCE:
                return("<unprintable>");

            default:
                return(nd.ToString());
            }
        }