Skip to content

Commit fe239c5

Browse files
committed
rel 2023
1 parent eac6fa4 commit fe239c5

11 files changed

Lines changed: 205 additions & 64 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
All major and minor version changes will be documented in this file. Details of
44
patch-level version changes can be found in [commit messages](../../commits/master).
55

6+
## 2023 - 2023/06/26
7+
8+
- Improved the tutorial docs
9+
- Bugfixes to `run` function
10+
- Test `run` function
11+
612
## 2022.2 - 2022/09/02
713

814
Improvements per https://github.com/FHPythonUtils/Waifu2x/pull/4, thanks

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,8 @@ optional arguments:
9595
A high-level overview of how the documentation is organized organized will help you know
9696
where to look for certain things:
9797

98-
<!--
9998
- [Tutorials](/documentation/tutorials) take you by the hand through a series of steps to get
10099
started using the software. Start here if you’re new.
101-
-->
102100
- The [Technical Reference](/documentation/reference) documents APIs and other aspects of the
103101
machinery. This documentation describes how to use the classes and functions at a lower level
104102
and assume that you have a good high-level understanding of the software.

documentation/reference/waifu2x/index.md

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,31 @@ def main():
8888

8989
Runs waifu2x. Mostly the same inputs as CLI ones.
9090

91+
#### Arguments
92+
93+
- `input_img_path` *str* - Input image/ directory, defaults to "images/small.png"
94+
- `output_img_path` *str* - Directory to write output images to, defaults to "./"
95+
- `gpu` *int* - CUDA enabled GPU to use, defaults to -1
96+
:param int | None quality: Set the quality of output images 1-100 (None=100), defaults to None
97+
:param str | None model_dir: Specify a custom directory containing models, defaults to None
98+
- `scale_ratio` *float* - Specify a scale, defaults to 2.0
99+
- `batch_size` *int* - _description_, defaults to 16
100+
- `block_size` *int* - _description_, defaults to 128
101+
- `extension` *str* - Select output extension png/webp
102+
- `arch` *str* - _description_, defaults to "VGG7"
103+
- `method` *str* - _description_, defaults to "scale"
104+
- `noise_level` *int* - _description_, defaults to 1
105+
- `color` *str* - _description_, defaults to "rgb"
106+
- `tta_level` *int* - _description_, defaults to 8
107+
- `width` *int* - _description_, defaults to 0
108+
- `height` *int* - _description_, defaults to 0
109+
- `shorter_side` *int* - _description_, defaults to 0
110+
- `longer_side` *int* - _description_, defaults to 0
111+
- `should_print` *bool* - _description_, defaults to True
112+
91113
#### Raises
92114

93-
- `ValueError` - Output file extension not supported
115+
- `ValueError` - Output file extension not supported
94116

95117
#### Signature
96118

