unity sentis 2.1.0

unity sentis 2.1.0学习记录帖

unity sentis 2.1.0手写字体识别



前言

随着unity6的发布 记录自己学习历程


一、使用步骤

1. 引入库

代码如下(省去安装步骤):

using UnityEngine;
using Unity.Sentis;

2. 将 softmax 层添加到模型的末尾

代码如下(示例):

FunctionalGraph graph = new FunctionalGraph();
// Set the inputs of the graph from the original model inputs and return an array of functional tensors
FunctionalTensor[] inputs = graph.AddInputs(runtimeModel);
FunctionalTensor[] outputs = Functional.Forward(runtimeModel, inputs);
// Calculate the softmax of the first output with the functional API.
FunctionalTensor softmax = Functional.Softmax(outputs[0]);

// Create a model with softmax by compiling the functional graph.
runtimeModel = graph.Compile(softmax);

3. 实现

// 将输入数据创建为张量
Tensor inputTensor = TextureConverter.ToTensor(inputTexture, width: 28, height: 28, channels: 1);
// 创建引擎
worker = new Worker(runtimeModel, BackendType.GPUCompute);
// 使用输入数据运行模型
worker.Schedule(inputTensor);
//Get the result
Tensor<float> outputTensor = worker.PeekOutput() as Tensor<float>;
results = outputTensor.DownloadToArray();
Debug.Log("识别结果:" + GetValue(results));

private int GetValue(float[] results)
{
    int index = 0;
    float value = 0;
    for (int i = 0; i < results.Length; i++)
    {
        if (value < results[i])
        {
            value = results[i];
            index = i;
        }
    }
    return index;
}

调整输出得到结果,索引值为结果值


在这里插入图片描述

总结

just soso

### Unity Sentis 技术概览 Unity Sentis 是一款允许开发者在 Unity 运行时环境中部署和运行人工智能模型的技术工具集[^1]。通过该平台,可以实现机器学习算法与游戏或交互应用的无缝集成。 #### 使用方法概述 为了简化AI模型的应用流程,Unity Sentis 提供了一系列API接口来加载预训练好的神经网络并处理输入输出数据流。具体来说,在实际项目开发过程中,通常会按照如下方式操作: - **初始化环境配置**:确保本地安装有支持TensorFlow Lite或其他兼容框架版本; - **导入必要的库文件**:将官方提供的SDK包加入到工程依赖项列表里; - **编写调用逻辑代码**:依据业务需求设计推理过程中的前后置动作以及结果解析机制; 下面是一段简单的Python风格伪代码用于说明如何在一个场景内实例化并激活已有的DL模型[^2]: ```python import unitysentis as us def setup_model(): model_path = "path/to/your/model.tflite" # 加载模型 dl_model = us.load(model_path) return dl_model def predict(input_data, loaded_model): output = loaded_model.predict(input_data) return output ``` 此段脚本展示了基本的工作模式——先指定路径读取外部存储下来的二进制权重参数集合,再利用这些信息构建起可供预测使用的计算图结构体对象。 #### 教程推荐 对于初学者而言,可以从以下几个方面入手了解更深入的知识点: - 官方文档提供了详尽的功能描述和技术细节指导; - 社区论坛上有很多热心人士分享的经验贴子值得借鉴; - YouTube平台上存在大量实操视频可以帮助快速入门掌握核心技能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值