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

使用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 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)