我有一个用于运行 tensorflow 模型的 python 脚本,我需要使用 PHP shell_exec
函数从 PHP 文件运行此脚本(出于复杂的原因)。当我使用以下代码运行 python 文件时:
$command = 'cd testModels/crosswalkPredict && . activate keras && python test_script.py';
$output = shell_exec($command);
我收到以下错误:Illegal instruction (core dumped)
我了解到,当 CPU 不支持较新版本的 Tensorflow 中存在的指令时,通常会出现此问题。所以我降级到 Tensorflow 1.5。
但是,当我运行 cd testModels/crosswalkPredict && 时,不会发生此错误。直接从终端激活 keras && python test_script.py
;它仅在我从 PHP shell_exec
函数中运行时发生。
我已经尝试了仅包含以下几行的 python 脚本:
import tensorflow
print('Hello!')
它仍然给出相同的错误,所以我知道当我所做的只是导入 tensorflow 并使用 shell_exec
运行脚本时会出现问题。
可能是什么问题?
最佳答案
这是一个已知的 TensorFlow 兼容性问题,与旧 CPU 上的 AVX 支持有关,如果您从源代码编译 TensorFlow,则可以解决此问题:
https://github.com/tensorflow/tensorflow/issues/17411#issuecomment-386888244
https://github.com/tensorflow/tensorflow/issues/17411#issuecomment-420157421
关于php - Tensorflow 1.5 的非法指令(核心转储),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55226284/