Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuntimeError: (PreconditionNotMet) Tensor holds no memory. Call Tensor::mutable_data firstly. #327

Open
Kun-Zhang-x opened this issue Jan 17, 2025 · 1 comment

Comments

@Kun-Zhang-x
Copy link

Kun-Zhang-x commented Jan 17, 2025

问题描述 / Problem Description

python封装ocr识别的接口,java多线程调用,经常出现下面报错,但是找到这张图片,重新调用可以正常识别。

Traceback (most recent call last):

  File "/data/virtualenvs/recognition/bin/gunicorn", line 8, in <module>
    sys.exit(run())
    │   │    └ <function run at 0x7f0c827d85e0>
    │   └ <built-in function exit><module 'sys' (built-in)>
  File "/data/virtualenvs/recognition/lib/python3.11/site-packages/gunicorn/app/wsgiapp.py", line 66, in run
    WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]", prog=prog).run()
    │                                                       └ None
    └ <class 'gunicorn.app.wsgiapp.WSGIApplication'>
  File "/data/virtualenvs/recognition/lib/python3.11/site-packages/gunicorn/app/base.py", line 235, in run
    super().run()
  File "/data/virtualenvs/recognition/lib/python3.11/site-packages/gunicorn/app/base.py", line 71, in run
    Arbiter(self).run()
    │       └ <gunicorn.app.wsgiapp.WSGIApplication object at 0x7f0c7b39f790><class 'gunicorn.arbiter.Arbiter'>
  File "/data/virtualenvs/recognition/lib/python3.11/site-packages/gunicorn/arbiter.py", line 201, in run
    self.manage_workers()
    │    └ <function Arbiter.manage_workers at 0x7f0c78614b80><gunicorn.arbiter.Arbiter object at 0x7f0c778a2d10>
  File "/data/virtualenvs/recognition/lib/python3.11/site-packages/gunicorn/arbiter.py", line 570, in manage_workers
    self.spawn_workers()
    │    └ <function Arbiter.spawn_workers at 0x7f0c78614cc0><gunicorn.arbiter.Arbiter object at 0x7f0c778a2d10>
  File "/data/virtualenvs/recognition/lib/python3.11/site-packages/gunicorn/arbiter.py", line 641, in spawn_workers
    self.spawn_worker()
    │    └ <function Arbiter.spawn_worker at 0x7f0c78614c20><gunicorn.arbiter.Arbiter object at 0x7f0c778a2d10>
  File "/data/virtualenvs/recognition/lib/python3.11/site-packages/gunicorn/arbiter.py", line 608, in spawn_worker
    worker.init_process()
    │      └ <function UvicornWorker.init_process at 0x7f0c7672e660><uvicorn.workers.UvicornWorker object at 0x7f0c76790450>
  File "/data/virtualenvs/recognition/lib/python3.11/site-packages/uvicorn/workers.py", line 75, in init_process
    super().init_process()
  File "/data/virtualenvs/recognition/lib/python3.11/site-packages/gunicorn/workers/base.py", line 143, in init_process
    self.run()
    │    └ <function UvicornWorker.run at 0x7f0c767896c0><uvicorn.workers.UvicornWorker object at 0x7f0c76790450>
  File "/data/virtualenvs/recognition/lib/python3.11/site-packages/uvicorn/workers.py", line 107, in run
    return asyncio.run(self._serve())
           │       │   │    └ <function UvicornWorker._serve at 0x7f0c76789620>
           │       │   └ <uvicorn.workers.UvicornWorker object at 0x7f0c76790450>
           │       └ <function run at 0x7f0c76fc6520><module 'asyncio' from '/home/python3/lib/python3.11/asyncio/__init__.py'>
  File "/home/python3/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           │      │   └ <coroutine object UvicornWorker._serve at 0x7f0baabaf9f0>
           │      └ <function Runner.run at 0x7f0c76fca700><asyncio.runners.Runner object at 0x7f0ab5d8b250>
  File "/home/python3/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           │    │     │                  └ <Task pending name='Task-1' coro=<UvicornWorker._serve() running at /data/virtualenvs/recognition/lib/python3.11/site-package...
           │    │     └ <function BaseEventLoop.run_until_complete at 0x7f0c76fc8360>
           │    └ <_UnixSelectorEventLoop running=True closed=False debug=False><asyncio.runners.Runner object at 0x7f0ab5d8b250>
  File "/home/python3/lib/python3.11/asyncio/base_events.py", line 641, in run_until_complete
    self.run_forever()
    │    └ <function BaseEventLoop.run_forever at 0x7f0c76fc82c0><_UnixSelectorEventLoop running=True closed=False debug=False>
  File "/home/python3/lib/python3.11/asyncio/base_events.py", line 608, in run_forever
    self._run_once()
    │    └ <function BaseEventLoop._run_once at 0x7f0c76fca0c0><_UnixSelectorEventLoop running=True closed=False debug=False>
  File "/home/python3/lib/python3.11/asyncio/base_events.py", line 1936, in _run_once
    handle._run()
    │      └ <function Handle._run at 0x7f0c76f5ede0><Handle Task.task_wakeup(<Future cancelled>)>
  File "/home/python3/lib/python3.11/asyncio/events.py", line 84, in _run
    self._context.run(self._callback, *self._args)
    │    │            │    │           │    └ <member '_args' of 'Handle' objects>
    │    │            │    │           └ <Handle Task.task_wakeup(<Future cancelled>)>
    │    │            │    └ <member '_callback' of 'Handle' objects>
    │    │            └ <Handle Task.task_wakeup(<Future cancelled>)>
    │    └ <member '_context' of 'Handle' objects><Handle Task.task_wakeup(<Future cancelled>)>
