2019-03-18 16:49
浏览 876

使用Tensorflow 1.5进行非法指令(核心转储)

I have a python script for running a tensorflow model, and I need to run this script from a PHP file (for complicated reasons) using the PHP shell_exec function. When I run the python file with the following code:

$command = 'cd testModels/crosswalkPredict && . activate keras && python';
$output = shell_exec($command);

I get the following error: Illegal instruction (core dumped)

I read that the issue typcally occurs when the CPU doesn't support instructions that are present in newer versions of Tensorflow. So I downgraded to Tensorflow 1.5.

However, this error does not occur when I run cd testModels/crosswalkPredict && . activate keras && python directly from the terminal; it only occurs when I run it from within the PHP shell_exec function.

I have gone as far as to try the python script with only the following lines:

import tensorflow

It still gives the same error, so I know the issue occurs when all I'm doing is importing tensorflow and running the script with shell_exec.

What could be the problem?

图片转代码服务由CSDN问答提供 功能建议

我有一个用于运行张量流模型的python脚本,我需要从PHP文件运行此脚本(对于 复杂的原因)使用PHP shell_exec 函数。 当我使用以下代码运行python文件时:

  $ command ='cd testModels / crosswalkPredict&&  。 激活keras&&  python'; 
 $ output = shell_exec($ command); 

我收到以下错误:非法指令(核心转储)< / code>

我读到,当CPU不支持更新版本的Tensorflow中存在的指令时,通常会出现此问题。 所以我降级为Tensorflow 1.5。

然而,当我运行 cd testModels / crosswalkPredict&amp;&amp; 。 激活keras&amp;&amp; python 直接来自终端; 它只发生在我从PHP shell_exec 函数中运行它时。


  import tensorflow 
print('你好!  ')

它仍然会出现同样的错误,所以我知道当我所做的只是导入tensorflow并使用 shell_exec运行脚本时会出现问题


  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dssqq82402 2019-04-01 00:07

    I figured out the problem. as I mentioned in a couple of the comments, I am using a python virtual environment. When I was executing the python script from the command line, the python interpreter from within the python virtual environment was being used, and everything was fine. Whenever I executed the script rom shell_exec, the default installation of the python interpreter was being used, and this was where the error occurred.

    I am not very experienced in using python virtual environments, so that is likely why it took so long for me to arrive at an understanding of the problem. Luckily, MohammedAyoubBENJELLOUN's comment about shell_exec using the default python installation put me on the right path, and I figured it out from there.

    To solve this problem, I simply invoked the python interpreter at the path of the interpreter inside of the python virtual environment instead of trying to activate the virtual environment and then executing.

    For example, I used:


    Instead of:

    . activate keras && python
    点赞 打赏 评论
  • dongmu5815 2019-03-18 22:13

    Its a known TensorFlow compatibility issue with AVX support on older CPU, it could be fixed if you compile TensorFlow from the sources:

    点赞 打赏 评论

相关推荐 更多相似问题