<aside> 🧸 飞桨 框架实现ocr,希望用于视频内容识别,票据识别。
</aside>
安装paddlehttps://www.paddlepaddle.org.cn/install/quick?docurl=/documentation/docs/zh/install/pip/windows-pip.html
paddle-gpu只支持特定版本CUDA,可在https://www.paddlepaddle.org.cn/packages/stable/ 下查看cu对应cuda..
cuDNN 需要复制至指定版本CUDA中https://docs.nvidia.com/deeplearning/cudnn/latest/installation/windows.html https://blog.csdn.net/anmin8888/article/details/127910084
TensorRT 添加至PATH即可运行.
如果不想破坏本机原先CUDA环境,可以使用WSL虚拟机,也可使用conda虚拟环境.
https://www.zouht.com/3754.html
https://www.163.com/dy/article/IKCQSB6P055621JP.html
python -m pip install paddlepaddle-gpu==2.6.2.post120 -i <https://www.paddlepaddle.org.cn/packages/stable/cu120/>
python -c "import paddle; print(paddle.version.cudnn())"
python -c "import paddle; paddle.utils.run_check()"
python -m pip install paddleocr
pip freeze > "requirements.txt"
PadlleOCR
https://github.com/PaddlePaddle/PaddleOCR/blob/main/docs/ppocr/quick_start.md
paddle-ocr-multit'h're'a'f
pip install fastdeploy-gpu-python -f <https://www.paddlepaddle.org.cn/whl/fastdeploy.html>
wget <https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/ch_PP-OCRv3_det_infer.tar> -OutFile ch_PP-OCRv3_det_infer.tar
wget <https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_cls_infer.tar> -OutFile ch_ppocr_mobile_v2.0_cls_infer.tar
wget <https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/ch_PP-OCRv3_rec_infer.tar> -OutFile ch_PP-OCRv3_rec_infer.tar
https://github.com/PaddlePaddle/PaddleNLP/blob/release/2.8/docs/get_started/installation.rst
https://paddlepaddle.github.io/PaddleOCR/main/ppstructure/model_train/train_kie.html#32-re
Write-Output "`nPATH 中包含的 CUDA 和 Scripts 路径:"
$env:PATH -split ';' | Where-Object { $_ -like '*CUDA*' -or $_ -like '*Scripts*' }
Param(
[Parameter(Mandatory = $false)]
[String]
$VenvDir,
[Parameter(Mandatory = $false)]
[String]
$Prompt
)
<# Function declarations --------------------------------------------------- #>
<#
.Synopsis
Remove all shell session elements added by the Activate script, including the
addition of the virtual environment's Python executable from the beginning of
the PATH variable.
.Parameter NonDestructive
If present, do not remove this function from the global namespace for the
session.
#>
function global:deactivate ([switch]$NonDestructive) {
# Revert to original values
# The prior prompt:
if (Test-Path -Path Function:_OLD_VIRTUAL_PROMPT) {
Copy-Item -Path Function:_OLD_VIRTUAL_PROMPT -Destination Function:prompt
Remove-Item -Path Function:_OLD_VIRTUAL_PROMPT
}
# The prior PYTHONHOME:
if (Test-Path -Path Env:_OLD_VIRTUAL_PYTHONHOME) {
Copy-Item -Path Env:_OLD_VIRTUAL_PYTHONHOME -Destination Env:PYTHONHOME
Remove-Item -Path Env:_OLD_VIRTUAL_PYTHONHOME
}
# The prior PATH:
if (Test-Path -Path Env:_OLD_VIRTUAL_PATH) {
Copy-Item -Path Env:_OLD_VIRTUAL_PATH -Destination Env:PATH
Remove-Item -Path Env:_OLD_VIRTUAL_PATH
}
# 之前的CUDA_PATH:
if (Test-Path -Path Env:_OLD_VIRTUAL_CUDA_PATH) {
Copy-Item -Path Env:_OLD_VIRTUAL_CUDA_PATH -Destination Env:CUDA_PATH
Remove-Item -Path Env:_OLD_VIRTUAL_CUDA_PATH
}
# Just remove the VIRTUAL_ENV altogether:
if (Test-Path -Path Env:VIRTUAL_ENV) {
Remove-Item -Path env:VIRTUAL_ENV
}
# Just remove VIRTUAL_ENV_PROMPT altogether.
if (Test-Path -Path Env:VIRTUAL_ENV_PROMPT) {
Remove-Item -Path env:VIRTUAL_ENV_PROMPT
}
# 移除 CUDA 环境变量
if (Test-Path -Path Env:CUDA_BIN) {
Remove-Item -Path Env:CUDA_BIN
}
if (Test-Path -Path Env:CUDA_LIB) {
Remove-Item -Path Env:CUDA_LIB
}
if (Test-Path -Path Env:CUDA_LIBNVVP) {
Remove-Item -Path Env:CUDA_LIBNVVP
}
if (Test-Path -Path Env:CUDA_INCLUDE) {
Remove-Item -Path Env:CUDA_INCLUDE
}
# Just remove the _PYTHON_VENV_PROMPT_PREFIX altogether:
if (Get-Variable -Name "_PYTHON_VENV_PROMPT_PREFIX" -ErrorAction SilentlyContinue) {
Remove-Variable -Name _PYTHON_VENV_PROMPT_PREFIX -Scope Global -Force
}
# Leave deactivate function in the global namespace if requested:
if (-not $NonDestructive) {
Remove-Item -Path function:deactivate
}
}
<#
.Description
Get-PyVenvConfig parses the values from the pyvenv.cfg file located in the
given folder, and returns them in a map.
For each line in the pyvenv.cfg file, if that line can be parsed into exactly
two strings separated by `=` (with any amount of whitespace surrounding the =)
then it is considered a `key = value` line. The left hand string is the key,
the right hand is the value.
If the value starts with a `'` or a `"` then the first and last character is
stripped from the value before being captured.
.Parameter ConfigDir
Path to the directory that contains the `pyvenv.cfg` file.
#>
function Get-PyVenvConfig(
[String]
$ConfigDir
) {
Write-Verbose "Given ConfigDir=$ConfigDir, obtain values in pyvenv.cfg"
# Ensure the file exists, and issue a warning if it doesn't (but still allow the function to continue).
$pyvenvConfigPath = Join-Path -Resolve -Path $ConfigDir -ChildPath 'pyvenv.cfg' -ErrorAction Continue
# An empty map will be returned if no config file is found.
$pyvenvConfig = @{ }
if ($pyvenvConfigPath) {
Write-Verbose "File exists, parse `key = value` lines"
$pyvenvConfigContent = Get-Content -Path $pyvenvConfigPath
$pyvenvConfigContent | ForEach-Object {
$keyval = $PSItem -split "\\s*=\\s*", 2
if ($keyval[0] -and $keyval[1]) {
$val = $keyval[1]
# Remove extraneous quotations around a string value.
if ("'""".Contains($val.Substring(0, 1))) {
$val = $val.Substring(1, $val.Length - 2)
}
$pyvenvConfig[$keyval[0]] = $val
Write-Verbose "Adding Key: '$($keyval[0])'='$val'"
}
}
}
return $pyvenvConfig
}
<# Begin Activate script --------------------------------------------------- #>
# Determine the containing directory of this script
$VenvExecPath = Split-Path -Parent $MyInvocation.MyCommand.Definition
$VenvExecDir = Get-Item -Path $VenvExecPath
Write-Verbose "Activation script is located in path: '$VenvExecPath'"
Write-Verbose "VenvExecDir Fullname: '$($VenvExecDir.FullName)"
Write-Verbose "VenvExecDir Name: '$($VenvExecDir.Name)"
# Set values required in priority: CmdLine, ConfigFile, Default
# First, get the location of the virtual environment, it might not be
# VenvExecDir if specified on the command line.
if ($VenvDir) {
Write-Verbose "VenvDir given as parameter, using '$VenvDir' to determine values"
}
else {
Write-Verbose "VenvDir not given as a parameter, using parent directory name as VenvDir."
$VenvDir = $VenvExecDir.Parent.FullName.TrimEnd("\\\\/")
Write-Verbose "VenvDir=$VenvDir"
}
# Next, read the `pyvenv.cfg` file to determine any required value such
# as `prompt`.
$pyvenvCfg = Get-PyVenvConfig -ConfigDir $VenvDir
# Next, set the prompt from the command line, or the config file, or
# just use the name of the virtual environment folder.
if ($Prompt) {
Write-Verbose "Prompt specified as argument, using '$Prompt'"
}
else {
Write-Verbose "Prompt not specified as argument to script, checking pyvenv.cfg value"
if ($pyvenvCfg -and $pyvenvCfg['prompt']) {
Write-Verbose " Setting based on value in pyvenv.cfg='$($pyvenvCfg['prompt'])'"
$Prompt = $pyvenvCfg['prompt'];
}
else {
Write-Verbose " Setting prompt based on parent's directory's name. (Is the directory name passed to venv module when creating the virtual environment)"
Write-Verbose " Got leaf-name of $VenvDir='$(Split-Path -Path $venvDir -Leaf)'"
$Prompt = Split-Path -Path $venvDir -Leaf
}
}
Write-Verbose "Prompt = '$Prompt'"
Write-Verbose "VenvDir='$VenvDir'"
# Deactivate any currently active virtual environment, but leave the
# deactivate function in place.
deactivate -nondestructive
# Now set the environment variable VIRTUAL_ENV, used by many tools to determine
# that there is an activated venv.
$env:VIRTUAL_ENV = $VenvDir
if (-not $Env:VIRTUAL_ENV_DISABLE_PROMPT) {
Write-Verbose "Setting prompt to '$Prompt'"
# Set the prompt to include the env name
# Make sure _OLD_VIRTUAL_PROMPT is global
function global:_OLD_VIRTUAL_PROMPT { "" }
Copy-Item -Path function:prompt -Destination function:_OLD_VIRTUAL_PROMPT
New-Variable -Name _PYTHON_VENV_PROMPT_PREFIX -Description "Python virtual environment prompt prefix" -Scope Global -Option ReadOnly -Visibility Public -Value $Prompt
function global:prompt {
Write-Host -NoNewline -ForegroundColor Green "($_PYTHON_VENV_PROMPT_PREFIX) "
_OLD_VIRTUAL_PROMPT
}
$env:VIRTUAL_ENV_PROMPT = $Prompt
}
## 清理原有环境变量
# Clear PYTHONHOME
if (Test-Path -Path Env:PYTHONHOME) {
Copy-Item -Path Env:PYTHONHOME -Destination Env:_OLD_VIRTUAL_PYTHONHOME
Remove-Item -Path Env:PYTHONHOME
}
## Clear CUDA_PATH
if (Test-Path -Path Env:CUDA_PATH) {
Copy-Item -Path Env:CUDA_PATH -Destination Env:_OLD_VIRTUAL_CUDA_PATH
$Env:CUDA_PATH = "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v12.0"
}
# Add the venv to the PATH
## 保留
Copy-Item -Path Env:PATH -Destination Env:_OLD_VIRTUAL_PATH
## 设置 CUDA 环境变量
$CUDA_BIN = "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v12.0\\bin"
$CUDA_LIB = "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v12.0\\lib"
$CUDA_LIBNVVP = "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v12.0\\libnvvp"
$CUDA_INCLUDE = "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v12.0\\include"
$cudaPaths = @(
$CUDA_BIN
$CUDA_LIB
$CUDA_LIBNVVP
$CUDA_INCLUDE
Join-Path $VenvExecDir $([System.IO.Path]::PathSeparator)
)
$Env:PATH = ($cudaPaths -join ";") + ";" + $Env:PATH
有一说一,真有人用paddlepaddle (飞桨) 吗? - 椿楸的回答 - 知乎 https://www.zhihu.com/question/360157891/answer/1918473402