suvadityamuk
commited on
Commit
•
471c9f3
1
Parent(s):
dc063d8
added new files and made changes in app.py
Browse filesSigned-off-by: Suvaditya Mukherjee <suvadityamuk@gmail.com>
This view is limited to 50 files because it contains too many changes.
See raw diff
- app.py +16 -15
- celeb_dataset/Angelina Jolie/006_9135205d.jpg +3 -0
- celeb_dataset/Angelina Jolie/007_cabbfcbb.jpg +3 -0
- celeb_dataset/Angelina Jolie/008_d1f87068.jpg +3 -0
- celeb_dataset/Angelina Jolie/009_fb3e6174.jpg +3 -0
- celeb_dataset/Angelina Jolie/010_f99d79e3.jpg +3 -0
- celeb_dataset/Brad Pitt/006_87166f38.jpg +3 -0
- celeb_dataset/Brad Pitt/007_74ccfb4a.jpg +3 -0
- celeb_dataset/Brad Pitt/008_31e90c6b.jpg +3 -0
- celeb_dataset/Brad Pitt/009_23c94f29.jpg +3 -0
- celeb_dataset/Brad Pitt/010_08c44431.jpg +3 -0
- celeb_dataset/Denzel Washington/006_2880115c.jpg +3 -0
- celeb_dataset/Denzel Washington/007_1f6f632a.jpg +3 -0
- celeb_dataset/Denzel Washington/008_7619a328.jpg +3 -0
- celeb_dataset/Denzel Washington/009_817304c7.jpg +3 -0
- celeb_dataset/Denzel Washington/010_47031d88.jpg +3 -0
- celeb_dataset/Hugh Jackman/006_ff6876d9.jpg +3 -0
- celeb_dataset/Hugh Jackman/007_68abd54d.jpg +3 -0
- celeb_dataset/Hugh Jackman/008_d5553651.jpg +3 -0
- celeb_dataset/Hugh Jackman/009_11c22a3b.jpg +3 -0
- celeb_dataset/Hugh Jackman/010_cce39614.jpg +3 -0
- celeb_dataset/Jennifer Lawrence/006_2d0dccd4.jpg +3 -0
- celeb_dataset/Jennifer Lawrence/007_72ad75ba.jpg +3 -0
- celeb_dataset/Jennifer Lawrence/008_35fbbb0c.jpg +3 -0
- celeb_dataset/Jennifer Lawrence/009_bcd380a7.jpg +3 -0
- celeb_dataset/Jennifer Lawrence/010_34d63b53.jpg +3 -0
- celeb_dataset/Johnny Depp/006_8fc31fd7.jpg +3 -0
- celeb_dataset/Johnny Depp/007_1bc0bcd6.jpg +3 -0
- celeb_dataset/Johnny Depp/008_35d1be70.jpg +3 -0
- celeb_dataset/Johnny Depp/009_f4a38fec.jpg +3 -0
- celeb_dataset/Johnny Depp/010_610eea60.jpg +3 -0
- celeb_dataset/Kate Winslet/006_eda1948f.jpg +3 -0
- celeb_dataset/Kate Winslet/007_572cf58c.jpg +3 -0
- celeb_dataset/Kate Winslet/008_6c01eb52.jpg +3 -0
- celeb_dataset/Kate Winslet/009_07c15c37.jpg +3 -0
- celeb_dataset/Kate Winslet/010_6102c83d.jpg +3 -0
- celeb_dataset/Leonardo DiCaprio/006_30010640.jpg +3 -0
- celeb_dataset/Leonardo DiCaprio/007_6ca7c622.jpg +3 -0
- celeb_dataset/Leonardo DiCaprio/008_35daa4bc.jpg +3 -0
- celeb_dataset/Leonardo DiCaprio/009_b86449f6.jpg +3 -0
- celeb_dataset/Leonardo DiCaprio/010_2f9c83bc.jpg +3 -0
- celeb_dataset/Megan Fox/006_4e33c943.jpg +3 -0
- celeb_dataset/Megan Fox/007_e3073d58.jpg +3 -0
- celeb_dataset/Megan Fox/008_74bda018.jpg +3 -0
- celeb_dataset/Megan Fox/009_3283c30e.jpg +3 -0
- celeb_dataset/Megan Fox/010_0479e335.jpg +3 -0
- celeb_dataset/Natalie Portman/006_51ad8fdd.jpg +3 -0
- celeb_dataset/Natalie Portman/007_b82eb947.jpg +3 -0
- celeb_dataset/Natalie Portman/008_8fc20495.jpg +3 -0
- celeb_dataset/Natalie Portman/009_3300e98f.jpg +3 -0
app.py
CHANGED
@@ -10,15 +10,15 @@ from sklearn.svm import SVC
|
|
10 |
|
11 |
def calc_embeddings(all_files, names):
|
12 |
detector = cv2.dnn.readNetFromCaffe(
|
13 |
-
"
|
14 |
)
|
15 |
-
embedder = cv2.dnn.readNetFromTorch("
|
16 |
knownNames = []
|
17 |
knownEmbeddings = []
|
18 |
total = 0
|
19 |
for file in all_files:
|
20 |
name = names[total]
|
21 |
-
path = os.path.join(os.getcwd(), name, file)
|
22 |
# f = open(f"/celeb_dataset/'{name}'/{file}", "rb")
|
23 |
f = open(path, "rb")
|
24 |
file_bytes = np.asarray(bytearray(f.read()), dtype=np.uint8)
|
@@ -57,9 +57,9 @@ def calc_embeddings(all_files, names):
|
|
57 |
knownNames.append(name)
|
58 |
knownEmbeddings.append(vec.flatten())
|
59 |
total += 1
|
60 |
-
with open("
|
61 |
l = pickle.load(fp)
|
62 |
-
with open("
|
63 |
n = pickle.load(fp)
|
64 |
for i in l:
|
65 |
knownEmbeddings.append(i)
|
@@ -79,27 +79,27 @@ def recognize(embeddings, names):
|
|
79 |
|
80 |
def run_inference(myImage):
|
81 |
|
82 |
-
os.chdir("celeb_dataset")
|
83 |
celebs = []
|
84 |
scores = dict()
|
85 |
|
86 |
-
for celeb in os.listdir():
|
87 |
files = []
|
88 |
names = []
|
89 |
if celeb in celebs:
|
90 |
continue
|
91 |
name = celeb
|
92 |
celebs.append(name)
|
93 |
-
for file in os.listdir(celeb):
|
94 |
files.append(file)
|
95 |
names.append(name)
|
96 |
embeddings, names = calc_embeddings(files, names)
|
97 |
le, model = recognize(embeddings, names)
|
98 |
detector = cv2.dnn.readNetFromCaffe(
|
99 |
-
"
|
100 |
-
"
|
101 |
)
|
102 |
-
embedder = cv2.dnn.readNetFromTorch("
|
103 |
(h, w) = myImage.shape[:2]
|
104 |
imageBlob = cv2.dnn.blobFromImage(
|
105 |
cv2.resize(myImage, (300, 300)),
|
@@ -130,10 +130,11 @@ def run_inference(myImage):
|
|
130 |
j = np.argmax(preds)
|
131 |
proba = preds[j]
|
132 |
name = le.classes_[j]
|
133 |
-
|
134 |
-
scores[name] = proba
|
135 |
-
|
136 |
-
|
|
|
137 |
|
138 |
|
139 |
iface = gr.Interface(
|
|
|
10 |
|
11 |
def calc_embeddings(all_files, names):
|
12 |
detector = cv2.dnn.readNetFromCaffe(
|
13 |
+
"deploy.prototxt.txt", "res10_300x300_ssd_iter_140000.caffemodel"
|
14 |
)
|
15 |
+
embedder = cv2.dnn.readNetFromTorch("openface.nn4.small2.v1.t7")
|
16 |
knownNames = []
|
17 |
knownEmbeddings = []
|
18 |
total = 0
|
19 |
for file in all_files:
|
20 |
name = names[total]
|
21 |
+
path = os.path.join(os.getcwd(), 'celeb_dataset', name, file)
|
22 |
# f = open(f"/celeb_dataset/'{name}'/{file}", "rb")
|
23 |
f = open(path, "rb")
|
24 |
file_bytes = np.asarray(bytearray(f.read()), dtype=np.uint8)
|
|
|
57 |
knownNames.append(name)
|
58 |
knownEmbeddings.append(vec.flatten())
|
59 |
total += 1
|
60 |
+
with open("unknownEmbeddings.pkl", "rb") as fp:
|
61 |
l = pickle.load(fp)
|
62 |
+
with open("unknownNames.pkl", "rb") as fp:
|
63 |
n = pickle.load(fp)
|
64 |
for i in l:
|
65 |
knownEmbeddings.append(i)
|
|
|
79 |
|
80 |
def run_inference(myImage):
|
81 |
|
82 |
+
# os.chdir("./celeb_dataset")
|
83 |
celebs = []
|
84 |
scores = dict()
|
85 |
|
86 |
+
for celeb in os.listdir("./celeb_dataset"):
|
87 |
files = []
|
88 |
names = []
|
89 |
if celeb in celebs:
|
90 |
continue
|
91 |
name = celeb
|
92 |
celebs.append(name)
|
93 |
+
for file in os.listdir(os.path.join(os.getcwd(), 'celeb_dataset', celeb)):
|
94 |
files.append(file)
|
95 |
names.append(name)
|
96 |
embeddings, names = calc_embeddings(files, names)
|
97 |
le, model = recognize(embeddings, names)
|
98 |
detector = cv2.dnn.readNetFromCaffe(
|
99 |
+
"deploy.prototxt.txt",
|
100 |
+
"res10_300x300_ssd_iter_140000.caffemodel",
|
101 |
)
|
102 |
+
embedder = cv2.dnn.readNetFromTorch("openface.nn4.small2.v1.t7")
|
103 |
(h, w) = myImage.shape[:2]
|
104 |
imageBlob = cv2.dnn.blobFromImage(
|
105 |
cv2.resize(myImage, (300, 300)),
|
|
|
130 |
j = np.argmax(preds)
|
131 |
proba = preds[j]
|
132 |
name = le.classes_[j]
|
133 |
+
text = "{}: {:.2f}%".format(name, proba * 100)
|
134 |
+
scores[name] = proba
|
135 |
+
if len(scores)>1:
|
136 |
+
del scores["Unknown"]
|
137 |
+
return scores
|
138 |
|
139 |
|
140 |
iface = gr.Interface(
|
celeb_dataset/Angelina Jolie/006_9135205d.jpg
ADDED
Git LFS Details
|
celeb_dataset/Angelina Jolie/007_cabbfcbb.jpg
ADDED
Git LFS Details
|
celeb_dataset/Angelina Jolie/008_d1f87068.jpg
ADDED
Git LFS Details
|
celeb_dataset/Angelina Jolie/009_fb3e6174.jpg
ADDED
Git LFS Details
|
celeb_dataset/Angelina Jolie/010_f99d79e3.jpg
ADDED
Git LFS Details
|
celeb_dataset/Brad Pitt/006_87166f38.jpg
ADDED
Git LFS Details
|
celeb_dataset/Brad Pitt/007_74ccfb4a.jpg
ADDED
Git LFS Details
|
celeb_dataset/Brad Pitt/008_31e90c6b.jpg
ADDED
Git LFS Details
|
celeb_dataset/Brad Pitt/009_23c94f29.jpg
ADDED
Git LFS Details
|
celeb_dataset/Brad Pitt/010_08c44431.jpg
ADDED
Git LFS Details
|
celeb_dataset/Denzel Washington/006_2880115c.jpg
ADDED
Git LFS Details
|
celeb_dataset/Denzel Washington/007_1f6f632a.jpg
ADDED
Git LFS Details
|
celeb_dataset/Denzel Washington/008_7619a328.jpg
ADDED
Git LFS Details
|
celeb_dataset/Denzel Washington/009_817304c7.jpg
ADDED
Git LFS Details
|
celeb_dataset/Denzel Washington/010_47031d88.jpg
ADDED
Git LFS Details
|
celeb_dataset/Hugh Jackman/006_ff6876d9.jpg
ADDED
Git LFS Details
|
celeb_dataset/Hugh Jackman/007_68abd54d.jpg
ADDED
Git LFS Details
|
celeb_dataset/Hugh Jackman/008_d5553651.jpg
ADDED
Git LFS Details
|
celeb_dataset/Hugh Jackman/009_11c22a3b.jpg
ADDED
Git LFS Details
|
celeb_dataset/Hugh Jackman/010_cce39614.jpg
ADDED
Git LFS Details
|
celeb_dataset/Jennifer Lawrence/006_2d0dccd4.jpg
ADDED
Git LFS Details
|
celeb_dataset/Jennifer Lawrence/007_72ad75ba.jpg
ADDED
Git LFS Details
|
celeb_dataset/Jennifer Lawrence/008_35fbbb0c.jpg
ADDED
Git LFS Details
|
celeb_dataset/Jennifer Lawrence/009_bcd380a7.jpg
ADDED
Git LFS Details
|
celeb_dataset/Jennifer Lawrence/010_34d63b53.jpg
ADDED
Git LFS Details
|
celeb_dataset/Johnny Depp/006_8fc31fd7.jpg
ADDED
Git LFS Details
|
celeb_dataset/Johnny Depp/007_1bc0bcd6.jpg
ADDED
Git LFS Details
|
celeb_dataset/Johnny Depp/008_35d1be70.jpg
ADDED
Git LFS Details
|
celeb_dataset/Johnny Depp/009_f4a38fec.jpg
ADDED
Git LFS Details
|
celeb_dataset/Johnny Depp/010_610eea60.jpg
ADDED
Git LFS Details
|
celeb_dataset/Kate Winslet/006_eda1948f.jpg
ADDED
Git LFS Details
|
celeb_dataset/Kate Winslet/007_572cf58c.jpg
ADDED
Git LFS Details
|
celeb_dataset/Kate Winslet/008_6c01eb52.jpg
ADDED
Git LFS Details
|
celeb_dataset/Kate Winslet/009_07c15c37.jpg
ADDED
Git LFS Details
|
celeb_dataset/Kate Winslet/010_6102c83d.jpg
ADDED
Git LFS Details
|
celeb_dataset/Leonardo DiCaprio/006_30010640.jpg
ADDED
Git LFS Details
|
celeb_dataset/Leonardo DiCaprio/007_6ca7c622.jpg
ADDED
Git LFS Details
|
celeb_dataset/Leonardo DiCaprio/008_35daa4bc.jpg
ADDED
Git LFS Details
|
celeb_dataset/Leonardo DiCaprio/009_b86449f6.jpg
ADDED
Git LFS Details
|
celeb_dataset/Leonardo DiCaprio/010_2f9c83bc.jpg
ADDED
Git LFS Details
|
celeb_dataset/Megan Fox/006_4e33c943.jpg
ADDED
Git LFS Details
|
celeb_dataset/Megan Fox/007_e3073d58.jpg
ADDED
Git LFS Details
|
celeb_dataset/Megan Fox/008_74bda018.jpg
ADDED
Git LFS Details
|
celeb_dataset/Megan Fox/009_3283c30e.jpg
ADDED
Git LFS Details
|
celeb_dataset/Megan Fox/010_0479e335.jpg
ADDED
Git LFS Details
|
celeb_dataset/Natalie Portman/006_51ad8fdd.jpg
ADDED
Git LFS Details
|
celeb_dataset/Natalie Portman/007_b82eb947.jpg
ADDED
Git LFS Details
|
celeb_dataset/Natalie Portman/008_8fc20495.jpg
ADDED
Git LFS Details
|
celeb_dataset/Natalie Portman/009_3300e98f.jpg
ADDED
Git LFS Details
|