Skip to content

Commit 1bb82a5

Browse files
Merge branch 'dev'
2 parents 391a5f9 + c5c4328 commit 1bb82a5

25 files changed

+1801
-74
lines changed

.coveragerc

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
[run]
2+
source = .
3+
omit =
4+
*/venv/*
5+
*/tests/*
6+
*/examples/*
7+
*/unit_tests/*
8+
*/CodeFormer/*
9+
*/__pycache__/*
10+
*/site-packages/*
11+
config*.py
12+
13+
[report]
14+
exclude_lines =
15+
pragma: no cover
16+
def __repr__
17+
raise AssertionError
18+
raise NotImplementedError
19+
if __name__ == .__main__.:
20+
if TYPE_CHECKING:
21+
@abstractmethod
22+
except Exception as error:
23+
raise
24+
def __repr__
25+
raise AssertionError
26+
raise NotImplementedError
27+
if __name__ == .__main__.:
28+
if TYPE_CHECKING:
29+
@abstractmethod
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Filter small faces using min_face_size parameter
2+
3+
## Overview
4+
5+
The `min_face_size` parameter allows you to filter out faces smaller than a specified percentage of the image's minimum dimension (width or height). This is useful when you want to target only prominent faces in the image and ignore smaller background faces.
6+
7+
## How it works
8+
9+
- `min_face_size` is specified as a percentage (0-100)
10+
- The filter compares each detected face's bounding box dimensions against the threshold
11+
- Faces with width OR height smaller than the threshold are excluded
12+
- The threshold is calculated as: `min_dimension * (min_face_size / 100)`
13+
- Where `min_dimension` is the smaller of the image's width or height
14+
15+
## Example Use Case
16+
17+
In an image with Harry Potter in the foreground (large face) and background characters with smaller faces, setting `min_face_size: 30` will filter out the smaller background faces, allowing you to target only Harry Potter's face.
18+
19+
## Request
20+
21+
In this example, setting `min_face_size` to `30` means faces must be at least 30% of the image's minimum dimension. This filters out small background faces and only processes the main face in the image.
22+
23+
```json
24+
{
25+
"input": {
26+
"source_image": "base64 encoded source image content",
27+
"target_image": "base64 encoded target image content",
28+
"source_indexes": "-1",
29+
"target_indexes": "-1",
30+
"background_enhance": true,
31+
"face_restore": true,
32+
"face_upsample": true,
33+
"upscale": 1,
34+
"codeformer_fidelity": 0.5,
35+
"output_format": "JPEG",
36+
"min_face_size": 30
37+
}
38+
}
39+
```
40+
41+
## Common Values
42+
43+
- `0` (default): No filtering, all detected faces are processed
44+
- `10-20`: Filter very small faces (distant background faces)
45+
- `20-30`: Filter small to medium faces (background characters)
46+
- `30-50`: Only process large, prominent faces (main subjects)
47+
- `50+`: Only process very large faces (close-up portraits)
48+
49+
## Response
50+
51+
### RUN
52+
53+
```json
54+
{
55+
"id": "83bbc301-5dcd-4236-9293-a65cdd681858",
56+
"status": "IN_QUEUE"
57+
}
58+
```
59+
60+
### RUNSYNC
61+
62+
```json
63+
{
64+
"delayTime": 20275,
65+
"executionTime": 43997,
66+
"id": "sync-a3b54383-e671-4e24-a7bd-c5fec16fda3b",
67+
"output": {
68+
"status": "ok",
69+
"image": "base64 encoded output image"
70+
},
71+
"status": "COMPLETED"
72+
}
73+
```

docs/testing/local.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ python3 -u handler.py --rp_serve_api
2828
```
2929

3030
**NOTE:** You need to keep the RunPod Handler API running in order to
31-
run the tests, so open a new terminal window to run the tests.
31+
run the examples, so open a new terminal window to run the examples.
3232

3333
## Set your test data files
3434

3535
You can either overwrite the images in the `data` directory with your
3636
own source and target files, or alternatively, you can edit the
37-
scripts in the `tests` directory to reference the source and target
37+
scripts in the `examples` directory to reference the source and target
3838
images somewhere else on your system.
3939

4040
## Remove credentials from .env
@@ -44,23 +44,24 @@ If you have added your `RUNPOD_API_KEY` and
4444
this directory, you should first comment them
4545
out before attempting to test locally. If
4646
the .env file exists and the values are provided,
47-
the tests will attempt to send the requests to
47+
the examples will attempt to send the requests to
4848
your RunPod endpoint instead of running locally.
4949

50-
### Run test scripts
50+
### Run example scripts
5151

5252
1. Ensure that the RunPod Handler API is still running.
53-
2. Change directory to the `tests` directory and run
53+
2. Change directory to the `examples` directory and run
5454
one of the scripts, for example:
5555
```bash
56-
cd tests
56+
cd examples
5757
python3 all_1_source_into_all_1_target.py
5858
```
5959
3. This will display the HTTP status code and the filename
6060
of the output image, for example:
6161
```
6262
Status code: 200
6363
Saving image: 792a7e9f-9c36-4d35-b408-0d45d8e2bbcb.jpg
64+
Total time taken for RunPod Serverless API call 14.0 seconds
6465
```
6566

6667
You can then open the output image (in this case

docs/testing/runpod.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,21 @@ pip install -r requirements.txt
1515

1616
## Add Runpod credentials to .env
1717

18-
Copy the `.env.example` file to '.env' in the `tests`
18+
Copy the `.env.example` file to '.env' in the `examples`
1919
directory as follows:
2020

2121
```bash
22-
cd tests
22+
cd examples
2323
cp .env.example .env
2424
```
2525

2626
Edit the .env file and add your RunPod API key to
2727
`RUNPOD_API_KEY` and your endpoint ID to
2828
`RUNPOD_ENDPOINT_ID`. Without these credentials,
29-
the tests will attempt to run locally instead of
29+
the examples will attempt to run locally instead of
3030
on RunPod.
3131

32-
## Run test scripts
32+
## Run example scripts
3333

3434
Once the venv is created and activated, the requirements
3535
installed, and the credentials added to the .env
@@ -44,6 +44,7 @@ of the output image, for example:
4444
```
4545
Status code: 200
4646
Saving image: 792a7e9f-9c36-4d35-b408-0d45d8e2bbcb.jpg
47+
Total time taken for RunPod Serverless API call 14.0 seconds
4748
```
4849

4950
You can then open the output image (in this case
File renamed without changes.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env python3
2+
# Replace the single source face into the first face in the target image
3+
from util import post_request, encode_image_to_base64
4+
5+
SOURCE_IMAGE = '../data/src.jpg'
6+
TARGET_IMAGE = '../data/hp-3faces.jpeg'
7+
SOURCE_INDEXES = '-1'
8+
TARGET_INDEXES = '-1'
9+
BACKGROUND_ENHANCE = True
10+
FACE_RESTORE = True
11+
FACE_UPSAMPLE = True
12+
UPSCALE = 1
13+
CODEFORMER_FIDELITY = 0.5
14+
OUTPUT_FORMAT = 'JPEG'
15+
16+
17+
if __name__ == '__main__':
18+
# Create the payload dictionary
19+
payload = {
20+
"input": {
21+
"source_image": encode_image_to_base64(SOURCE_IMAGE),
22+
"target_image": encode_image_to_base64(TARGET_IMAGE),
23+
"source_indexes": SOURCE_INDEXES,
24+
"target_indexes": TARGET_INDEXES,
25+
"background_enhance": BACKGROUND_ENHANCE,
26+
"face_restore": FACE_RESTORE,
27+
"face_upsample": FACE_UPSAMPLE,
28+
"upscale": UPSCALE,
29+
"codeformer_fidelity": CODEFORMER_FIDELITY,
30+
"output_format": OUTPUT_FORMAT,
31+
"min_face_size": 30
32+
}
33+
}
34+
35+
post_request(payload)

0 commit comments

Comments
 (0)