简体   繁体   English

如何在 GPU 的支持下运行 python 代码

[英]How to run python code with support of GPU

I have created a flask service for accepting requests with camera URLs as parameters for finding objects(table, chair etc...) in the camera frame.我已经创建了一个 flask 服务,用于接受使用相机 URL 作为在相机框架中查找对象(桌子、椅子等)的参数的请求。 I have written code in flask for accepting POST requests.我已经在 flask 中编写了用于接受 POST 请求的代码。

@app.route('/rest/detectObjects', methods=['GET','POST'])
def detectObjects()
...
json_result = function_call_for_detecting_objects()
...
return

In the function, its loads the tf model for object detection and returns the result.在函数中,它加载用于对象检测的 tf 模型并返回结果。 A large amount of request needs to be processed simultaneously by the flask server. Flask 服务器需要同时处理大量请求。 So I need to execute the function using GPU as the camera access time and image processing for object detection takes much time and CPU utilization.所以我需要使用 GPU 执行该功能,因为相机访问时间和对象检测的图像处理需要很多时间和 CPU 使用率。 Have a 4 GB GeForce GTX 1050 Ti/PCIe/SSE2.拥有 4 GB GeForce GTX 1050 Ti/PCIe/SSE2。 How can I make my python script to make use of GPU for this?如何让我的 python 脚本为此使用 GPU?

To utilize the GPU in python you can use use one of the available libraries: https://www.researchgate.net/post/How_do_I_run_a_python_code_in_the_GPU要在 python 中使用 GPU,您可以使用可用库之一: https ://www.researchgate.net/post/How_do_I_run_a_python_code_in_the_GPU

CUDA might be the right for a NVIDIA GPU. CUDA 可能适合 NVIDIA GPU。 For a guidance using it with the Anaconda Python distribution see https://weeraman.com/put-that-gpu-to-good-use-with-python-e5a437168c01有关将其与 Anaconda Python 发行版一起使用的指南,请参阅https://weeraman.com/put-that-gpu-to-good-use-with-python-e5a437168c01

Installing tensorflow gpu will make the script to detect gpu automatically.安装 tensorflow gpu 将使脚本自动检测 gpu。 if it is not detecting the gpu, check the driver versions(Cuda and cudnn).如果它没有检测到 gpu,请检查驱动程序版本(Cuda 和 cudnn)。 If no version mismatch or errors occur, then the script can identify the gpu present and will run utilizing the gpu.如果没有版本不匹配或错误发生,则脚本可以识别存在的 gpu 并将使用 gpu 运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM