Bump
How to run a python script and get the result?
Hello,
I have a system in which some C code posts a picture to my server running laravel, the image is then passed to a python script to get some detection of objects within the image, the python script runs tensor flow to detect the object. Once the object is detected the output is returned in the terminal. I want to then take the result and insert it into the database.
My issue is that once the script posts the image, I can retrieve it and save it, but I can't run the python script for some reason. I have tried exec() but i haven't been able to get it working fully yet.
Here is a copy of my code so far:
public function upload(Request $request)
{
$uuid4 = Uuid::uuid4();
$file = $request->file('photo');
$filename = $uuid4->toString() . '.' . $file->getClientOriginalExtension();
$path = public_path('number_plate/' . $filename);
$img = Image::make($file->getRealPath())->save($path);
exec("/usr/bin/python3 /var/www/Honours/public/Network/detect_plate.py $path /var/www/Honours/public/Network/weights.npz",
$output,
$return_var);
dd($output);
return response()->json([
'status' => '200',
'state' => 'Successfully Created the Resource.'
]);
}
Here is sample output if I run the command manually
chad@chad-GA-990XA-UD3:/var/www/Honours/public/number_plate$ /usr/bin/python3 /home/chad/Desktop/Network/detect_plate.py /var/www/Honours/public/number_plate/2ebc2b51-2f1a-46f9-a754-5851b6cfa91c.jpg /home/chad/Desktop/Network/weights.npz
I tensorflow/stream_executor/dso_loader.cc:125] successfully opened CUDA library libcublas.so.8.0 locally
I tensorflow/stream_executor/dso_loader.cc:125] successfully opened CUDA library libcudnn.so.5 locally
I tensorflow/stream_executor/dso_loader.cc:125] successfully opened CUDA library libcufft.so.8.0 locally
I tensorflow/stream_executor/dso_loader.cc:125] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:125] successfully opened CUDA library libcurand.so.8.0 locally
I tensorflow/core/common_runtime/gpu/gpu_device.cc:885] Found device 0 with properties:
name: GeForce GTX 1070
major: 6 minor: 1 memoryClockRate (GHz) 1.683
pciBusID 0000:01:00.0
Total memory: 7.92GiB
Free memory: 7.69GiB
I tensorflow/core/common_runtime/gpu/gpu_device.cc:906] DMA: 0
I tensorflow/core/common_runtime/gpu/gpu_device.cc:916] 0: Y
I tensorflow/core/common_runtime/gpu/gpu_device.cc:975] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 1070, pci bus id: 0000:01:00.0)
CE62BXY
The result of the script i get however is "".
also the script takes a few seconds to run (10seconds - 20 seconds).
Please or to participate in this conversation.