> File "/data/virtualenvs/recognition/lib/python3.11/site-packages/uvicorn/protocols/http/h11_impl.py", line 406, in run_asgi
    result = await app(  # type: ignore[func-returns-value]<uvicorn.middleware.proxy_headers.ProxyHeadersMiddleware object at 0x7f0ab563e810>
  File "/data/virtualenvs/recognition/lib/python3.11/site-packages/uvicorn/middleware/proxy_headers.py", line 70, in __call__
    return await self.app(scope, receive, send)
                 │    │   │      │        └ <bound method RequestResponseCycle.send of <uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x7f09027b3610>>
                 │    │   │      └ <bound method RequestResponseCycle.receive of <uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x7f09027b3610>>
                 │    │   └ {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.4'}, 'http_version': '1.0', 'server': ('172.25.240.67', 8000),...
                 │    └ <fastapi.applications.FastAPI object at 0x7f0ba88fba90><uvicorn.middleware.proxy_headers.ProxyHeadersMiddleware object at 0x7f0ab563e810>
  File "/data/virtualenvs/recognition/lib/python3.11/site-packages/fastapi/applications.py", line 1054, in __call__
    await super().__call__(scope, receive, send)
                           │      │        └ <bound method RequestResponseCycle.send of <uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x7f09027b3610>>
                           │      └ <bound method RequestResponseCycle.receive of <uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x7f09027b3610>>
                           └ {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.4'}, 'http_version': '1.0', 'server': ('172.25.240.67', 8000),...
  File "/data/virtualenvs/recognition/lib/python3.11/site-packages/starlette/applications.py", line 123, in __call__
    await self.middleware_stack(scope, receive, send)
          │    │                │      │        └ <bound method RequestResponseCycle.send of <uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x7f09027b3610>>
          │    │                │      └ <bound method RequestResponseCycle.receive of <uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x7f09027b3610>>
          │    │                └ {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.4'}, 'http_version': '1.0', 'server': ('172.25.240.67', 8000),...
          │    └ <starlette.middleware.errors.ServerErrorMiddleware object at 0x7f0ab5354490><fastapi.applications.FastAPI object at 0x7f0ba88fba90>
  File "/data/virtualenvs/recognition/lib/python3.11/site-packages/starlette/middleware/errors.py", line 186, in __call__
    raise exc
  File "/data/virtualenvs/recognition/lib/python3.11/site-packages/starlette/middleware/errors.py", line 164, in __call__
    await self.app(scope, receive, _send)
          │    │   │      │        └ <function ServerErrorMiddleware.__call__.<locals>._send at 0x7f09023e3d80>
          │    │   │      └ <bound method RequestResponseCycle.receive of <uvicorn.protocols.http.h11_impl.RequestResponseCycle object at 0x7f09027b3610>>
          │    │   └ {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.4'}, 'http_version': '1.0', 'server': ('172.25.240.67', 8000),...
          │    └ <config.trace_id_middleware.TraceIdMiddleware object at 0x7f0ab63abe50><starlette.middleware.errors.ServerErrorMiddleware object at 0x7f0ab5354490>
  File "/data/virtualenvs/recognition/lib/python3.11/site-packages/starlette/middleware/base.py", line 189, in __call__
    with collapse_excgroups():
         └ <function collapse_excgroups at 0x7f0c74f28720>
  File "/home/python3/lib/python3.11/contextlib.py", line 158, in __exit__
    self.gen.throw(typ, value, traceback)
    │    │   │     │    │      └ <traceback object at 0x7f090c5871c0>
    │    │   │     │    └ ExceptionGroup('unhandled errors in a TaskGroup', [RuntimeError('(PreconditionNotMet) Tensor holds no memory. Call Tensor::mu...
    │    │   │     └ <class 'ExceptionGroup'>
    │    │   └ <method 'throw' of 'generator' objects>
    │    └ <generator object collapse_excgroups at 0x7f0a143e8d60>
    └ <contextlib._GeneratorContextManager object at 0x7f09027b1610>
  File "/data/virtualenvs/recognition/lib/python3.11/site-packages/starlette/_utils.py", line 89, in collapse_excgroups
    raise exc
  File "/data/virtualenvs/recognition/lib/python3.11/site-packages/starlette/middleware/base.py", line 191, in __call__
    response = await self.dispatch_func(request, call_next)
                     │    │             │        └ <function BaseHTTPMiddleware.__call__.<locals>.call_next at 0x7f09023e1800>
                     │    │             └ <starlette.middleware.base._CachedRequest object at 0x7f090252c750>
                     │    └ <bound method TraceIdMiddleware.dispatch of <config.trace_id_middleware.TraceIdMiddleware object at 0x7f0ab63abe50>>
                     └ <config.trace_id_middleware.TraceIdMiddleware object at 0x7f0ab63abe50>

  File "/app/recognition/config/trace_id_middleware.py", line 29, in dispatch
    response = await call_next(request)
                     │         └ <starlette.middleware.base._CachedRequest object at 0x7f090252c750>
                     └ <function BaseHTTPMiddleware.__call__.<locals>.call_next at 0x7f09023e1800>

  File "/data/virtualenvs/recognition/lib/python3.11/site-packages/starlette/middleware/base.py", line 165, in call_next
    raise app_exc
          └ RuntimeError('(PreconditionNotMet) Tensor holds no memory. Call Tensor::mutable_data firstly.\n  [Hint: holder_ should not be...
  File "/data/virtualenvs/recognition/lib/python3.11/site-packages/starlette/middleware/base.py", line 151, in coro
    await self.app(scope, receive_or_disconnect, send_no_error)
          │    │   │      │                      └ <function BaseHTTPMiddleware.__call__.<locals>.call_next.<locals>.send_no_error at 0x7f09023e2de0>
          │    │   │      └ <function BaseHTTPMiddleware.__call__.<locals>.call_next.<locals>.receive_or_disconnect at 0x7f09023e23e0>
          │    │   └ {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.4'}, 'http_version': '1.0', 'server': ('172.25.240.67', 8000),...
          │    └ <starlette.middleware.exceptions.ExceptionMiddleware object at 0x7f0ab63ab7d0><config.trace_id_middleware.TraceIdMiddleware object at 0x7f0ab63abe50>
  File "/data/virtualenvs/recognition/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 65, in __call__
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
          │                            │    │    │     │      │        └ <function BaseHTTPMiddleware.__call__.<locals>.call_next.<locals>.send_no_error at 0x7f09023e2de0>
          │                            │    │    │     │      └ <function BaseHTTPMiddleware.__call__.<locals>.call_next.<locals>.receive_or_disconnect at 0x7f09023e23e0>
          │                            │    │    │     └ {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.4'}, 'http_version': '1.0', 'server': ('172.25.240.67', 8000),...
          │                            │    │    └ <starlette.requests.Request object at 0x7f09027b3f50>
          │                            │    └ <fastapi.routing.APIRouter object at 0x7f0c74e83190>
          │                            └ <starlette.middleware.exceptions.ExceptionMiddleware object at 0x7f0ab63ab7d0><function wrap_app_handling_exceptions at 0x7f0c74daae80>
  File "/data/virtualenvs/recognition/lib/python3.11/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
    raise exc
  File "/data/virtualenvs/recognition/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    await app(scope, receive, sender)
          │   │      │        └ <function wrap_app_handling_exceptions.<locals>.wrapped_app.<locals>.sender at 0x7f09023e2700>
          │   │      └ <function BaseHTTPMiddleware.__call__.<locals>.call_next.<locals>.receive_or_disconnect at 0x7f09023e23e0>
          │   └ {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.4'}, 'http_version': '1.0', 'server': ('172.25.240.67', 8000),...
          └ <fastapi.routing.APIRouter object at 0x7f0c74e83190>
  File "/data/virtualenvs/recognition/lib/python3.11/site-packages/starlette/routing.py", line 754, in __call__
    await self.middleware_stack(scope, receive, send)
          │    │                │      │        └ <function wrap_app_handling_exceptions.<locals>.wrapped_app.<locals>.sender at 0x7f09023e2700>
          │    │                │      └ <function BaseHTTPMiddleware.__call__.<locals>.call_next.<locals>.receive_or_disconnect at 0x7f09023e23e0>
          │    │                └ {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.4'}, 'http_version': '1.0', 'server': ('172.25.240.67', 8000),...
          │    └ <bound method Router.app of <fastapi.routing.APIRouter object at 0x7f0c74e83190>><fastapi.routing.APIRouter object at 0x7f0c74e83190>
  File "/data/virtualenvs/recognition/lib/python3.11/site-packages/starlette/routing.py", line 774, in app
    await route.handle(scope, receive, send)
          │     │      │      │        └ <function wrap_app_handling_exceptions.<locals>.wrapped_app.<locals>.sender at 0x7f09023e2700>
          │     │      │      └ <function BaseHTTPMiddleware.__call__.<locals>.call_next.<locals>.receive_or_disconnect at 0x7f09023e23e0>
          │     │      └ {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.4'}, 'http_version': '1.0', 'server': ('172.25.240.67', 8000),...
          │     └ <function Route.handle at 0x7f0c74dc8540>
          └ APIRoute(path='/ocr/rapid', name='ocr', methods=['POST'])
  File "/data/virtualenvs/recognition/lib/python3.11/site-packages/starlette/routing.py", line 295, in handle
    await self.app(scope, receive, send)
          │    │   │      │        └ <function wrap_app_handling_exceptions.<locals>.wrapped_app.<locals>.sender at 0x7f09023e2700>
          │    │   │      └ <function BaseHTTPMiddleware.__call__.<locals>.call_next.<locals>.receive_or_disconnect at 0x7f09023e23e0>
          │    │   └ {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.4'}, 'http_version': '1.0', 'server': ('172.25.240.67', 8000),...
          │    └ <function request_response.<locals>.app at 0x7f0ab4f18cc0>
          └ APIRoute(path='/ocr/rapid', name='ocr', methods=['POST'])
  File "/data/virtualenvs/recognition/lib/python3.11/site-packages/starlette/routing.py", line 77, in app
    await wrap_app_handling_exceptions(app, request)(scope, receive, send)
          │                            │    │        │      │        └ <function wrap_app_handling_exceptions.<locals>.wrapped_app.<locals>.sender at 0x7f09023e2700>
          │                            │    │        │      └ <function BaseHTTPMiddleware.__call__.<locals>.call_next.<locals>.receive_or_disconnect at 0x7f09023e23e0>
          │                            │    │        └ {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.4'}, 'http_version': '1.0', 'server': ('172.25.240.67', 8000),...
          │                            │    └ <starlette.requests.Request object at 0x7f090253c5d0>
          │                            └ <function request_response.<locals>.app.<locals>.app at 0x7f09023e0900><function wrap_app_handling_exceptions at 0x7f0c74daae80>
  File "/data/virtualenvs/recognition/lib/python3.11/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
    raise exc
  File "/data/virtualenvs/recognition/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    await app(scope, receive, sender)
          │   │      │        └ <function wrap_app_handling_exceptions.<locals>.wrapped_app.<locals>.sender at 0x7f09023e34c0>
          │   │      └ <function BaseHTTPMiddleware.__call__.<locals>.call_next.<locals>.receive_or_disconnect at 0x7f09023e23e0>
          │   └ {'type': 'http', 'asgi': {'version': '3.0', 'spec_version': '2.4'}, 'http_version': '1.0', 'server': ('172.25.240.67', 8000),...
          └ <function request_response.<locals>.app.<locals>.app at 0x7f09023e0900>
  File "/data/virtualenvs/recognition/lib/python3.11/site-packages/starlette/routing.py", line 74, in app
    response = await f(request)
                     │ └ <starlette.requests.Request object at 0x7f090253c5d0><function get_request_handler.<locals>.app at 0x7f0ab4f18d60>
  File "/data/virtualenvs/recognition/lib/python3.11/site-packages/fastapi/routing.py", line 278, in app
    raw_response = await run_endpoint_function(
                         └ <function run_endpoint_function at 0x7f0c74dc8040>
  File "/data/virtualenvs/recognition/lib/python3.11/site-packages/fastapi/routing.py", line 193, in run_endpoint_function
    return await run_in_threadpool(dependant.call, **values)
                 │                 │         │       └ {'ocrParam': OcrParam(image_path='http://192.168.240.62:19000/rpd-test/crawler/2025-01-16/17/7526/image/2.png', image_data=No...
                 │                 │         └ <function ocr at 0x7f0ae2e09ee0>
                 │                 └ <fastapi.dependencies.models.Dependant object at 0x7f0ab4f295d0><function run_in_threadpool at 0x7f0c757a0540>
  File "/data/virtualenvs/recognition/lib/python3.11/site-packages/starlette/concurrency.py", line 42, in run_in_threadpool
    return await anyio.to_thread.run_sync(func, *args)
                 │     │         │        │       ()
                 │     │         │        └ functools.partial(<function ocr at 0x7f0ae2e09ee0>, ocrParam=OcrParam(image_path='http://192.168.240.62:19000/rpd-test/crawle...
                 │     │         └ <function run_sync at 0x7f0c757a1800>
                 │     └ <module 'anyio.to_thread' from '/data/virtualenvs/recognition/lib/python3.11/site-packages/anyio/to_thread.py'>
                 └ <module 'anyio' from '/data/virtualenvs/recognition/lib/python3.11/site-packages/anyio/__init__.py'>
  File "/data/virtualenvs/recognition/lib/python3.11/site-packages/anyio/to_thread.py", line 56, in run_sync
    return await get_async_backend().run_sync_in_worker_thread(
                 └ <function get_async_backend at 0x7f0c757a1120>
  File "/data/virtualenvs/recognition/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 2441, in run_sync_in_worker_thread
    return await future
                 └ <Future finished exception=RuntimeError('(PreconditionNotMet) Tensor holds no memory. Call Tensor::mutable_data firstly.\n  [...
  File "/data/virtualenvs/recognition/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 943, in run
    result = context.run(func, *args)
             │       │   │       ()
             │       │   └ functools.partial(<function ocr at 0x7f0ae2e09ee0>, ocrParam=OcrParam(image_path='http://192.168.240.62:19000/rpd-test/crawle...
             │       └ <method 'run' of '_contextvars.Context' objects>
             └ <_contextvars.Context object at 0x7f090c7c3800>

  File "/app/recognition/ocr/rapid_ocr.py", line 40, in ocr
    ocr_res = processor(image)
              │         └ <PIL.PngImagePlugin.PngImageFile image mode=RGBA size=692x670 at 0x7F08986B3C90>
              └ <ocr.ocr_utils.OcrUtils object at 0x7f0ba7545fd0>

  File "/app/recognition/ocr/ocr_utils.py", line 31, in __call__
    ocr_res, elapse = self.ocr(img)
                      │    │   └ array([[[155, 155, 155, 255],
                      │    │             [156, 156, 156, 255],
                      │    │             [157, 157, 157, 255],
                      │    │             ...,
                      │    │             [182, 182, 174...
                      │    └ <rapidocr_paddle.main.RapidOCR object at 0x7f0ba4141cd0>
                      └ <ocr.ocr_utils.OcrUtils object at 0x7f0ba7545fd0>

  File "/data/virtualenvs/recognition/lib/python3.11/site-packages/rapidocr_paddle/main.py", line 96, in __call__
    rec_res, rec_elapse = self.text_rec(img)
    │                     │    │        └ [array([[[98, 98, 98],
    │                     │    │                  [98, 98, 98],
    │                     │    │                  [98, 98, 98],
    │                     │    │                  ...,
    │                     │    │                  [82, 80, 80],
    │                     │    │                  [80, 78, 78],
    │                     │    │           ...
    │                     │    └ <rapidocr_paddle.ch_ppocr_rec.text_recognize.TextRecognizer object at 0x7f0ba4136590>
    │                     └ <rapidocr_paddle.main.RapidOCR object at 0x7f0ba4141cd0>
    └ None
  File "/data/virtualenvs/recognition/lib/python3.11/site-packages/rapidocr_paddle/ch_ppocr_rec/text_recognize.py", line 73, in __call__
    preds = self.infer(norm_img_batch)[0]
            │    │     └ array([[[[-0.23137254, -0.23137254, -0.23137254, ...,  0.        ,
            │    │                  0.        ,  0.        ],
            │    │                [-0.23137254...
            │    └ <rapidocr_paddle.utils.infer_engine.PaddleInferSession object at 0x7f0ae9840350>
            └ <rapidocr_paddle.ch_ppocr_rec.text_recognize.TextRecognizer object at 0x7f0ba4136590>
  File "/data/virtualenvs/recognition/lib/python3.11/site-packages/rapidocr_paddle/utils/infer_engine.py", line 64, in __call__
    output = output_tensor.copy_to_cpu()
             │             └ <instancemethod copy_to_cpu at 0x7f0ae983b400>
             └ <paddle.base.libpaddle.PaddleInferTensor object at 0x7f0902535130>

RuntimeError: (PreconditionNotMet) Tensor holds no memory. Call Tensor::mutable_data firstly.
  [Hint: holder_ should not be null.] (at /paddle/paddle/phi/core/dense_tensor_impl.cc:44)

运行环境 / Runtime Environment

Linux version 3.10.0-1160.71.1.el7.x86_64 ([email protected]) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) ) 
Python 3.11.9
GPU:NVIDIA tesla t4
NVIDIA-SMI 550.90.07              Driver Version: 550.90.07      CUDA Version: 12.4 
rapidocr_paddle==1.3.27
paddlepaddle-gpu==2.6.2

复现代码 / Reproduction Code

import os
from PIL import Image
from typing import List
import numpy as np
from rapidocr_paddle import RapidOCR
import torch

os.environ["KMP_DUPLICATE_LIB_OK"] = "TRUE"


class OcrUtils:
    def __init__(self) -> None:
        cuda_is_available = torch.cuda.is_available()
        self.ocr = RapidOCR(det_use_cuda=cuda_is_available, cls_use_cuda=cuda_is_available, rec_use_cuda=cuda_is_available)


    def __call__(self, img: Image.Image) -> List:
        img = np.array(img)
        ocr_res, elapse = self.ocr(img)

        if not ocr_res:
            return []

        out_dict = [
            {
                "rec_txt": rec,
                "score": score
            }
            for dt_box, rec, score in ocr_res
        ]
        return out_dict

可能解决方案 / Possible solutions

@Kun-Zhang-x Kun-Zhang-x changed the title Bug RuntimeError: (PreconditionNotMet) Tensor holds no memory. Call Tensor::mutable_data firstly. Jan 17, 2025
@SWHL
Copy link
Member

SWHL commented Jan 19, 2025

试试rapidocr-onnxruntime cpu端呢?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants