国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Docker【部署 05】docker使用tensorflow-gpu安裝及調(diào)用GPU踩坑記錄

這篇具有很好參考價值的文章主要介紹了Docker【部署 05】docker使用tensorflow-gpu安裝及調(diào)用GPU踩坑記錄。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

1.安裝tensorflow-gpu

Building wheels for collected packages: tensorflow-gpu
  Building wheel for tensorflow-gpu (setup.py): started
  Building wheel for tensorflow-gpu (setup.py): finished with status 'error'
  Running setup.py clean for tensorflow-gpu
  error: subprocess-exited-with-error

  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [18 lines of output]
      Traceback (most recent call last):
        File "<string>", line 2, in <module>
        File "<pip-setuptools-caller>", line 34, in <module>
        File "/tmp/pip-install-i6frcfa8/tensorflow-gpu_2cea358528754cc596c541f9c2ce45ca/setup.py", line 37, in <module>
          raise Exception(TF_REMOVAL_WARNING)
      Exception:

      =========================================================
      The "tensorflow-gpu" package has been removed!

      Please install "tensorflow" instead.

      Other than the name, the two packages have been identical
      since TensorFlow 2.1, or roughly since Sep 2019. For more
      information, see: pypi.org/project/tensorflow-gpu
      =========================================================


      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for tensorflow-gpu
Failed to build tensorflow-gpu

Other than the name, the two packages have been identical since TensorFlow 2.1 也就是說安裝2.1版本的已經(jīng)自帶GPU支持。

2.Docker使用GPU

不同型號的GPU及驅(qū)動版本有所區(qū)別,環(huán)境驅(qū)動及CUDA版本如下:

[root@localhost ~]# nvidia-smi
# 查詢結(jié)果
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 460.27.04    Driver Version: 460.27.04    CUDA Version: 11.2     |
|-------------------------------+----------------------+----------------------+

2.1 Could not find cuda drivers

# 報錯
I tensorflow/tsl/cuda/cudart_stub.cc:28] Could not find cuda drivers on your machine, GPU will not be used.

在Docker容器中的程序無法識別CUDA環(huán)境變量,可以嘗試以下步驟來解決這個問題:

  1. 檢查CUDA版本:首先,需要確認宿主機上已經(jīng)正確安裝了CUDA。在宿主機上運行nvcc --version命令來檢查CUDA版本。
  2. 使用NVIDIA Docker鏡像:NVIDIA提供了一些預(yù)先配置好的Docker鏡像,這些鏡像已經(jīng)包含了CUDA和其他必要的庫。可以使用這些鏡像作為Dockerfile的基礎(chǔ)鏡像。
  3. 設(shè)置環(huán)境變量:在Dockerfile中,可以使用ENV指令來設(shè)置環(huán)境變量。例如,如果CUDA安裝在/usr/local/cuda目錄下,可以添加以下行到Dockerfile中:ENV PATH /usr/local/cuda/bin:$PATH
  4. 使用nvidia-docker:nvidia-docker是一個用于運行GPU加速的Docker容器的工具。

檢測CUDA版本是必要的,由于使用的是導出的鏡像文件,2和3的方法無法使用,最終使用-e進行環(huán)境變量設(shè)置:

# 添加cuda的環(huán)境變量
-e PATH=/usr/local/cuda-11.2/bin:$PATH -e LD_LIBRARY_PATH=/usr/local/cuda-11.2/lib64:$LD_LIBRARY_PATH

# 啟動命令
nvidia-docker run --name deepface --privileged=true --restart=always --net="host" -e PATH=/usr/local/cuda-11.2/bin:$PATH -e LD_LIBRARY_PATH=/usr/local/cuda-11.2/lib64:$LD_LIBRARY_PATH -v /root/.deepface/weights/:/root/.deepface/weights/ -v /usr/local/cuda-11.2/:/usr/local/cuda-11.2/ -d deepface_image

2.2 was unable to find libcuda.so DSO

I tensorflow/compiler/xla/stream_executor/cuda/cuda_diagnostics.cc:168] retrieving CUDA diagnostic information for host: localhost.localdomain
I tensorflow/compiler/xla/stream_executor/cuda/cuda_diagnostics.cc:175] hostname: localhost.localdomain
I tensorflow/compiler/xla/stream_executor/cuda/cuda_diagnostics.cc:199] libcuda reported version is: NOT_FOUND: was unable to find libcuda.so DSO loaded into this program
I tensorflow/compiler/xla/stream_executor/cuda/cuda_diagnostics.cc:203] kernel reported version is: 460.27.4

