georghess / neurad-studio

[CVPR2024] NeuRAD: Neural Rendering for Autonomous Driving
https://research.zenseact.com/publications/neurad/
Apache License 2.0
346 stars 24 forks source link

Update closed loop server with new interface #9

Closed wljungbergh closed 6 months ago

wljungbergh commented 6 months ago

Update the closed-loop server

atonderski commented 6 months ago

I wonder if it would be better to allow for both raw tensors as well as actual images. Raw tensors are great if running on the same local connection (or even machine), but it could be horribly slow in other settings.

atonderski commented 6 months ago

maybe something like this:

class ImageFormat(str, Enum):
    raw = "raw"
    png = "png"
    jpg = "jpg"

@app.get("/image/")
async def get_image(format: ImageFormat = ImageFormat.jpg):
    image_bytes = get_image_bytes(format)  # Assuming get_image_bytes() method exists
    if format in (ImageFormat.jpg, ImageFormat.png):
        return Response(content=image_bytes, media_type=f"image/{format.value}")
    else:
        return PlainTextResponse(content=image_bytes, media_type="text/plain")

Alternatively, yours truly chatgpt suggested this, dunno if nice

    if format == ImageFormat.raw:
        return StreamingResponse(iter([image_bytes]), media_type="image/jpeg")
    elif format == ImageFormat.png:
        return StreamingResponse(iter([image_bytes]), media_type="image/png")
    elif format == ImageFormat.jpg:
        return StreamingResponse(iter([image_bytes]), media_type="image/jpeg")
wljungbergh commented 6 months ago

I like it. I added options for raw, png, and jpeg/jpg. However, I didn't change to the streaming response for now.