Skip to content

How to infer on an image without saving it to a file #937

Answered by tominator95
lidiahhhh asked this question in Q&A
Discussion options

You must be logged in to vote

Hi,
I created a REST API for inference. When I send the request, I send the file within it. So its not saved anywhere. The inferencer.predict() fucntion expects a path to an image file or the image as numpy array. More in the code snippet:

from anomalib.deploy import TorchInferencer
from PIL import Image

inferencer = TorchInferencer(config="<<path to config>>", model_source="<<path to weights file>>", device="auto")

def predict(file: typing.IO[bytes]):
        file_bytes = bytearray(file.read())
        img = Image.open(io.BytesIO(file_bytes))
        img_arr = np.array(img)
       
       predictions = inferencer.predict(image=img_arr)

I hope that helps you.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@lidiahhhh
Comment options

Answer selected by lidiahhhh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants