Commit 4e149412 authored by Данилов Егор Вадимович's avatar Данилов Егор Вадимович
Browse files

hw4: done task 3_2

parent f1490329
1 merge request!3homework 4
Showing with 265 additions and 13 deletions
+265 -13
Задание 1 [Ссылка на скринкаст](https://drive.google.com/file/d/1NkOrWvB7MN_F7HE4JrXJYbcaADkSU-BT/view?usp=sharing)
Задание 2 [Ссылка на скринкаст](https://drive.google.com/file/d/1FZa6tnDL8EPwTQNkvOc7InXlRpPxhXbs/view?usp=sharing)
Задание 3 [Ссылка на архив с фото](https://drive.google.com/file/d/1lzfjR7TEkcoXOj29QZ4UbrwVrywpHwCs/view?usp=sharing)
numpy==2.2.2
opencv-python==4.11.0.86
\ No newline at end of file
absl-py==2.1.0
altair==5.5.0
astunparse==1.6.3
attrs==25.1.0
beautifulsoup4==4.12.3
blinker==1.9.0
cachetools==5.5.1
certifi==2025.1.31
charset-normalizer==3.4.1
click==8.1.8
contourpy==1.3.1
cycler==0.12.1
deepface==0.0.93
faiss-cpu==1.10.0
filelock==3.17.0
fire==0.7.0
Flask==3.1.0
Flask-Cors==5.0.0
flatbuffers==25.1.24
fonttools==4.55.8
fsspec==2024.12.0
gast==0.6.0
gdown==5.2.0
gitdb==4.0.12
GitPython==3.1.44
google-pasta==0.2.0
grpcio==1.70.0
gunicorn==23.0.0
h5py==3.12.1
idna==3.10
itsdangerous==2.2.0
Jinja2==3.1.5
joblib==1.4.2
jsonschema==4.23.0
jsonschema-specifications==2024.10.1
keras==3.8.0
kiwisolver==1.4.8
libclang==18.1.1
lz4==4.4.3
Markdown==3.7
markdown-it-py==3.0.0
MarkupSafe==3.0.2
matplotlib==3.10.0
mdurl==0.1.2
ml-dtypes==0.4.1
mpmath==1.3.0
mtcnn==1.0.0
namex==0.0.8
narwhals==1.24.1
networkx==3.4.2
numpy==1.26.4
opencv-python==4.11.0.86
opt_einsum==3.4.0
optree==0.14.0
packaging==24.2
pandas==2.2.3
pillow==11.1.0
protobuf==4.25.6
psutil==6.1.1
py-cpuinfo==9.0.0
pyarrow==19.0.0
pydeck==0.9.1
Pygments==2.19.1
pyparsing==3.2.1
PySocks==1.7.1
python-dateutil==2.9.0.post0
pytz==2025.1
PyYAML==6.0.2
referencing==0.36.2
requests==2.32.3
retina-face==0.0.17
rich==13.9.4
rpds-py==0.22.3
scipy==1.15.1
seaborn==0.13.2
six==1.17.0
smmap==5.0.2
soupsieve==2.6
streamlit==1.41.1
sympy==1.13.1
tenacity==9.0.0
tensorboard==2.18.0
tensorboard-data-server==0.7.2
tensorflow==2.18.0
tensorflow-io-gcs-filesystem==0.37.1
tensorflow-metal==1.2.0
termcolor==2.5.0
tf_keras==2.18.0
toml==0.10.2
torch==2.6.0
torchvision==0.21.0
tornado==6.4.2
tqdm==4.67.1
typing_extensions==4.12.2
tzdata==2025.1
Unidecode==1.3.8
urllib3==2.3.0
Werkzeug==3.1.3
wrapt==1.17.2
......@@ -22,7 +22,7 @@ def visualize(frame, faces, fps, recognizer, ground_base_feature):
cosine_similarity_threshold = 0.363
l2_similarity_threshold = 1.128
cosine_score = recognizer.match(
face_feature,
ground_base_feature,
......@@ -76,7 +76,6 @@ def get_ground_base_feature(detector, recognizer):
return face_feature
def main():
detector = cv.FaceDetectorYN.create(
env["face_detection_model"],
......
......@@ -30,7 +30,7 @@ def create_dataset_embeddings() -> (np.ndarray, List):
for path in Path("task2_input/hse_faces_miem/").rglob("*.jpeg"):
path = str(path)
print(path)
image = np.array(Image.open(path))[:, :, ::-1]
image = np.array(Image.open(path))
try:
detections = get_image_embeddings(image)
......@@ -102,7 +102,7 @@ def main(index, ids):
np_image = np.asarray(
Image.open(uploaded_file)
)[:, :, ::-1]
)
detection = get_image_embeddings(np_image)[0]
......@@ -127,7 +127,8 @@ def main(index, ids):
detected_name,
)
st.markdown("""
st.markdown(
"""
<style>
.stButton>button {
width: 100%;
......
......@@ -69,7 +69,7 @@ def main():
if image is None:
break
result_image = image.copy()
np_image = np.asarray(image[:, :])[:, :, ::-1]
np_image = np.asarray(image[:, :])
print("Processing frame: ", current_frame_index)
frame_filename = os.path.join(video_output_dir, f"frame_{current_frame_index}.jpg")
......@@ -99,7 +99,7 @@ def main():
y2 = face["facial_area"]["h"] + y
try:
verified |= DeepFace.verify(person_path, np_image[y:y2, x:x2])["verified"]
verified = DeepFace.verify(person_path, np_image[y:y2, x:x2])["verified"]
except Exception as e:
print(f"Failed to verify person {person_path} with exception {e}")
if verified:
......
......@@ -2,7 +2,7 @@
Video: palmasizade_video.mp4
Labels: [[0, 12180, ['palmasizade']], [12210, 12270, ['palmasizade', 'vkrepker']], [12300, 18000, ['palmasizade']]]
Length: 17751
True Positives: 53
False Positives: 303
Precision: 0.14887640449438203
Correct Frames: [2700, 3000, 7600, 7650, 7700, 7750, 8400, 8500, 8950, 9100, 9200, 9250, 9300, 9350, 9400, 9450, 9500, 9550, 9600, 9650, 9700, 9750, 10200, 10400, 10450, 10700, 10950, 11000, 11200, 11250, 11350, 11400, 11450, 11500, 11550, 11600, 11900, 12250, 12300, 12350, 12400, 12450, 12600, 12650, 12800, 12850, 12900, 13700, 13900, 14350, 14800, 15500, 15550]
True Positives: 54
False Positives: 302
Precision: 0.15168539325842698
Correct Frames: [2700, 3000, 7600, 7650, 7700, 7750, 7800, 8000, 9100, 9150, 9200, 9250, 9300, 9400, 9450, 9500, 9550, 9600, 9650, 9700, 9750, 9800, 10400, 10450, 10700, 10950, 11000, 11200, 11250, 11350, 11400, 11450, 11500, 11550, 11600, 11700, 11900, 12250, 12300, 12350, 12400, 12450, 12600, 12800, 12850, 12900, 13700, 13800, 13900, 14350, 14800, 15500, 15550, 16650]
hw4/task3_2.py 0 → 100644
from deepface import DeepFace
import pandas as pd
import numpy as np
import cv2 as cv
import os
models = [
"VGG-Face",
"Facenet",
"Facenet512",
"OpenFace",
# "DeepFace",
"DeepID",
"ArcFace",
# "Dlib",
"SFace",
"GhostFaceNet"
]
results = {
"model": models,
"original": [],
"rotated_45": [],
"rotated_90": [],
"blurred": [],
"dark": [],
"bright": [],
"noisy": []
}
def augment_dataset():
dataset_folder = "./task3_2_input/dataset"
original_folder = os.path.join(dataset_folder, "original")
for filename in os.listdir(original_folder):
image_path = os.path.join(original_folder, filename)
image = cv.imread(image_path)
if image is not None:
print(f"Processing {filename}")
# Rotate 45 degrees
(h, w) = image.shape[:2]
center = (w // 2, h // 2)
M = cv.getRotationMatrix2D(center, 45, 1.0)
rotated_45 = cv.warpAffine(image, M, (w, h))
os.makedirs(os.path.join(dataset_folder, "rotated_45"), exist_ok=True)
rotated_45_path = os.path.join(
dataset_folder,
"rotated_45",
f"{os.path.splitext(filename)[0]}_rotated_45{os.path.splitext(filename)[1]}"
)
cv.imwrite(rotated_45_path, rotated_45)
# Rotate 90 degrees
rotated_90 = cv.rotate(image, cv.ROTATE_90_CLOCKWISE)
os.makedirs(os.path.join(dataset_folder, "rotated_90"), exist_ok=True)
rotated_90_path = os.path.join(
dataset_folder,
"rotated_90",
f"{os.path.splitext(filename)[0]}_rotated_90{os.path.splitext(filename)[1]}"
)
cv.imwrite(rotated_90_path, rotated_90)
# Blur
blurred = cv.GaussianBlur(image, (15, 15), 0)
os.makedirs(os.path.join(dataset_folder, "blurred"), exist_ok=True)
blurred_path = os.path.join(
dataset_folder,
"blurred",
f"{os.path.splitext(filename)[0]}_blurred{os.path.splitext(filename)[1]}"
)
cv.imwrite(blurred_path, blurred)
# Brightness
# Decrease brightness by 50%
dark = cv.convertScaleAbs(image, alpha=0.5, beta=0)
os.makedirs(os.path.join(dataset_folder, "dark"), exist_ok=True)
dark_path = os.path.join(
dataset_folder,
"dark",
f"{os.path.splitext(filename)[0]}_dark{os.path.splitext(filename)[1]}"
)
cv.imwrite(dark_path, dark)
# Increase brightness by 50%
bright = cv.convertScaleAbs(image, alpha=1.5, beta=0)
os.makedirs(os.path.join(dataset_folder, "bright"), exist_ok=True)
bright_path = os.path.join(
dataset_folder,
"bright",
f"{os.path.splitext(filename)[0]}_bright{os.path.splitext(filename)[1]}"
)
cv.imwrite(bright_path, bright)
# Add noise
noise = image.copy()
mean = 0
sigma = 25
gauss = np.random.normal(mean, sigma, noise.shape).astype("uint8")
noisy_image = cv.add(noise, gauss)
os.makedirs(os.path.join(dataset_folder, "noisy"), exist_ok=True)
noisy_path = os.path.join(
dataset_folder,
"noisy",
f"{os.path.splitext(filename)[0]}_noisy{os.path.splitext(filename)[1]}"
)
cv.imwrite(noisy_path, noisy_image)
else:
print(f"Failed to load {filename}")
def main():
# augment_dataset()
for model in models:
print("==================================")
print(f"Processing model {model}")
for dataset in list(results.keys())[1:]:
detection = DeepFace.find(
img_path="task3_2_input/egor.jpg",
db_path=f"task3_2_input/dataset/{dataset}",
model_name=model,
enforce_detection=False
)
recall = float(len(detection[0])) / 20.0
results[dataset].append(recall)
print(len(detection[0]))
print()
table = pd.DataFrame(results)
print(table)
table.to_csv("task3_2_output/results.txt", index=False)
if __name__ == "__main__":
main()
model,original,rotated_45,rotated_90,blurred,dark,bright,noisy
VGG-Face,0.4,0.05,0.05,0.25,0.5,0.4,0.0
Facenet,0.1,0.0,0.05,0.05,0.0,0.1,0.0
Facenet512,0.0,0.0,0.05,0.0,0.0,0.0,0.0
OpenFace,0.0,0.0,0.0,0.0,0.1,0.0,0.0
DeepID,0.1,0.05,0.0,0.05,0.0,0.1,0.05
ArcFace,0.6,0.0,0.05,0.35,0.6,0.5,0.0
SFace,0.4,0.0,0.05,0.2,0.45,0.35,0.0
GhostFaceNet,0.25,0.0,0.05,0.1,0.15,0.2,0.0
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment