ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
## 错误 报错错误信息`OSError: [WinError 126] 找不到指定的模块。 Error loading` ```ts (tinywan-modelscope) D:\AI\python>python resty_easyocr.py Traceback (most recent call last): File "D:\AI\python\resty_easyocr.py", line 1, in <module> import easyocr File "D:\anaconda3\envs\tinywan-modelscope\lib\site-packages\easyocr\__init__.py", line 1, in <module> from .easyocr import Reader File "D:\anaconda3\envs\tinywan-modelscope\lib\site-packages\easyocr\easyocr.py", line 3, in <module> from .recognition import get_recognizer, get_text File "D:\anaconda3\envs\tinywan-modelscope\lib\site-packages\easyocr\recognition.py", line 2, in <module> import torch File "D:\anaconda3\envs\tinywan-modelscope\lib\site-packages\torch\__init__.py", line 148, in <module> raise err OSError: [WinError 126] 找不到指定的模块。 Error loading "D:\anaconda3\envs\tinywan-modelscope\lib\site-packages\torch\lib\fbgemm.dll" or one of its dependencies. ``` 这个错误信息表明在尝试加载 `fbgemm.dll`(Facebook的GEMM(通用矩阵乘法)库的一个优化版本,专为CPU上的深度学习操作而设计)或其依赖项时出现了问题。这个库是PyTorch(一个广泛使用的深度学习库)的一部分,特别是在使用Intel CPU并启用特定优化时。 使用conda安装或更新PyTorch的示例命令 ```ts conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch ``` ## 识别 脚本`resty_easyocr.py` ```python import easyocr import sys def extract_text_from_image(image_path): """ 从给定的图片路径中提取文本。 参数: image_path (str): 图片文件的路径。 返回: str: 提取的文本,每行文本之间用换行符分隔。 """ # 初始化EasyOCR,指定需要识别的语言,这里是中国简体(ch_sim)和英文(en) reader = easyocr.Reader(['ch_sim', 'en']) # 使用readtext方法从图片中读取文本 results = reader.readtext(image_path) # 初始化一个空字符串用于存储提取的文本 text = "" # 遍历识别结果 for result in results: # 每个result是一个元组,其中result[0]是边界框信息,result[1]是识别到的文本 # 这里我们只需要文本部分,并将其添加到text字符串中,每个文本后添加一个换行符 text += result[1] + "\n" # 返回最终提取的文本 return text if __name__ == "__main__": # 检查是否提供了命令行参数(图片路径) if len(sys.argv) != 2: print("Usage: python script.py <image_path>") sys.exit(1) # 非零退出码表示错误 # 从命令行参数中获取图片路径 image_path = sys.argv[1] # 调用函数提取文本 text = extract_text_from_image(image_path) # 打印提取的文本 print(text) ``` ![](https://img.kancloud.cn/09/ba/09ba9f712c1043a7a2b5ea97fc570213_1128x111.png) 需要识别的图片 ![](https://img.kancloud.cn/22/f0/22f027bb158e9ea32df41aa551f3f43d_900x383.png) 执行命令识别结果 ``` (tinywan-modelscope) D:\AI\python>python resty_easyocr.py .\demo.png Neither CUDA nor MPS are available - defaulting to CPU. Note: This module is much faster with a GPU. D:\anaconda3\envs\tinywan-modelscope\lib\site-packages\easyocr\detection.py:78: FutureWarning: You are using `torch.load` with `weights_only=False` (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models for more details). In a future release, the default value for `weights_only` will be flipped to `True`. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via `torch.serialization.add_safe_globals`. We recommend you start setting `weights_only=True` for any use case where you don't have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature. net.load_state_dict(copyStateDict(torch.load(trained_model, map_location=device))) D:\anaconda3\envs\tinywan-modelscope\lib\site-packages\easyocr\recognition.py:169: FutureWarning: You are using `torch.load` with `weights_only=False` (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models for more details). In a future release, the default value for `weights_only` will be flipped to `True`. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via `torch.serialization.add_safe_globals`. We recommend you start setting `weights_only=True` for any use case where you don't have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature. state_dict = torch.load(model_path, map_location=device) Casbin实战教程 ABAC模型策略设计研发 ``` ![](https://img.kancloud.cn/2a/9f/2a9f0df867f7657c28e4e4db94f6130e_1116x496.png) ## phpy Docker镜像 ```ts docker pull phpswoole/phpy:1.0.5 ``` 通过`docker scout quickview`查看镜像供应链 ![](https://img.kancloud.cn/f2/38/f23829853327f879b69311c75327b1bc_1057x306.png)