Commit d3ec5ab 1 parent 03458fb commit d3ec5ab Copy full SHA for d3ec5ab
File tree 2 files changed +4
-15
lines changed
src/hope_dedup_engine/apps/faces
2 files changed +4
-15
lines changed Original file line number Diff line number Diff line change 1
- from fnmatch import fnmatch
2
- from typing import Final
3
-
4
1
from django .conf import settings
5
2
6
3
import cv2
7
4
import numpy as np
8
5
from storages .backends .azure_storage import AzureStorage
9
6
10
- FILES_PATTERN : Final [tuple [str ]] = ("*.png" , "*.jpg" , "*.jpeg" )
11
-
12
7
13
8
class ImagesStorageManager :
14
9
def __init__ (self ) -> None :
15
10
self .storage : AzureStorage = AzureStorage (** settings .STORAGES .get ("hope" ).get ("OPTIONS" ))
16
11
17
- def get_files (self , pattern : tuple = FILES_PATTERN ) -> list [str ]:
18
- _ , images = self .storage .listdir ("" )
19
- return [f for f in images if any (fnmatch (f , p ) for p in pattern )]
20
-
21
12
def load_image (self , file : str ) -> np .ndarray :
22
13
with self .storage .open (file , "rb" ) as img_file :
23
14
img_array = np .frombuffer (img_file .read (), dtype = np .uint8 )
Original file line number Diff line number Diff line change 2
2
from collections import defaultdict
3
3
from typing import Any
4
4
5
+ from azure .core .exceptions import ResourceNotFoundError
5
6
from deepface import DeepFace
6
7
7
8
from hope_dedup_engine .apps .api .models import Image
@@ -28,9 +29,6 @@ def encode_faces(
28
29
with report_long_execution ("ImagesStorageManager()" ):
29
30
storage = ImagesStorageManager ()
30
31
31
- with report_long_execution ("storage.get_files()" ):
32
- images = storage .get_files ()
33
-
34
32
encoded = {}
35
33
if pre_encodings :
36
34
with report_long_execution ("encoded.update(pre_encodings)" ):
@@ -40,9 +38,6 @@ def encode_faces(
40
38
for file in files :
41
39
with report_long_execution ("progress()" ):
42
40
progress ()
43
- if file not in images :
44
- encoded [file ] = Image .StatusCode .NO_FILE_FOUND .name
45
- continue
46
41
if file in encoded :
47
42
existing_cnt += 1
48
43
continue
@@ -59,6 +54,9 @@ def encode_faces(
59
54
encoded [file ] = Image .StatusCode .GENERIC_ERROR .name
60
55
except ValueError :
61
56
encoded [file ] = Image .StatusCode .NO_FACE_DETECTED .name
57
+ except ResourceNotFoundError :
58
+ encoded [file ] = Image .StatusCode .NO_FILE_FOUND .name
59
+
62
60
return encoded , added_cnt , existing_cnt
63
61
64
62
You can’t perform that action at this time.
0 commit comments