简体   繁体   English

从 ns3 内部执行外部 python 文件

[英]Executing external python file from inside ns3

I have a python file, containing a pre-trained model. How can I execute this file from inside ns-3 code?我有一个 python 文件,其中包含一个预训练的 model。我如何从 ns-3 代码中执行这个文件? The python file will start execution when enough amount of data is gerenerated by the ns-3, which will be given to the pre-trained model. Later, the model predicts one value and it is used in ns-3 during simulation. python文件会在ns-3生成足够多的数据后开始执行,这些数据会被提供给预训练好的model。之后model会预测一个值,并在ns-3仿真时使用。

I tried Calling Python script from C++ and using its output .我尝试从 C++ 调用 Python 脚本并使用它的 output It is not helpful in my case.这对我来说没有帮助。 I am expecting to execute only python file from ns-3.我期望只执行来自 ns-3 的 python 文件。

In my case, I have tried the following piece of code in a function where I was required to execute the external python file from ns-3.在我的例子中,我在 function 中尝试了以下代码,我被要求从 ns-3 执行外部 python 文件。 This specific example is for the Ubuntu environment.此特定示例适用于 Ubuntu 环境。

system("/[path_to_your_python]/anaconda3/bin/python /[path_to_your_inference_file]/inference.py");

Note: The inference.py file will be executed whenever the C++ function is called, making the simulation too time-consuming compared to normal circumstances.注意:每次调用C++ function时都会执行inference.py文件,导致仿真比正常情况下耗时太长。

Suggestion: I would suggest using ONNX .建议:我建议使用ONNX

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM