-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
Use CUPY instead of Tensorflow to count GPUs #505
base: experimental
Are you sure you want to change the base?
Conversation
Revert "Enable to choose a camera device in UI" Will put it on experimental as of this moment
… install requirements. Now the code is working. You are able to run it on your Windows machine.
Fix this cyclic dependency issue which was coming while installing rquirements
Fixed a typo.
Update README.md
relinking this to the old repo
Nothing we say is legally binding in here, but it behooves us to be stronger in our language - getting consent to be digitally reproduced should be required and standard procedure.
Grammar updates Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
…-optimisation macOS optimisations for Silicon Macs for GPU / Metal usage (reduced CPU load from 600% to 150%)
…ew-is-closed Stop live mode when the preview window is closed
hides NSFW button
To fix bugs and support more options for the Live function (see details in Commits tab)
This reverts commit eab5ba7.
Hides NSFW
This reverts commit 9d20e04.
…imental" This reverts commit df99f6c.
Update README.md to address the issue with the GTK package on MAC OS
@refer to the PR hacksider#237 in the `experimental` branch. Signed-off-by: Vic P <[email protected]>
Signed-off-by: Vic P <[email protected]>
Re-enabled the NSFW function (turn-off by default) with its bug fixes at PR hacksider#237.
- The live camera display as you see it in the front-facing camera frame (like iPhone's Mirror Front Camera). - The live camera frame is resizable. Note: These options are turned off by default. Enabling both options may reduce performance by ~2%. Signed-off-by: Vic P <[email protected]>
Signed-off-by: Vic P <[email protected]>
@refer to the PR hacksider#293 in the `experimental` branch.
Disable NSFW in accordance to github rules
Adding a swap faces button to easily swap source/target images
Reviewer's Guide by SourceryThis pull request implements several changes to improve the functionality and user experience of the face swapping application. Key changes include adding NSFW filtering, enhancing the live preview feature, updating the UI, and improving performance. File-Level Changes
Tips
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @MYusufY - I've reviewed your changes - here's some feedback:
Overall Comments:
- Consider splitting this PR into smaller, more focused changes to make review and testing easier. The switch from TensorFlow to CuPy and the removal of camera selection are significant changes that warrant careful consideration.
- Some new features, like the NSFW filter, could benefit from more detailed documentation or code comments explaining their functionality.
Here's what I looked at during the review
- 🟡 General issues: 1 issue found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟡 Complexity: 1 issue found
- 🟡 Documentation: 2 issues found
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.
@@ -6,11 +6,14 @@ | |||
|
|||
MAX_PROBABILITY = 0.85 | |||
|
|||
# Preload the model once for efficiency |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Consider more encapsulated approach for model caching
The global caching of the NSFW model is a good optimization. However, consider using a more encapsulated approach, such as a singleton pattern or a module-level function that manages the model instance, to avoid potential issues with global state.
class NSFWModel:
_instance = None
@classmethod
def get_instance(cls):
if cls._instance is None:
cls._instance = cls._load_model()
return cls._instance
@staticmethod
def _load_model():
# Load and return the NSFW model
pass
@@ -33,6 +33,10 @@ We highly recommend to work with a `venv` to avoid issues. | |||
``` | |||
pip install -r requirements.txt | |||
``` | |||
For MAC OS, You have to install or upgrade python-tk package: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (documentation): Correct capitalization of macOS
The correct capitalization is 'macOS' instead of 'MAC OS'.
For MAC OS, You have to install or upgrade python-tk package: | |
For macOS, you have to install or upgrade the python-tk package: |
@@ -0,0 +1 @@ | |||
Please always push on the experimental to ensure we don't mess with the main branch. All the test will be done on the experimental and will be pushed to the main branch after few days of testing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (documentation): Consider expanding CONTRIBUTING.md
While this is a good start, consider expanding CONTRIBUTING.md with more detailed guidelines for potential contributors. This could include coding standards, pull request process, and how to report issues.
# Contributing Guidelines
## Branch Management
- Always push changes to the `experimental` branch.
- The `main` branch is protected for stability.
- All tests will be conducted on the `experimental` branch.
- Changes will be merged to `main` after thorough testing (typically a few days).
## Pull Request Process
1. Create a pull request from your feature branch to `experimental`.
2. Ensure all tests pass and code meets our standards.
3. Wait for review and address any feedback.
## Reporting Issues
- Use the GitHub Issues tab to report bugs or suggest enhancements.
- Provide a clear description and steps to reproduce if applicable.
|
||
def webcam_preview(camera_index: int): | ||
def webcam_preview(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (complexity): Consider refactoring the webcam_preview function into smaller, more focused functions.
The webcam_preview
function has become overly complex, handling multiple responsibilities including camera initialization, frame processing, UI updates, and virtual camera output. To improve maintainability and adhere to the Single Responsibility Principle, consider refactoring this function into smaller, more focused functions:
- Extract camera initialization:
def initialize_camera(width, height, fps):
camera = cv2.VideoCapture(0)
camera.set(cv2.CAP_PROP_FRAME_WIDTH, width)
camera.set(cv2.CAP_PROP_FRAME_HEIGHT, height)
camera.set(cv2.CAP_PROP_FPS, fps)
return camera
- Create a separate function for frame processing:
def process_frame(frame, source_image, frame_processors):
temp_frame = frame.copy()
if modules.globals.live_mirror:
temp_frame = cv2.flip(temp_frame, 1)
if modules.globals.live_resizable:
temp_frame = fit_image_to_size(temp_frame, PREVIEW.winfo_width(), PREVIEW.winfo_height())
for frame_processor in frame_processors:
temp_frame = frame_processor.process_frame(source_image, temp_frame)
return temp_frame
- Extract UI update logic:
def update_preview_ui(frame):
image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
image = Image.fromarray(image)
image = ImageOps.contain(image, (frame.shape[1], frame.shape[0]), Image.LANCZOS)
image = ctk.CTkImage(image, size=image.size)
preview_label.configure(image=image)
ROOT.update()
- Create a separate function for virtual camera output (if needed):
def output_to_virtual_camera(frame, virtual_cam):
virtual_cam.send(frame)
virtual_cam.sleep_until_next_frame()
Then, refactor the main webcam_preview
function to use these helper functions:
def webcam_preview():
if modules.globals.source_path is None:
return
camera = initialize_camera(PREVIEW_DEFAULT_WIDTH, PREVIEW_DEFAULT_HEIGHT, 60)
preview_label.configure(width=PREVIEW_DEFAULT_WIDTH, height=PREVIEW_DEFAULT_HEIGHT)
PREVIEW.deiconify()
frame_processors = get_frame_processors_modules(modules.globals.frame_processors)
source_image = get_one_face(cv2.imread(modules.globals.source_path)) if modules.globals.source_path else None
while camera:
ret, frame = camera.read()
if not ret:
break
processed_frame = process_frame(frame, source_image, frame_processors)
update_preview_ui(processed_frame)
if PREVIEW.state() == 'withdrawn':
break
camera.release()
PREVIEW.withdraw()
This refactoring separates concerns, making the code more modular and easier to maintain. Each function now has a single responsibility, improving readability and testability.
I thinks this solves |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
p
Summary by Sourcery
Replace TensorFlow with CuPy for GPU management, add new UI features including a swap faces button and live camera options, implement NSFW filtering, and update documentation with new features and contribution guidelines.
New Features:
Enhancements:
Documentation: