How to infer on an image without saving it to a file #937
-
Hello, Can I call predict directly on the image array? The image is the result of an object detection step. |
Beta Was this translation helpful? Give feedback.
Answered by
tominator95
Mar 3, 2023
Replies: 1 comment 1 reply
-
Hi, 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. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
lidiahhhh
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:I hope that helps you.