在C#或Unity中执行Python脚本

3
我在Python中使用Keras设计了一个神经网络,用于计算类似于降噪函数的东西。目前它运行得很好,现在我想使用这个网络来清洗我的Unity项目中的数据。
我原本认为这不会太困难。但是我只能在资产商店中找到一个不支持外部Python库的Python解释器。IronPython也不是一个选项,因为我需要包含Keras软件包。我在GitHub上找到了一个名为KerasSharp的项目,但没有关于如何加载已训练好的网络的文档,而且在开始训练它也不是一个选项。此外,由于提交历史记录和未回答的问题,看起来已经没有人再开发该项目了。通过网络API访问脚本可能也不是一个好选择,因为存在延迟。我需要每一帧都进行计算。
所以我的问题是:有没有办法将Keras / TensorFlow模型加载到C#或Unity中?
或者
我是否可以以某种方式访问计算噪声减少函数的python脚本,该脚本使用了Keras模型?
1个回答

3
如果您的情况允许您在Unity之后启动python脚本,您可以尝试像这里描述的那样将python脚本作为子进程启动: http://answers.unity.com/answers/14156/view.html

If you do not require the other process to be running before the Unity one, you could have your Unity project launch that via Process and then redirect stdin/out to streams and communicate through these.

Example:

Process otherProcess = new Process ();
otherProcess.StartInfo.FileName = path;
otherProcess.StartInfo.CreateNoWindow = true;
otherProcess.StartInfo.UseShellExecute = false;
otherProcess.StartInfo.RedirectStandardInput = true;
otherProcess.StartInfo.RedirectStandardOutput = true;

// Now communicate via streams
//     otherProcess.StandardOutput
// and
//     otherProcess.StandardInput

It is also possible that grabbing a running process by name or pid and then setting the forwarding would work, but I've not tested this and it does seem rather doubtful.

这个设置需要您的Python脚本能够从标准输入中接收数据,并通过标准输出输出结果。


1
这正是我一直在寻找的!我考虑过查看SO / SI,但不知道如何开始使用C#脚本来获取访问权限。谢谢@Ruzihm - TheBlackBird

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接