问题1:Error loading "D:\env\paddleocr_env\.venv\lib\site-packages\torch\lib\fbgemm.dll" or one of its dependencies.
OSError: [WinError 127] 找不到指定的程序。 Error loading "D:\env\text_recognition\text_recognition\.venv\lib\site-packages\torch\lib\shm.dll" or one of its dependencies.

在训练paddleocr 时报这个错是缺少c++环境依赖,

解决  下载 Visual Studio 社区版并安装上述 C++ 包
VMSVC v142 - VS 2019 C++ x64/x86 build t..
VMSVC v141 - VS 2017 C++ x64/x86 build t..
VMSVC v140 - VS 2015 C+ + build tools (v1..

Visual Studio 社区版
https://visualstudio.microsoft.com/zh-hans/vs/community/

或者只勾选几个必要的组件就行,安装路径放到D盘

pytorch 此报错讨论区

https://discuss.pytorch.org/t/failed-to-import-pytorch-fbgemm-dll-or-one-of-its-dependencies-is-missing/201969/63
安装torch版本

torch<=2.4.0 以下版本可用
pip install torch==2.2.2 torchvision==0.15.2 torchaudio==2.2.2 --index-url https://download.pytorch.org/whl/cu118
pip install torch==2.3.0 torchvision==0.16.0 torchaudio==2.3.0 --index-url https://download.pytorch.org/whl/cu118
pip install torch==2.4.0 torchvision==0.19.0 torchaudio==2.4.0 --index-url https://download.pytorch.org/whl/cu118

pip install torch==2.5.1 torchvision==0.20.1 torchaudio==2.5.1 --index-url https://download.pytorch.org/whl/cu118
pip install torch==2.6.0 torchvision==0.21.0 torchaudio==2.6.0 --index-url https://download.pytorch.org/whl/cu118

问题2:

D:\env\paddleocr_env\.venv\lib\site-packages\paddle\utils\cpp_extension\extension_utils.py:715: 
UserWarning: No ccache found. Please be aware that recompiling all source files may be required. 
You can download and install ccache from: https://github.com/ccache/ccache/blob/master/doc/INSTALL.md


ccache 是一个编译器缓存工具,它可以:
缓存之前的编译结果
避免重复编译相同的源代码
显著加快编译速度
Windows 系统:
# 使用 Chocolatey 安装
choco install ccache
# 或使用 Scoop 安装
scoop install ccache
# 或从官网下载解压后添加到环境变量中
# 访问:https://github.com/ccache/ccache/releases
Linux 系统:
# Ubuntu/Debian
sudo apt-get install ccache
# CentOS/RHEL
sudo yum install ccache
# 或使用 dnf
sudo dnf install ccache

# 检查 ccache 是否安装
ccache --version
# 查看 ccache 统计信息
ccache -s
# 清理 ccache 缓存
ccache -C

问题3:RuntimeError: generic_type: type "_CudaDeviceProperties" is already registered!

是由于paddlepaddle-gpu低于3.1.0 只支持到cuda11.7
安装指南 https://www.paddlepaddle.org.cn/documentation/docs/en/install/pip/windows-pip_en.html
pip install paddlepaddle-gpu==3.1.0 -i https://www.paddlepaddle.org.cn/packages/stable/cu118/
pip install opencv-python==4.10.0.84 -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install opencv-python-headless==4.10.0.84 -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install numpy==1.26.4 -i https://www.paddlepaddle.org.cn/packages/stable/cu118/

4. #测试torch是否可用

def check_cuda():
    print(f"PyTorch版本: {torch.__version__}")
    print(f"CUDA可用: {torch.cuda.is_available()}")

    if torch.cuda.is_available():
        device = torch.device("cuda")
        print(f"设备名称: {torch.cuda.get_device_name(0)}")

        # 测试张量计算
        x = torch.rand(5, 3).to(device)
        y = torch.rand(5, 3).to(device)
        z = x + y
        print("CUDA计算测试通过!")

        # 测试设备属性访问
        props = torch.cuda.get_device_properties(0)
        print(f"设备内存: {props.total_memory/1024**3:.2f} GB")
        return True
    return False

if __name__ == "__main__":
    if check_cuda():
        print("CUDA环境正常!")
    else:
        print("CUDA不可用,请检查安装")

更多推荐