GithubHelp home page GithubHelp logo

Comments (2)

philippe-heitzmann avatar philippe-heitzmann commented on August 11, 2024

Hello, I am getting the same error when uploading a test image through the localhost:8000 "Upload File" UI while confirmed this works fine when attempting the same through the minimal implementation, would the team be able to please look at this? Please see below for the full error:

OSError: cannot open resource
INFO:     127.0.0.1:49700 - "GET / HTTP/1.1" 200 OK
INFO:     127.0.0.1:49700 - "GET /templates/main.css HTTP/1.1" 304 Not Modified
INFO:     127.0.0.1:49704 - "GET / HTTP/1.1" 200 OK
INFO:     127.0.0.1:49708 - "POST / HTTP/1.1" 500 Internal Server Error
ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/Users/opt/anaconda3/envs/yolov5_fastapi/lib/python3.8/site-packages/uvicorn/protocols/http/h11_impl.py", line 369, in run_asgi
    result = await app(self.scope, self.receive, self.send)
  File "/Users/opt/anaconda3/envs/yolov5_fastapi/lib/python3.8/site-packages/uvicorn/middleware/proxy_headers.py", line 59, in __call__
    return await self.app(scope, receive, send)
  File "/Users/opt/anaconda3/envs/yolov5_fastapi/lib/python3.8/site-packages/fastapi/applications.py", line 199, in __call__
    await super().__call__(scope, receive, send)
  File "/Users/opt/anaconda3/envs/yolov5_fastapi/lib/python3.8/site-packages/starlette/applications.py", line 112, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/Users/opt/anaconda3/envs/yolov5_fastapi/lib/python3.8/site-packages/starlette/middleware/errors.py", line 181, in __call__
    raise exc from None
  File "/Users/opt/anaconda3/envs/yolov5_fastapi/lib/python3.8/site-packages/starlette/middleware/errors.py", line 159, in __call__
    await self.app(scope, receive, _send)
  File "/Users/opt/anaconda3/envs/yolov5_fastapi/lib/python3.8/site-packages/starlette/exceptions.py", line 82, in __call__
    raise exc from None
  File "/Users/opt/anaconda3/envs/yolov5_fastapi/lib/python3.8/site-packages/starlette/exceptions.py", line 71, in __call__
    await self.app(scope, receive, sender)
  File "/Users/opt/anaconda3/envs/yolov5_fastapi/lib/python3.8/site-packages/starlette/routing.py", line 580, in __call__
    await route.handle(scope, receive, send)
  File "/Users/opt/anaconda3/envs/yolov5_fastapi/lib/python3.8/site-packages/starlette/routing.py", line 241, in handle
    await self.app(scope, receive, send)
  File "/Users/opt/anaconda3/envs/yolov5_fastapi/lib/python3.8/site-packages/starlette/routing.py", line 52, in app
    response = await func(request)
  File "/Users/opt/anaconda3/envs/yolov5_fastapi/lib/python3.8/site-packages/fastapi/routing.py", line 216, in app
    raw_response = await run_endpoint_function(
  File "/Users/opt/anaconda3/envs/yolov5_fastapi/lib/python3.8/site-packages/fastapi/routing.py", line 149, in run_endpoint_function
    return await dependant.call(**values)
  File "/Users//Object_Detection/yolov5-fastapi-demo/server.py", line 160, in detect_via_web_form
    plot_one_box(bbox['normalized_box'], img, label=label,
  File "/Users//Object_Detection/yolov5-fastapi-demo/server.py", line 85, in plot_one_box
    fnt = ImageFont.truetype("/usr/share/fonts/truetype/freefont/FreeMono.ttf", 36, encoding="unic")
  File "/Users/opt/anaconda3/envs/yolov5_fastapi/lib/python3.8/site-packages/PIL/ImageFont.py", line 855, in truetype
    return freetype(font)
  File "/Users/opt/anaconda3/envs/yolov5_fastapi/lib/python3.8/site-packages/PIL/ImageFont.py", line 852, in freetype
    return FreeTypeFont(font, size, index, encoding, layout_engine)
  File "/Users/opt/anaconda3/envs/yolov5_fastapi/lib/python3.8/site-packages/PIL/ImageFont.py", line 211, in __init__
    self.font = core.getfont(
OSError: cannot open resource
Exception in ASGI application
Traceback (most recent call last):
  File "/Users/opt/anaconda3/envs/yolov5_fastapi/lib/python3.8/site-packages/uvicorn/protocols/http/h11_impl.py", line 369, in run_asgi
    result = await app(self.scope, self.receive, self.send)
  File "/Users/opt/anaconda3/envs/yolov5_fastapi/lib/python3.8/site-packages/uvicorn/middleware/proxy_headers.py", line 59, in __call__
    return await self.app(scope, receive, send)
  File "/Users/opt/anaconda3/envs/yolov5_fastapi/lib/python3.8/site-packages/fastapi/applications.py", line 199, in __call__
    await super().__call__(scope, receive, send)
  File "/Users/opt/anaconda3/envs/yolov5_fastapi/lib/python3.8/site-packages/starlette/applications.py", line 112, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/Users/opt/anaconda3/envs/yolov5_fastapi/lib/python3.8/site-packages/starlette/middleware/errors.py", line 181, in __call__
    raise exc from None
  File "/Users/ opt/anaconda3/envs/yolov5_fastapi/lib/python3.8/site-packages/starlette/middleware/errors.py", line 159, in __call__
    await self.app(scope, receive, _send)
  File "/Users/opt/anaconda3/envs/yolov5_fastapi/lib/python3.8/site-packages/starlette/exceptions.py", line 82, in __call__
    raise exc from None
  File "/Users/opt/anaconda3/envs/yolov5_fastapi/lib/python3.8/site-packages/starlette/exceptions.py", line 71, in __call__
    await self.app(scope, receive, sender)
  File "/Users/opt/anaconda3/envs/yolov5_fastapi/lib/python3.8/site-packages/starlette/routing.py", line 580, in __call__
    await route.handle(scope, receive, send)
  File "/Users/opt/anaconda3/envs/yolov5_fastapi/lib/python3.8/site-packages/starlette/routing.py", line 241, in handle
    await self.app(scope, receive, send)
  File "/Users/opt/anaconda3/envs/yolov5_fastapi/lib/python3.8/site-packages/starlette/routing.py", line 52, in app
    response = await func(request)
  File "/Users/opt/anaconda3/envs/yolov5_fastapi/lib/python3.8/site-packages/fastapi/routing.py", line 216, in app
    raw_response = await run_endpoint_function(
  File "/Users/opt/anaconda3/envs/yolov5_fastapi/lib/python3.8/site-packages/fastapi/routing.py", line 149, in run_endpoint_function
    return await dependant.call(**values)
  File "/Users/Object_Detection/yolov5-fastapi-demo/server.py", line 160, in detect_via_web_form
    plot_one_box(bbox['normalized_box'], img, label=label,
  File "/Users/Object_Detection/yolov5-fastapi-demo/server.py", line 85, in plot_one_box
    fnt = ImageFont.truetype("/usr/share/fonts/truetype/freefont/FreeMono.ttf", 36, encoding="unic")
  File "/Users/opt/anaconda3/envs/yolov5_fastapi/lib/python3.8/site-packages/PIL/ImageFont.py", line 855, in truetype
    return freetype(font)
  File "/Users/opt/anaconda3/envs/yolov5_fastapi/lib/python3.8/site-packages/PIL/ImageFont.py", line 852, in freetype
    return FreeTypeFont(font, size, index, encoding, layout_engine)
  File "/Users/opt/anaconda3/envs/yolov5_fastapi/lib/python3.8/site-packages/PIL/ImageFont.py", line 211, in __init__
    self.font = core.getfont(
OSError: cannot open resource

Thank you!

from yolov5-fastapi-demo.

philippe-heitzmann avatar philippe-heitzmann commented on August 11, 2024

UPDATE: I was able to fix this by updating line 85 of server.py to the below. It looks like the above specified font may not be available on Linux OS and switching font to system default is therefore needed.

fnt = ImageFont.load_default()

from yolov5-fastapi-demo.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.