dongqing6661 2019-03-18 16:49
浏览 1018
已采纳

使用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 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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料