在Linux環(huán)境下,Docker可以支持將宿主機上的目錄掛載到容器里。這意味著,如果宿主機上的目錄包含軟鏈接,那么這些軟鏈接也會被掛載到容器中。然而,需要注意的是,這些軟鏈接指向的路徑必須在Docker容器中是可訪問的。也就是說,如果軟鏈接指向的路徑?jīng)]有被掛載到Docker容器中,那么在容器中訪問這個軟鏈接可能會失敗。
原文鏈接:https://blog.csdn.net/u013546508/article/details/88637434,當前環(huán)境下問題解決步驟:

# 1.查找 libcuda.so 文件位置
find / -name libcuda.so*
# 查找結(jié)果
/usr/lib/libcuda.so
/usr/lib/libcuda.so.1
/usr/lib/libcuda.so.460.27.04
/usr/lib64/libcuda.so
/usr/lib64/libcuda.so.1
/usr/lib64/libcuda.so.460.27.04

# 2.查看LD_LIBRARY_PATH
echo $LD_LIBRARY_PATH
# 查詢結(jié)果
/usr/local/cuda/lib64

# 3.將64位的libcuda.so.460.27.04復制到LD_LIBRARY_PATH路徑下【libcuda.so和libcuda.so.1都是軟連接】
cp /usr/lib64/libcuda.so.460.27.04 /usr/local/cuda-11.2/lib64/

# 4.創(chuàng)建軟連接
ln -s libcuda.so.460.27.04 libcuda.so.1
ln -s libcuda.so.1 libcuda.so

2.3 Could not find TensorRT&&Cannot dlopen some GPU libraries

I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: AVX2 AVX512F FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.

W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT
W tensorflow/core/common_runtime/gpu/gpu_device.cc:1960] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.
Skipping registering GPU devices...

這個問題實際上是Docker鏡像文件未安裝TensorRT導致的,可以在Dockerfile里添加安裝命令后重新構(gòu)建鏡像:

RUN pip install tensorrt -i https://pypi.tuna.tsinghua.edu.cn/simple

以下操作不推薦,進入容器進行安裝:

# 1.查詢?nèi)萜鱅D
docker ps

# 2.在running狀態(tài)進入容器
docker exec -it ContainerID /bin/bash

# 3.安裝軟件
pip install tensorrt -i https://pypi.tuna.tsinghua.edu.cn/simple

# 4.提交新的鏡像【可以將新的鏡像導出使用】
docker commit ContainerID imageName:version

安裝后的現(xiàn)象:

