C# ini读取一个节点下所有键值

[DllImport("kernel32.dll")]
private static extern int GetPrivateProfileSection(string lpAppName, byte[] lpszReturnBuffer, int nSize, string lpFileName);

public static Dictionary<string, string> GetKeys(string iniFile, string category)
{

    byte[] buffer = new byte[2048];

    GetPrivateProfileSection(category, buffer, 2048, iniFile);
    String[] tmp = Encoding.Default.GetString(buffer).Trim('\0').Split('\0');
    Dictionary<string, string> result = new Dictionary<string, string>();
    foreach (String entry in tmp)
    {
        string[] v = entry.Split('=');
        result.Add(v[0], v[1]);
    }
    return result;
}

 

  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
读取 ONNX 模型中每个节点的数据,可以使用 ONNX Runtime 库。以下是 C# 代码示例: ```csharp using System; using System.Collections.Generic; using Microsoft.ML.OnnxRuntime; using Microsoft.ML.OnnxRuntime.Tensors; class Program { static void Main(string[] args) { // Load the ONNX model var modelPath = "model.onnx"; var session = new InferenceSession(modelPath); // Get the input and output node names var inputName = session.InputMetadata.Keys.First(); var outputName = session.OutputMetadata.Keys.First(); // Prepare the input tensor var tensor = new DenseTensor<float>(new[] { 1, 3 }, new float[] { 1, 2, 3 }); // Run the inference var inputs = new List<NamedOnnxValue> { NamedOnnxValue.CreateFromTensor(inputName, tensor) }; var results = session.Run(inputs); // Print the output tensor shape and data var outputTensor = results.First().AsTensor<float>(); Console.WriteLine($"Output shape: {string.Join(",", outputTensor.Dimensions)}"); Console.WriteLine($"Output data: {string.Join(",", outputTensor.ToArray())}"); // Print the data for each node in the graph foreach (var node in session.Graph.Nodes) { var nodeOutputName = node.Outputs.First(); var nodeOutput = results.First(output => output.Name == nodeOutputName).AsTensor<float>(); Console.WriteLine($"Data for node {node.Name}: {string.Join(",", nodeOutput.ToArray())}"); } } } ``` 在上面的代码中,我们首先加载 ONNX 模型并获取输入和输出节点的名称。然后,我们准备输入张量并运行推理。最后,我们打印输出张量的形状和数据,并使用 foreach 循环遍历图中的每个节点并打印其输出数据。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值