douzhang1926 2018-06-08 10:44
浏览 221
已采纳

从php执行的python脚本将无法读取已保存的模型

Here is what I'm trying to do: I'm sending an Ajax request with an image as data to a php script that uploads it and execute a python script with the image name the python script loads a gender detection model and predict the gender on the person on the image.

The problem is the model doesn't load, I tried it with the php and python script in the same directory and it worked fine but I'm trying to use it in laravel so I can't do that anymore.

when I try running the python script manually like that :

python path/to/script.py 

It throws this error : OpenCV(3.4.1) Error: Unspecified error (File can't be opened for reading!)

but when I do this it works:-

cd path/to/script.py ; python script.py

Here is my php:-

    $file = $this->upload_Image($request->get('image'));
    $path =public_path().'/app/Http/Controllers';
    $command='cd '.$path.';';
    $path= 'python '.$path.'/facifier.py '.storage_path('app').$file;

    $command .= $path;
    return exec($command);

    Storage::disk('local')->delete($file);
    return json_encode($orderedData);

The command ends up like this : cd absolute/path/to/script.py ; python script.py absolute/path/to/image.jpg when I use it on a command prompt it works fine. Here is where I get the error on my python script:-

fisher_face_gender = cv2.face.FisherFaceRecognizer_create()
fisher_face_gender.read('models/gender_classifier_model_kdef.xml')

does anyone know whats causing this, I'm on windows by the way.

  • 写回答

1条回答 默认 最新

  • doubo1711 2018-06-09 14:11
    关注

    thanks to bruno desthuilliers comment i got it working. The problem was in the path to model i used,its relative to the python script because i thought that the script executes on its own path not on the command promt's path .

    I just changed the path to the model to the absolute path and it worked fine

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?