dongqing6661
2019-03-18 16:49 阅读 714

使用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 test_script.py';
$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 test_script.py 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
print('Hello!')

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?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • 已采纳
    dssqq82402 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:

    /home/user01/anaconda3/envs/keras/bin/python test_script.py
    

    Instead of:

    . activate keras && python test_script.py
    
    点赞 评论 复制链接分享
  • dongmu5815 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:

    https://github.com/tensorflow/tensorflow/issues/17411#issuecomment-386888244

    https://github.com/tensorflow/tensorflow/issues/17411#issuecomment-420157421

    点赞 评论 复制链接分享

相关推荐