-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Amr-YA
committed
Nov 13, 2022
1 parent
0122535
commit 4fa8d2b
Showing
7 changed files
with
683 additions
and
683 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
FROM python:3.9 | ||
|
||
WORKDIR /app | ||
COPY ./requirements.txt . | ||
RUN pip install --upgrade pip | ||
RUN pip install -U wheel cmake | ||
RUN apt-get update && apt-get install -y python3-opencv | ||
RUN pip install opencv-python | ||
RUN pip install -r requirements.txt | ||
|
||
COPY . . | ||
|
||
EXPOSE 5005 | ||
USER 1001 | ||
|
||
CMD ["python", "./face_rec_code/app.py"] | ||
FROM python:3.9 | ||
|
||
WORKDIR /app | ||
COPY ./requirements.txt . | ||
RUN pip install --upgrade pip | ||
RUN pip install -U wheel cmake | ||
RUN apt-get update && apt-get install -y python3-opencv | ||
RUN pip install opencv-python | ||
RUN pip install -r requirements.txt | ||
|
||
COPY . . | ||
|
||
EXPOSE 5005 | ||
USER 1001 | ||
|
||
CMD ["python", "./face_rec_code/app.py"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,26 @@ | ||
# Changelog | ||
|
||
## 25-Sep-22 - git:feature-start_end | ||
1. added `video_face_rec.py/faces_split_timestamps` return value for all the enteries a faces appears | ||
2. added `video_face_rec.py/refine_results` to remove single frames faces from enteries return, but not activated in 1st appearance return | ||
3. fixed `timestamp` = 0 by the end of the video | ||
4. fixed `target_fps` having value less than 1 which resulted in corrupted video output | ||
|
||
## 24-Sep-22 - git:feature-custm_analysis | ||
1. restructured the files into folders | ||
- `/face_rec_code/`: for all the python code | ||
- `/face_rec_files/`: for the videos and pictures | ||
2. split the code into 2 python files | ||
- `face_rec_code/video_face_rec.py` for loading the folder and files then the analysis code | ||
- `face_rec_code/app.py` for running the flask server | ||
3. output unknown persons photos and labeled video are saved inside a folder by the name of the video inside `./unknown/` | ||
4. changed `video_face_rec.py/run` to `video_face_rec.py/pipeline` with default parameters in case no parameters passed | ||
5. added 2 `app.py/run` methods in the server | ||
- `app.py/run_defaults` - GET: uses the `video_face_rec.py/pipeline` with default parameters, doesn't take any arguments | ||
- `app.py/run_custom` - POST: uses the `video_face_rec.py/pipeline` with customs parameters, takes the parameters from json object from the post request | ||
6. enhanced the `video_face_rec.py/confirm_dirs` to check all the directories and files are correct | ||
7. added `video_face_rec.py/fetch_video_full_dir` to get the video for the analysis (either from default or custom run) | ||
8. added tolerance parameter in the analysis | ||
9. moved code for saving photos and video to seperate functions `video_face_rec.py/save_photo` & `video_face_rec.py/save_video` | ||
10. changed the flask server running to more stable `app.py/WSGIServer` | ||
# Changelog | ||
|
||
## 25-Sep-22 - git:feature-start_end | ||
1. added `video_face_rec.py/faces_split_timestamps` return value for all the enteries a faces appears | ||
2. added `video_face_rec.py/refine_results` to remove single frames faces from enteries return, but not activated in 1st appearance return | ||
3. fixed `timestamp` = 0 by the end of the video | ||
4. fixed `target_fps` having value less than 1 which resulted in corrupted video output | ||
|
||
## 24-Sep-22 - git:feature-custm_analysis | ||
1. restructured the files into folders | ||
- `/face_rec_code/`: for all the python code | ||
- `/face_rec_files/`: for the videos and pictures | ||
2. split the code into 2 python files | ||
- `face_rec_code/video_face_rec.py` for loading the folder and files then the analysis code | ||
- `face_rec_code/app.py` for running the flask server | ||
3. output unknown persons photos and labeled video are saved inside a folder by the name of the video inside `./unknown/` | ||
4. changed `video_face_rec.py/run` to `video_face_rec.py/pipeline` with default parameters in case no parameters passed | ||
5. added 2 `app.py/run` methods in the server | ||
- `app.py/run_defaults` - GET: uses the `video_face_rec.py/pipeline` with default parameters, doesn't take any arguments | ||
- `app.py/run_custom` - POST: uses the `video_face_rec.py/pipeline` with customs parameters, takes the parameters from json object from the post request | ||
6. enhanced the `video_face_rec.py/confirm_dirs` to check all the directories and files are correct | ||
7. added `video_face_rec.py/fetch_video_full_dir` to get the video for the analysis (either from default or custom run) | ||
8. added tolerance parameter in the analysis | ||
9. moved code for saving photos and video to seperate functions `video_face_rec.py/save_photo` & `video_face_rec.py/save_video` | ||
10. changed the flask server running to more stable `app.py/WSGIServer` | ||
11. analysis terminal prints are now in minutes & seconds, ex:"time: 0m:25s - Found 1 faces, recognized: Unknown" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,104 +1,104 @@ | ||
import os | ||
from flask import Flask, request, jsonify | ||
import dlib | ||
from gevent.pywsgi import WSGIServer | ||
from video_face_rec import confirm_dirs, pipeline | ||
|
||
import warnings | ||
warnings.simplefilter("ignore") | ||
|
||
app = Flask(__name__) | ||
app.config['JSON_SORT_KEYS'] = False | ||
APP_DIR = os.path.dirname(__file__) | ||
DOCKER_DIR = os.path.dirname(APP_DIR) | ||
|
||
|
||
@app.route("/healthcheck", methods=["GET"]) | ||
def healthcheck(): | ||
status, _, _, _, _, msg = confirm_dirs(DOCKER_DIR) | ||
if status: | ||
status_code = 200 | ||
else: | ||
status_code = 425 # error in healthcheck | ||
obj = {"status": msg} | ||
return jsonify(obj), status_code | ||
|
||
@app.route("/run_defaults", methods=["GET"]) | ||
def run_defaults(): | ||
print("-----default analysis running") | ||
obj, status_code = pipeline() | ||
return jsonify(obj), status_code | ||
|
||
@app.route("/run_custom", methods=["POST"]) | ||
def run_custom(): | ||
print("-----custom analysis running") | ||
|
||
try: | ||
file_name = request.json["file_name"] | ||
print("-----file name found in request: ", file_name) | ||
except: | ||
file_name = None | ||
print("-----file name not found in request") | ||
|
||
try: | ||
model = request.json["model"] | ||
print("-----model found in request: ", model) | ||
except: | ||
model = 'hog' | ||
print("-----model name not found in request") | ||
|
||
try: | ||
skip_frames = request.json["skip_frames"] | ||
print("-----skip_frames found in request: ", skip_frames) | ||
except: | ||
skip_frames = 5 | ||
print("-----skip_frames not found in request") | ||
|
||
try: | ||
resiz_factor = request.json["resiz_factor"] | ||
print("-----resiz_factor found in request: ", resiz_factor) | ||
except: | ||
resiz_factor = 1 | ||
print("-----resiz_factor not found in request") | ||
|
||
try: | ||
n_upscale = request.json["n_upscale"] | ||
print("-----n_upscale found in request: ", n_upscale) | ||
except: | ||
n_upscale = 1 | ||
print("-----n_upscale not found in request") | ||
|
||
try: | ||
num_jitters = request.json["num_jitters"] | ||
print("-----num_jitters found in request: ", num_jitters) | ||
except: | ||
num_jitters = 1 | ||
print("-----num_jitters not found in request") | ||
|
||
try: | ||
tolerance = request.json["tolerance"] | ||
print("-----tolerance found in request: ", tolerance) | ||
except: | ||
tolerance = 0.6 | ||
print("-----tolerance not found in request") | ||
|
||
obj, status_code = pipeline(video_name=file_name, model=model, skip_frames=skip_frames, resiz_factor=resiz_factor, n_upscale=n_upscale, num_jitters=num_jitters, tolerance=tolerance) | ||
return jsonify(obj), status_code | ||
|
||
|
||
|
||
if __name__ == "__main__": | ||
print("-----working on: ",DOCKER_DIR) | ||
try: | ||
cuda = dlib.DLIB_USE_CUDA | ||
if cuda: | ||
print("-----running on GPU") | ||
else: | ||
print("-----running on CPU") | ||
except: | ||
print("-----couldnn't detect CUDA") | ||
|
||
# app.run(debug=True, host="0.0.0.0", port="3000") | ||
|
||
http_server = WSGIServer(('', 3000), app) | ||
http_server.serve_forever() | ||
import os | ||
from flask import Flask, request, jsonify | ||
import dlib | ||
from gevent.pywsgi import WSGIServer | ||
from video_face_rec import confirm_dirs, pipeline | ||
|
||
import warnings | ||
warnings.simplefilter("ignore") | ||
|
||
app = Flask(__name__) | ||
app.config['JSON_SORT_KEYS'] = False | ||
APP_DIR = os.path.dirname(__file__) | ||
DOCKER_DIR = os.path.dirname(APP_DIR) | ||
|
||
|
||
@app.route("/healthcheck", methods=["GET"]) | ||
def healthcheck(): | ||
status, _, _, _, _, msg = confirm_dirs(DOCKER_DIR) | ||
if status: | ||
status_code = 200 | ||
else: | ||
status_code = 425 # error in healthcheck | ||
obj = {"status": msg} | ||
return jsonify(obj), status_code | ||
|
||
@app.route("/run_defaults", methods=["GET"]) | ||
def run_defaults(): | ||
print("-----default analysis running") | ||
obj, status_code = pipeline() | ||
return jsonify(obj), status_code | ||
|
||
@app.route("/run_custom", methods=["POST"]) | ||
def run_custom(): | ||
print("-----custom analysis running") | ||
|
||
try: | ||
file_name = request.json["file_name"] | ||
print("-----file name found in request: ", file_name) | ||
except: | ||
file_name = None | ||
print("-----file name not found in request") | ||
|
||
try: | ||
model = request.json["model"] | ||
print("-----model found in request: ", model) | ||
except: | ||
model = 'hog' | ||
print("-----model name not found in request") | ||
|
||
try: | ||
skip_frames = request.json["skip_frames"] | ||
print("-----skip_frames found in request: ", skip_frames) | ||
except: | ||
skip_frames = 5 | ||
print("-----skip_frames not found in request") | ||
|
||
try: | ||
resiz_factor = request.json["resiz_factor"] | ||
print("-----resiz_factor found in request: ", resiz_factor) | ||
except: | ||
resiz_factor = 1 | ||
print("-----resiz_factor not found in request") | ||
|
||
try: | ||
n_upscale = request.json["n_upscale"] | ||
print("-----n_upscale found in request: ", n_upscale) | ||
except: | ||
n_upscale = 1 | ||
print("-----n_upscale not found in request") | ||
|
||
try: | ||
num_jitters = request.json["num_jitters"] | ||
print("-----num_jitters found in request: ", num_jitters) | ||
except: | ||
num_jitters = 1 | ||
print("-----num_jitters not found in request") | ||
|
||
try: | ||
tolerance = request.json["tolerance"] | ||
print("-----tolerance found in request: ", tolerance) | ||
except: | ||
tolerance = 0.6 | ||
print("-----tolerance not found in request") | ||
|
||
obj, status_code = pipeline(video_name=file_name, model=model, skip_frames=skip_frames, resiz_factor=resiz_factor, n_upscale=n_upscale, num_jitters=num_jitters, tolerance=tolerance) | ||
return jsonify(obj), status_code | ||
|
||
|
||
|
||
if __name__ == "__main__": | ||
print("-----working on: ",DOCKER_DIR) | ||
try: | ||
cuda = dlib.DLIB_USE_CUDA | ||
if cuda: | ||
print("-----running on GPU") | ||
else: | ||
print("-----running on CPU") | ||
except: | ||
print("-----couldnn't detect CUDA") | ||
|
||
# app.run(debug=True, host="0.0.0.0", port="3000") | ||
|
||
http_server = WSGIServer(('', 3000), app) | ||
http_server.serve_forever() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
import requests | ||
|
||
# test the server requests | ||
port = "3000" | ||
post_obj = { | ||
"file_name": "3.mp4", | ||
# "model": "hog", | ||
"skip_frames": 30, | ||
# "resiz_factor": 1, | ||
# "num_jitters": 1, | ||
# "tolerance": 0.6, | ||
} | ||
# method = "run_defaults" | ||
method = "run_custom" | ||
host = f'http://localhost:{port}/{method}' | ||
r = requests.post(host, json=post_obj) | ||
# r = requests.get(host) | ||
|
||
|
||
print(r.status_code) | ||
print(r.text) | ||
import requests | ||
|
||
# test the server requests | ||
port = "3000" | ||
post_obj = { | ||
"file_name": "3.mp4", | ||
# "model": "hog", | ||
"skip_frames": 30, | ||
# "resiz_factor": 1, | ||
# "num_jitters": 1, | ||
# "tolerance": 0.6, | ||
} | ||
# method = "run_defaults" | ||
method = "run_custom" | ||
host = f'http://localhost:{port}/{method}' | ||
r = requests.post(host, json=post_obj) | ||
# r = requests.get(host) | ||
|
||
|
||
print(r.status_code) | ||
print(r.text) |
Oops, something went wrong.