Spaces:
Runtime error
Runtime error
Revert last commit
Browse files- Processor.py +11 -2
- app.py +1 -2
Processor.py
CHANGED
@@ -10,9 +10,18 @@ class Processor():
|
|
10 |
self.__model = torch.hub.load(
|
11 |
'ultralytics/yolov5', 'yolov5x6', trust_repo=True)
|
12 |
|
13 |
-
def
|
14 |
-
|
|
|
15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
def filter_image(self, image: Image) -> bool:
|
17 |
results = self.__model(image)
|
18 |
results = results.pandas().xyxy[0]
|
|
|
10 |
self.__model = torch.hub.load(
|
11 |
'ultralytics/yolov5', 'yolov5x6', trust_repo=True)
|
12 |
|
13 |
+
def classify_images(self, images: List[NDArray]) -> List[str]:
|
14 |
+
result = []
|
15 |
+
class_names = self.__inference.dls.vocab
|
16 |
|
17 |
+
test_dl = self.__inference.dls.test_dl(images)
|
18 |
+
tensors = self.__inference.get_preds(dl=test_dl, with_decoded=True)[2]
|
19 |
+
preds = [int(t.item()) for t in tensors]
|
20 |
+
|
21 |
+
for i in preds:
|
22 |
+
result.append(class_names[i])
|
23 |
+
|
24 |
+
return result
|
25 |
def filter_image(self, image: Image) -> bool:
|
26 |
results = self.__model(image)
|
27 |
results = results.pandas().xyxy[0]
|
app.py
CHANGED
@@ -21,8 +21,7 @@ def process_images(images, processor: Processor):
|
|
21 |
if processor.filter_image(image):
|
22 |
filtered_images.append(np.asarray(image))
|
23 |
|
24 |
-
|
25 |
-
result.append(processor.classify_image(img)[0])
|
26 |
|
27 |
outfit = mode(result)
|
28 |
|
|
|
21 |
if processor.filter_image(image):
|
22 |
filtered_images.append(np.asarray(image))
|
23 |
|
24 |
+
result = processor.classify_images(filtered_images)
|
|
|
25 |
|
26 |
outfit = mode(result)
|
27 |
|