why some image produce such error?
ERROR: Exception in ASGI application
Traceback (most recent call last):
File "/workspace/api101/venv/lib/python3.10/site-packages/uvicorn/protocols/http/httptools_impl.py", line 426, in run_asgi
result = await app( # type: ignore[func-returns-value]
File "/workspace/api101/venv/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 84, in __call__
return await self.app(scope, receive, send)
File "/workspace/api101/venv/lib/python3.10/site-packages/fastapi/applications.py", line 292, in __call__
await super().__call__(scope, receive, send)
File "/workspace/api101/venv/lib/python3.10/site-packages/starlette/applications.py", line 122, in __call__
await self.middleware_stack(scope, receive, send)
File "/workspace/api101/venv/lib/python3.10/site-packages/starlette/middleware/errors.py", line 184, in __call__
raise exc
File "/workspace/api101/venv/lib/python3.10/site-packages/starlette/middleware/errors.py", line 162, in __call__
await self.app(scope, receive, _send)
File "/workspace/api101/venv/lib/python3.10/site-packages/starlette/middleware/cors.py", line 83, in __call__
await self.app(scope, receive, send)
File "/workspace/api101/venv/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 79, in __call__
raise exc
File "/workspace/api101/venv/lib/python3.10/site-packages/starlette/middleware/exceptions.py", line 68, in __call__
await self.app(scope, receive, sender)
File "/workspace/api101/venv/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 20, in __call__
raise e
File "/workspace/api101/venv/lib/python3.10/site-packages/fastapi/middleware/asyncexitstack.py", line 17, in __call__
await self.app(scope, receive, send)
File "/workspace/api101/venv/lib/python3.10/site-packages/starlette/routing.py", line 718, in __call__
await route.handle(scope, receive, send)
File "/workspace/api101/venv/lib/python3.10/site-packages/starlette/routing.py", line 276, in handle
await self.app(scope, receive, send)
File "/workspace/api101/venv/lib/python3.10/site-packages/starlette/routing.py", line 66, in app
response = await func(request)
File "/workspace/api101/venv/lib/python3.10/site-packages/fastapi/routing.py", line 273, in app
raw_response = await run_endpoint_function(
File "/workspace/api101/venv/lib/python3.10/site-packages/fastapi/routing.py", line 190, in run_endpoint_function
return await dependant.call(**values)
File "/workspace/api101/main.py", line 106, in replace_background
output_image = pipe(
File "/workspace/api101/venv/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
return func(*args, **kwargs)
File "/workspace/api101/venv/lib/python3.10/site-packages/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py", line 982, in __call__
latent_model_input = torch.cat([latent_model_input, mask, masked_image_latents], dim=1)
RuntimeError: Sizes of tensors must match except in dimension 1. Expected size 96 but got size 768 for tensor number 2 in the list.
@app.post('/replace-background/')
async def replace_background (
input: UploadFile = Form(),
prompt: str = Form(),
width: int = Form(),
height: int = Form(),
steps: Optional[int] = Form(20),
strength: Optional[float] = Form(1.0),
return_base64: Optional[bool] = Form(False)
):
file = await input.read()
image = Image.open(io.BytesIO(file))
mask = rembg.remove(image, only_mask=True)
init_image = image.resize(image.size)
mask_image = ImageOps.invert(mask.resize(init_image.size))
model = './realisticVisionV51_v51VAE-inpainting.safetensors'
pipe = StableDiffusionInpaintPipeline.from_single_file(model).to('cuda')
output_image = pipe(
prompt = prompt,
image = image,
mask_image = mask,
width = width,
height = height,
strength = strength,
num_inference_steps = steps,
).images[0]
buffer = io.BytesIO()
output_image.resize((image.width, image.height)).save(buffer, 'PNG')
buffer.seek(0)
if return_base64:
encoded_image = base64.b64encode(buffer.getvalue()).decode('utf-8')
return { 'image_base64': encoded_image }
else:
return StreamingResponse(buffer, media_type = 'image/png')
this one failed