@@ -100,7 +122,7 @@ def run(
100122
output_img_path: str = "./",
101123
gpu: int = -1,
102124
quality: int | None = None,
103-
model_dir: str = None,
125+
model_dir: str | None = None,
104126
scale_ratio: float = 2.0,
105127
batch_size: int = 16,
106128
block_size: int = 128,
@@ -114,7 +136,7 @@ def run(
114136
height: int = 0,
115137
shorter_side: int = 0,
116138
longer_side: int = 0,
117-
should_print: int = True,
139+
should_print: bool = True,
118140
):
119141
...
120142
```

documentation/tutorials/README.md

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,8 @@
1+
# Tutorials
12

2-
#
3+
These tutorials are to provide details on how to use the library from the command line
4+
and as a python module. The [Technical Reference](../../documentation/reference) documents
5+
APIs and other aspects of the machinery
36

4-
- [Step 1](#step-1)
5-
- [Step 2](#step-2)
6-
- [Step 3](#step-3)
7-
8-
## Step 1
9-
10-
Organise images into a single directory eg 'images/'
11-
12-
## Step 2
13-
14-
Run 'waifu2x' as follows:
15-
16-
```sh
17-
poetry run py -m waifu2x -i images -o output_images
18-
```
19-
20-
See below for a breakdown
21-
22-
- `poetry run`: in this example we are using poetry to run the python code inside a virtual environment. This is optional but good practise
23-
- `py -m waifu2x`: tell python to use waifu2x module (this library). If on Mac/ Linux use `python3 -m waifu2x`
24-
- `-i images`: the input directory of images
25-
- `-o output_images`: the output directory
26-
27-
## Step 3
28-
29-
Output can be found in 'output_images/'
7+
- [Command Line](cli.md)
8+
- [Python Module](module.md)

documentation/tutorials/cli.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<!-- omit in toc -->
2+
# Command Line Tutorial
3+
4+
- [Step 1](#step-1)
5+
- [Step 2](#step-2)
6+
- [Step 3](#step-3)
7+
8+
## Step 1
9+
10+
Organise images into a single directory eg `images/`
11+
12+
For example, the following files:
13+
14+
<div>
15+
<img src="../../tests/data/background.png" alt="Screenshot 1" width="300">
16+
<img src="../../tests/data/foreground.png" alt="Screenshot 2" width="300">
17+
</div>
18+
19+
## Step 2
20+
21+
Run `waifu2x` as follows:
22+
23+
```sh
24+
poetry run py -m waifu2x -i images -o output_images
25+
```
26+
27+
See below for a breakdown
28+
29+
- `poetry run`: in this example we are using poetry to run the python code inside a virtual environment. This is optional but good practise
30+
- `py -m waifu2x`: tell python to use waifu2x module (this library). If on Mac/ Linux use `python3 -m waifu2x`
31+
- `-i images`: the input directory of images
32+
- `-o output_images`: the output directory
33+
34+
## Step 3
35+
36+
Output can be found in `output_images/`
37+
38+
For example, the following files:
39+
40+
<div>
41+
<img src="../../tests/data/background_expected.png" alt="Screenshot 1" width="300">
42+
<img src="../../tests/data/foreground_expected.png" alt="Screenshot 2" width="300">
43+
</div>

documentation/tutorials/module.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<!-- omit in toc -->
2+
# Python Module Tutorial
3+
4+
- [Step 1](#step-1)
5+
- [Step 2](#step-2)
6+
- [Step 3](#step-3)
7+
8+
## Step 1
9+
10+
Organise images into a single directory eg `images/`
11+
12+
For example, the following files:
13+
14+
<div>
15+
<img src="../../tests/data/background.png" alt="Screenshot 1" width="300">
16+
<img src="../../tests/data/foreground.png" alt="Screenshot 2" width="300">
17+
</div>
18+
19+
## Step 2
20+
21+
```python
22+
from waifu2x import run
23+
24+
input_img_path = "foreground.png"
25+
output_img_path = "foreground_actual.png"
26+
run(input_img_path,output_img_path)
27+
```
28+
29+
## Step 3
30+
31+
Output can be found in `output_images/`
32+
33+
For example, the following files:
34+
35+
<div>
36+
<img src="../../tests/data/background_expected.png" alt="Screenshot 1" width="300">
37+
<img src="../../tests/data/foreground_expected.png" alt="Screenshot 2" width="300">
38+
</div>

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "waifu2x"
3-
version = "2022.2"
3+
version = "2023"
44
license = "mit"
55
description = "Chainer implementation of waifu2x"
66
authors = ["FredHappyface"]

tests/data/background_actual.png

4.44 KB
Loading

tests/data/foreground_actual.png

49.2 KB
Loading

tests/test_scale.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
THISDIR = str(Path(__file__).resolve().parent)
99
sys.path.insert(0, str(Path(THISDIR).parent))
1010

11-
from waifu2x import load_models, upscale_image
11+
from waifu2x import load_models, run, upscale_image
1212

1313
args = Namespace(
1414
color="rgb",
@@ -77,6 +77,32 @@ def test_foreground_jpg():
7777
)
7878

7979

80+
def test_run_background_png():
81+
"""test_run_background_png"""
82+
input_img_path = f"{THISDIR}/data/background.png"
83+
output_img_path = f"{THISDIR}/data/background_actual.png"
84+
expected = f"{THISDIR}/data/background_expected.png"
85+
run(input_img_path, output_img_path)
86+
assert imgcompare.is_equal(
87+
output_img_path,
88+
expected,
89+
tolerance=0.2,
90+
)
91+
92+
93+
def test_run_foreground_png():
94+
"""test_run_foreground_png"""
95+
input_img_path = f"{THISDIR}/data/foreground.png"
96+
output_img_path = f"{THISDIR}/data/foreground_actual.png"
97+
expected = f"{THISDIR}/data/foreground_expected.png"
98+
run(input_img_path, output_img_path)
99+
assert imgcompare.is_equal(
100+
output_img_path,
101+
expected,
102+
tolerance=0.2,
103+
)
104+
105+
80106
if __name__ == "__main__": # pragma: no cover
81107
test_background_png()
82108
test_background_jpg()

0 commit comments

Comments
 (0)