Skip to content

Commit 72aa2b8

Browse files
authored
Merge pull request #58 from pozitronik/issue_48
Issue 48
2 parents e196111 + f2da8b2 commit 72aa2b8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+1277
-481
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ jobs:
1414
python-version: 3.11
1515
- run: pip install flake8
1616
- run: pip install mypy
17-
- run: flake8 run.py sinner
18-
- run: mypy --config-file mypy.ini run.py sinner
17+
- run: flake8 sin.py sinner
18+
- run: mypy --config-file mypy.ini sin.py sinner
1919
tests:
2020
runs-on: ubuntu-latest
2121
steps:
@@ -28,5 +28,8 @@ jobs:
2828
with:
2929
python-version: 3.11
3030
- run: pip install -r requirements-ci.txt
31+
- run: |
32+
export DISPLAY=:1:0
33+
Xvfb :1 -screen 0 1600x1200x16 &
3134
- run: pytest -m "not skip"
3235

README.md

Lines changed: 35 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -22,49 +22,20 @@ The tasks that I aim to accomplish here are:
2222
## How do I install it?
2323

2424
The basic installation instructions for now are the same as those in the [s0md3v/roop](https://github.com/s0md3v/roop#how-do-i-install-it), check them out.
25-
In short, you need to install python 3.9 or a later version, VC runtimes, and desired Execution Provider kit (depending on your hardware and OS).
25+
In short, you need to install python 3.10 or a later version, VC runtimes, and desired Execution Provider kit (depending on your hardware and OS).
26+
Then you need to install required python packages by running `pip install -r requirements.txt`. Installation result may vary, depending on your system, but in the most cases it should be installed successfully. Otherwise, get a look to the command output, usually you may fix minor issues (like version requirements change) by yourself.
27+
28+
If nothing helps, feel free to create an issue with your problem, we will try to figure it out.
2629

2730
## How do I use it?
2831

29-
Go to application folder and run `python run.py` with desired set of command-line parameters (or just pick one of the [example](#command-line-usage-examples) and make changes to suit your need).
30-
31-
Here is the list of all possible command-line parameters.
32-
* `--source`: the image file containing a face, which will be used for deepfake magic.
33-
* `--target`: an image, a video file, or a directory with PNG images for processing.
34-
* `--output`: a path (either a file or a directory) to save the processing result. If not provided, the resulting file will be saved near the target with an automatically generated filename.
35-
* `--frame-processor`: the frame processor module or modules that you want to apply to your files. See the [built-in frame processors](#built-in-frame-processors) section for the list of built-in modules and their possibilities.
36-
* `--frame-handler`: a module to handle the `target`. In the most cases, you should omit that parameter (sinner will figure it out itself).
37-
* `--fps`: the parameter to set the frames per second (FPS) in the resulting video. If not provided, the resulting video's FPS will be the same as the `target`'s video (or 30, if an image directory is used as the `target`).
38-
* `--keep-audio`: defaults to `true`. Keeps the original audio in the resulting video.
39-
* `--keep-frames`: defaults to `false`. Keeps processed frames in the `temp-dir` after finishing.
40-
* `--many-faces`: defaults to `false`. If set to true, every frame processor in the processing chain will apply its magic to every face on every frame of the `target`. If set to `false`, only one face (the first one found, no heavy logic here) will be processed.
41-
* `--max-memory`: defaults to `4` for Mac and `16` for any other platforms. The maximum amount of gigabytes of RAM that will be allowed for sinner use.
42-
**Note 1**: AI processing usually requires a significant amount of RAM. While processing, you will see the memory usage statistics, and the `MEM LIMIT REACHED` statistics indicate a lack of RAM.
43-
**Note 2**: This parameter does not affect the amount of used video RAM if a GPU-accelerated `execution-provider` is used.
44-
* `--execution-provider`: defaults to `cpu`. This parameter specifies what kind of driver should be used to produce AI magic, and it depends on what your hardware and software capabilities. The `cpu` provider should fit as a basic choice, but any GPU-accelerated option is worth trying.
45-
* `--execution-threads`: defaults to `1`. Configures the count of parallel simultaneous processing tasks. This value heavily depends on your hardware capabilities — how many computing cores it has, and what amount of memory it can use. Let's say, you have a CPU with 32 cores — so you can set `--execution-threads=32` and `--execution-provider=cpu` to use all its computing powers. In another case, a GPU with thousands of CUDA cores, will probably be much faster in total, but one thread will also require a lot of those cores to work with. For that case, I recommend doing some experiments, or waiting until the benchmark mode is implemented in sinner.
46-
* `--extract-frames`: defaults to `false`. If set to true, all frames from the `target` will be extracted to a temporary folder as a sequence of PNG files right before processing. If set to false, every frame will be extracted to a memory only by a processor module's request. The first way requires some disk space for temporary frames, the second way might be a little slower in some cases.
47-
* `--temp-dir`: defaults to the `temp` subdirectory in the application directory. A way to provide a directory, where processed (and, in the case of `--in-memory=false`, extracted too) frames will be saved.
48-
* `--benchmark`: runs a benchmark on a selected `frame-processor` to determine the optimal value for the execution-threads parameter. Additionally, you can specify the `--execution-provider` parameter to choose a specific execution provider (if not provided, all available providers will be tried in sequence). Furthermore, you have the option to specify the `--source` and `--target` parameters to use custom files during the benchmark (if not provided, default test files will be used).
49-
* `--gui`: starts in GUI mode (experimental).
50-
51-
**FrameResizer:**
52-
* `--scale`: Scales output frames to certain float value. Example: `--scale=0.5` will halve frame in both size and `--scale=2` will zoom it twice.
53-
* `--height`: Set output frames height to this integer value, the width also will be scaled proportional.
54-
* `--width`: Set output frames width to this integer value, the height also will be scaled proportional.
55-
* `--height-max`: Set output frames height to this integer value, but only if current frame height is greater. The width also will be scaled proportional.
56-
* `--width-max`: Set output frames width to this integer value, but only if current frame width is greater. The width also will be scaled proportional.
57-
* `--height-max`: Set output frames height to this integer value, but only if current frame height is smaller. The width also will be scaled proportional.
58-
* `--width-max`: Set output frames width to this integer value, but only if current frame width is smaller. The width also will be scaled proportional.
59-
**Note**: The size keys priority is: all `height` keys will be used in the first place; if they skipped, then all `width` keys will be used; and if no `height` or `width` keys are provided, then `scale` key is used.
60-
61-
**FaceEnhancer:**
62-
* `--upscale`: Scales output frames to certain float value. Example: `--scale=0.5` will halve frame in both size and `--scale=2` will zoom it twice.
63-
**Note**: You can combine this parameter with `FrameResizer` scaling possibilities. As example:
64-
```cmd
65-
python run.py --target="d:\videos\not_a_porn.mp4" --frame-processor FrameResizer FaceEnhancer --output="d:\results\result.mp4" --scale=0.5 --upscale=2
66-
```
67-
Thus, all frames will be halved before enhancing, and restored to original size with FaceEnhancer with its magic. The profit is that the processing of smaller frames can be faster.
32+
Go to application folder and run `python sin.py` with desired set of command-line parameters (or just pick one of [examples](#command-line-usage-examples) and make changes to suit your need).
33+
34+
You can get the list of all available command-line parameters by running the program with `--h` or `--help` keys. Those commands will list all configurable modules and their supported parameters.
35+
1
36+
Some modules may have the same parameters. It is okay: those parameters (and its values) are shared. It is also okay, if parameters expected values are different between modules: usually, they will be harmonized in runtime. But if something goes wrong, you will get an explicit error message.
37+
38+
Also, you can read about modules parameters [here](/docs/modules.md)
6839

6940
## Built-in frame processors
7041

@@ -74,26 +45,47 @@ you want to use, and provide them with some sources to work on. Here is the list
7445
![FaceSwapper demo](/demos/swapper-demo.gif)
7546
- `FaceEnhancer`: performs face restoration and enhances the quality of the `target`. The processor is based on the libraries of the [ARC Lab GFPGAN project](https://github.com/TencentARC/GFPGAN).
7647
![FaceEnhancer demo](/demos/enhancer-demo.jpg)
48+
- `FrameExtractor`: use this processor in the processing chain when using video file as the target to force sinner extract frames to a temporary folder as a sequence of PNG files. If not used, every frame will be extracted into the memory by a processor module's request. The first way requires some disk space for temporary frames, the second way might be a little slower in some cases.
7749
- `FrameResizer`: resizes frames to certain size.
7850
- `DummyProcessor`: literally does nothing; it is just a test tool.
7951

8052
## Command line usage examples
8153

8254
```cmd
83-
python run.py --source="d:\pictures\cool_photo.jpg" --target="d:\pictures\other_cool_photo.jpg" --frame-processor=FaceSwapper
55+
python sin.py --source="d:\pictures\cool_photo.jpg" --target="d:\pictures\other_cool_photo.jpg" --frame-processor=FaceSwapper
8456
```
8557
Swap one face on the `d:\pictures\other_cool_photo.jpg` picture to face from the `d:\pictures\cool_photo.jpg` picture and save resulting image to `d:\pictures\cool_photo_other_cool_photo.png` (autogenerated name).
8658
```cmd
87-
python run.py --source="d:\pictures\cool_photo.jpg" --target="d:\videos\not_a_porn.mp4" --frame-processor FaceSwapper FaceEnhancer --output="d:\results\result.mp4" --many-faces --execution-provider=cuda
59+
python sin.py --source="d:\pictures\cool_photo.jpg" --target="d:\videos\not_a_porn.mp4" --frame-processor FaceSwapper FaceEnhancer --output="d:\results\result.mp4" --many-faces --execution-provider=cuda
8860
```
8961
Swap all faces on the `d:\videos\not_a_porn.mp4` video file to the face from `d:\pictures\cool_photo.jpg` and enhance all faces quality, both processing will be made using the `cuda` provider, and result will be saved to the `d:\results\result.mp4`.
9062
```cmd
91-
python run.py --source="d:\pictures\any_picture.jpg" --target="d:\pictures\pngs_dir" --output="d:\pictures\pngs_dir\enhanced" --frame-processor=FaceEnhancer --many-faces --max-memory=24 --execution-provider=cuda --execution-threads=8
63+
python sin.py --source="d:\pictures\any_picture.jpg" --target="d:\pictures\pngs_dir" --output="d:\pictures\pngs_dir\enhanced" --frame-processor=FaceEnhancer --many-faces --max-memory=24 --execution-provider=cuda --execution-threads=8
9264
```
9365
Enhance all faces in every PNG file in the `d:\pictures\pngs_dir` directory using the `cuda` provider and 8 simultaneous execution threads, with limit of 24 Gb RAM, and save every enhanced image to the `d:\pictures\pngs_dir\enhanced` directory.<br/>
9466
**Note 1**: only PNG images are supported at the moment.<br/>
9567
**Note 2**: even if the selected frame processor does not require a `source`, you should provide one at this time.
9668

69+
## Configuration file
70+
71+
You can store commonly used options in the configuration file, to make them apply on every run by default. Just edit `sinner.ini` file in the application directory and add desired parameters inside the `[sinner]` section as key-value pairs.
72+
73+
Example:
74+
```ini
75+
[sinner]
76+
keep-frames=1
77+
many-faces=1
78+
execution-provider=gpu
79+
execution-threads=2
80+
```
81+
82+
Any parameter set from command line will override corresponding parameter from the ini file.
83+
84+
You also can pass path to the custom configuration file as a command line parameter:
85+
```cmd
86+
python sin.py --ini="d:\path\custom.ini"
87+
```
88+
9789
## FAQ
9890

9991
:question: What are the differences between sinner and roop?<br/>

conftest.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import os
2+
3+
4+
def pytest_sessionstart(session):
5+
# try to avoid tkl initialization errors while testing in GitHub CI
6+
if 'CI' in os.environ and 'DISPLAY' not in os.environ:
7+
os.environ.__setitem__('DISPLAY', ':1.0')

0 commit comments

Comments
 (0)