root@localhost:/app# python
Python 3.8.18 (default, Sep 20 2023, 11:41:31)
[GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

# 使用tensorflow報錯
>>> import tensorflow as tf
2023-10-09 10:15:55.482545: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: AVX2 AVX512F FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
2023-10-09 10:15:56.498608: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT

# 先導入tensorrt后使用tensorflow看我用
>>> import tensorrt as tr
>>> import tensorflow as tf
>>> tf.test.is_gpu_available()
WARNING:tensorflow:From <stdin>:1: is_gpu_available (from tensorflow.python.framework.test_util) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.config.list_physical_devices('GPU')` instead.
2023-10-09 10:16:41.452672: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1639] Created device /device:GPU:0 with 11389 MB memory:  -> device: 0, name: Tesla T4, pci bus id: 0000:2f:00.0, compute capability: 7.5
True

嘗試解決,在容器啟動要執(zhí)行的py文件內(nèi)加入以下代碼,我將以下代碼加入到app.py文件內(nèi):

import tensorrt as tr
import tensorflow as tf

if __name__ == "__main__":
    available = tf.config.list_physical_devices('GPU')
    print(f"available:{available}")

加入代碼后的文件為:

# 3rd parth dependencies
import tensorrt as tr
import tensorflow as tf
from flask import Flask
from routes import blueprint

def create_app():
    available = tf.config.list_physical_devices('GPU')
    print(f"available:{available}")
    app = Flask(__name__)
    app.register_blueprint(blueprint)
    return app

啟動容器:

nvidia-docker run --name deepface --privileged=true --restart=always --net="host" -e PATH=/usr/local/cuda-11.2/bin:$PATH -e LD_LIBRARY_PATH=/usr/local/cuda-11.2/lib64:$LD_LIBRARY_PATH -v /root/.deepface/weights/:/root/.deepface/weights/ -v /usr/local/cuda-11.2/:/usr/local/cuda-11.2/ -v /opt/xinan-facesearch-service-public/deepface/api/app.py:/app/app.py -d deepface_image

2.4 Could not create cudnn handle: CUDNN_STATUS_NOT_INITIALIZED

E tensorflow/compiler/xla/stream_executor/cuda/cuda_dnn.cc:437] Could not create cudnn handle: CUDNN_STATUS_NOT_INITIALIZED
E tensorflow/compiler/xla/stream_executor/cuda/cuda_dnn.cc:441] Memory usage: 1100742656 bytes free, 15843721216 bytes total.
E tensorflow/compiler/xla/stream_executor/cuda/cuda_dnn.cc:451] Possibly insufficient driver version: 460.27.4
W tensorflow/core/framework/op_kernel.cc:1828] OP_REQUIRES failed at conv_ops_impl.h:770 : UNIMPLEMENTED: DNN library is not found.

未安裝cuDNN導致的問題,安裝即可。

2.5 CuDNN library needs to have matching major version and equal or higher minor version

安裝版本跟編譯項目的版本不匹配,調(diào)整版本后成功使用GPU。文章來源地址http://www.zghlxwxcb.cn/news/detail-713328.html

E tensorflow/compiler/xla/stream_executor/cuda/cuda_dnn.cc:425] Loaded runtime CuDNN library: 8.1.1 but source was compiled with: 8.6.0.  CuDNN library needs to have matching major version and equal or higher minor version. If using a binary install, upgrade your CuDNN library.  If building from sources, make sure the library loaded at runtime is compatible with the version specified during compile configuration.

到了這里,關(guān)于Docker【部署 05】docker使用tensorflow-gpu安裝及調(diào)用GPU踩坑記錄的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔相關(guān)法律責任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • 安裝tensorflow-gpu

    安裝tensorflow-gpu

    打開anaconda prompt,添加鏡像源: 刪除鏡像源使用: 創(chuàng)建虛擬環(huán)境并安裝tensorflow-gpu: 查看一下包的版本: python是3.6.2版本的 在下面的網(wǎng)站中查找對應(yīng)版本: 在 Windows 環(huán)境中從源代碼構(gòu)建 ?|? TensorFlow (google.cn) 對應(yīng)的最低tensorflow-gpu是1.2.0版本的 選擇一個合適的2.0.0版本的 但

    2024年02月07日
    瀏覽(25)
  • tensorflow-GPU環(huán)境搭建

    最近在學習AI相關(guān)知識,需要使用 gpu 運行 tensorflow 代碼,選擇在騰訊云上搭建環(huán)境 安裝 tensorflow 與 GPU 支持需要對齊以下軟件的版本號(按依賴順序排列): GPU 驅(qū)動版本號 CUDA 版本號 cudnn 版本號 tensorflow 版本號 由于 tensorflow 位于最下游,因此更新時機最晚,因此實際安裝

    2024年01月17日
    瀏覽(24)
  • tensorflow-gpu卸載 (windows)

    tensorflow-gpu卸載 (windows)

    在安裝 Tensorflow-gpu 時,如果, Tensorflow-gpu 、 Python 、 cuda 、 cuDNN 版本關(guān)系不匹配很容易安裝出錯,要重新安裝的話,要把之前裝的卸載干凈! tensorflow-cpu卸載, 激活進入虛擬環(huán)境,在這里卸載: 進入虛擬環(huán)境安裝路徑: Proceed(y/n)? y 刪除之前創(chuàng)建的虛擬環(huán)境(例子為刪除名

    2024年02月05日
    瀏覽(20)
  • Windows安裝tensorflow-gpu(1050Ti,cuda11.6,cuDNN7.6.5,python3.6,tensorflow-gpu2.3.0)

    Windows安裝tensorflow-gpu(1050Ti,cuda11.6,cuDNN7.6.5,python3.6,tensorflow-gpu2.3.0)

    參考:https://blog.csdn.net/qq_43215538/article/details/123852028 首先查看本機GPU對應(yīng)的cuda版本,如下圖所示,本機cuda版本為11.6,后面選擇的cuda版本不要超過這里的版本就好。 https://developer.nvidia.com/cuda-toolkit-archive選擇相應(yīng)的cudatoolkit版本下載,如這里選擇版本一定要注意,因為cuda版本

    2023年04月08日
    瀏覽(26)
  • MacOS M2:配置Tensorflow-GPU版

    MacOS M2:配置Tensorflow-GPU版

    本文主要介紹MacOS 12.x系統(tǒng)下的Tensorflow配置??偟膩碚f,配置Mac版本的Tensorflow只需要三步:第一步配置一個虛擬環(huán)境,建議選擇miniconda;第二步創(chuàng)建conda環(huán)境;第三步安裝Tensorflow。 1、安裝 Miniconda 1.1 徹底刪除anaconda (1)下載??anaconda-clean???用于刪除相關(guān)配置文件 2)刪除

    2024年04月13日
    瀏覽(20)
  • win10 安裝 tensorflow-gpu 2.10.0

    系統(tǒng)配置 系統(tǒng) win10 x64 顯卡 GTX 1660 Ti CUDA 12.2 cudnn 8.9 查看版本對應(yīng): https://tensorflow.google.cn/install/source_windows#gpu Version Python version Compiler Build tools cuDNN CUDA tensorflow_gpu-2.10.0 3.7-3.10 MSVC 2019 Bazel 5.1.1 8.1 11.2 這里查看我 系統(tǒng)配置 我安裝 python 3.10 和 tensorflow_gpu-2.10.0 安裝 conda 安裝

    2024年02月14日
    瀏覽(28)
  • tensorflow,tensorflow-gpu, CUDA, cuDNN,Python, numpy對應(yīng)版本

    本機GPU是NVIDIA GeForce GTX 1650, 支持的最高版本CUDA是12.0。想要在Windows下使用GPU跑深度學習模型,需要使用tensorflow-gpu,其目前最高版本是2.6.0。所以其他依賴環(huán)境均按照tensorflow-gpu的需求來配置。 Tensorflow-gpu 2.6.0 (目前為止最高版本) Python 3.9.18 (能夠支持tensorflow-GPU的最高Python版

    2024年04月17日
    瀏覽(26)
  • 解決CUDA 11.6版本對應(yīng)的tensorflow-gpu版本問題

    解決CUDA 11.6版本對應(yīng)的tensorflow-gpu版本問題

    個人電腦相關(guān)配置版本信息 (超級超級新的版本,以至于適配方面花了很長時間來搞) cuda? 11.6 cudnn ?8.9.0 python ?3.10 對應(yīng)安裝的gpu版本 tensorflow-gpu ?2.10.0 對應(yīng)代碼 具體怎么安裝的我已經(jīng)放在文章底部啦,改鏡像源什么的也不多說~ 感謝參考嘿(-v- ---------------------------------

    2024年02月08日
    瀏覽(25)
  • [conda]tf_agents和tensorflow-gpu安裝傻瓜式教程

    [conda]tf_agents和tensorflow-gpu安裝傻瓜式教程

    1.打開終端或Anaconda Prompt(Windows用戶)。 2.輸入以下命令創(chuàng)建新的Python環(huán)境: ? ?其中, env_name 是您想要創(chuàng)建的環(huán)境名稱, version 是您想要安裝的Python版本號。例如,要創(chuàng)建名為 python37 的Python 3.7環(huán)境,請輸入以下命令: 3.進入到要使用的環(huán)境去使用pip安裝應(yīng)用 進入后顯示如

    2024年02月11日
    瀏覽(75)
  • tensorflow-gpu 2.3.0安裝 及 相關(guān)對應(yīng)版本庫安裝(Anaconda安裝)

    tensorflow-gpu 2.3.0安裝 及 相關(guān)對應(yīng)版本庫安裝(Anaconda安裝)

    目錄 如需轉(zhuǎn)載,請標明出處,謝謝。 一、安裝tensorflow-gpu2.3.0 二、配置其他相關(guān)的庫 很多人以為安裝完tensorflow-gpu就是一切都結(jié)束了,但是殊不知,python中的很多庫,比如numpy,matplotlib等庫,就與我們的tensorflow的版本有對應(yīng) 總結(jié) 對于anaconda的下載,網(wǎng)上的教程很多,而且很

    2024年02月02日
    瀏覽(30)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包