Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

models_update (update 1 of 2) #34

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

BlakkTyger
Copy link
Collaborator

@BlakkTyger BlakkTyger commented Nov 4, 2024

Edits Made

  • model weights added
  • face_recog feature added and integrated
  • structured functions and files in required format
  • requirements and gitignore updated

To-Do in update 2 of 2

  • create API endpoints for the 2 models
  • containerize the services

Summary by Sourcery

Add face recognition feature and integrate it into the system. Restructure codebase to meet required format and update dependencies in requirements.txt.

New Features:

  • Add face recognition feature using DeepFace library.

Enhancements:

  • Integrate face recognition feature into the existing system.
  • Restructure functions and files to adhere to the required format.

Build:

  • Update requirements.txt to include necessary dependencies for new features.

- model weights added
- face_recog feature added and integrated
- structured functions and files in required format
- requirements and gitignore updated
Copy link
Contributor

sourcery-ai bot commented Nov 4, 2024

Reviewer's Guide by Sourcery

This PR introduces face recognition capabilities and gesture classification functionality while restructuring the project. The implementation uses DeepFace for face recognition and MediaPipe for hand gesture detection, with model weights being added to support these features. The changes include proper file organization and necessary dependency updates.

ER diagram for updated requirements

erDiagram
    REQUIREMENTS {
        string numpy
        string pandas
        string matplotlib
        string scikit-learn
        string mediapipe
        string opencv-python
        string tf-keras
        string deepface
        string flask
    }
    note for REQUIREMENTS "Updated to include new dependencies for face recognition and gesture classification"
Loading

Class diagram for gesture classification and face recognition

classDiagram
    class gestureClassify {
        +detectGesture(img)
        +compare(detectOutput, gestureClass)
    }
    class faceRecog {
        +recog(img_1_path, img_2_path)
    }
    note for gestureClassify "Uses MediaPipe for hand gesture detection"
    note for faceRecog "Uses DeepFace for face recognition"
Loading

File-Level Changes

Change Details Files
Implement gesture classification functionality using MediaPipe and pre-trained models
  • Add function to detect and classify hand gestures from images using MediaPipe Hands
  • Implement gesture comparison functionality to validate detected gestures
  • Load model weights from a zip file for gesture classification
  • Process hand landmarks to generate feature vectors for classification
models/gestureClassify.py
Add face recognition feature using DeepFace library
  • Implement face comparison function using ArcFace model
  • Configure RetinaFace as the detector backend
  • Return boolean verification result for face matching
models/faceRecog.py
Update project configuration and dependencies
  • Add new Python package dependencies including ML libraries
  • Update dataset directory path configuration
  • Remove main.py as part of restructuring
requirements.txt
models/TrainData_preprocess.py
models/main.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @BlakkTyger - I've reviewed your changes - here's some feedback:

Overall Comments:

  • The model.zip extraction in gestureClassify.py happens on every function call, which is inefficient. Consider loading the model once during initialization.
  • There's a bug in the compare() function where a bare 'True' statement doesn't return anything. This needs to be fixed to return True when gestures match.
Here's what I looked at during the review
  • 🟡 General issues: 3 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

'''


with ZipFile("./model.zip", 'r') as zObject:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (performance): Consider caching the model instead of extracting it on every function call

Repeatedly extracting the zip file for each detection will cause significant performance overhead. Consider loading the model once at module level or implementing a caching mechanism.

MODEL_ZIP = ZipFile("./model.zip", 'r')

def __init__(self):
    self.model_object = MODEL_ZIP

if detectOutput == 1:
return False, 'Gesture Not Inferred'
else:
if detectOutput == gestureClass:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Missing return statement in the True case

The function will fall through to return False even when the gestures match. Add 'return True' here.


Parameters:
img_1_path: path of image to be checked
imt_2_path: path of original image
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick (typo): Fix typo in parameter name in docstring

'imt_2_path' should be 'img_2_path'

from zipfile import ZipFile


def detectGesture(img):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (complexity): Consider refactoring model loading and return patterns to reduce redundant operations

Two suggestions to reduce complexity while maintaining functionality:

  1. Move model loading to module level to avoid repeated ZIP operations:
# At module level
_model = None

def _load_model():
    global _model
    if _model is None:
        with ZipFile("./model.zip", 'r') as zObject:
            zObject.extract("model.p", path="./")
        _model = pickle.load(open('./model.p', 'rb'))['model']
    return _model

# In detectGesture(), replace model loading with:
model = _load_model()
  1. Simplify compare() with consistent return types:
def compare(detectOutput, gestureClass):
    if detectOutput == 0:
        return False, 'Hand Not Detected'
    if detectOutput == 1:
        return False, 'Gesture Not Inferred'
    return (detectOutput == gestureClass, 
            'Correct Gesture' if detectOutput == gestureClass else 'Incorrect Gesture')

These changes improve performance by loading the model once and make the code more maintainable with consistent return patterns.

Copy link
Contributor

sourcery-ai bot commented Nov 4, 2024

🧙 Sourcery is reviewing your pull request!


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have skipped reviewing this pull request. It looks like we've already reviewed the commit 0ccef39 in this pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant