Spaces:
Runtime error
Runtime error
File size: 799 Bytes
0777b3a eba7ca5 0777b3a afa9738 0777b3a c6bb0b9 afa9738 0777b3a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
import PIL.Image as Image
import torch
from fastai.vision.all import Learner
from numpy.typing import NDArray
from typing import List
class Processor():
def __init__(self, learn: Learner):
self.inference = learn
self.__model = torch.hub.load(
'ultralytics/yolov5', 'yolov5x6', trust_repo=True)
def classify_image(self, images: NDArray) -> str:
return self.inference.predict(images)
def filter_image(self, image: Image) -> bool:
results = self.__model(image)
results = results.pandas().xyxy[0]
person_detected = 0
for name in results['name']:
if name == 'person':
person_detected += 1
if person_detected == 0 or person_detected > 1:
return False
return True
|