Skip to content

Commit 1a68ace

Browse files
committed
Changes for the Masters Thesis
1 parent 4af6532 commit 1a68ace

28 files changed

+2546
-809
lines changed

.devcontainer/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ RUN apt-get -y install --no-install-recommends libgl1-mesa-glx
1919

2020
# Runtime dependencies
2121
COPY ./requirements/requirements_docker.txt /root/requirements_docker.txt
22+
RUN pip install Cython
2223
RUN pip install -r /root/requirements_docker.txt
2324

2425
# Develop dependencies

.devcontainer/devcontainer.json

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,18 @@
66
},
77
// Set *default* container specific settings.json values on container create.
88
"settings": {
9-
"terminal.integrated.shell.linux": "/usr/bin/zsh",
9+
"terminal.integrated.defaultProfile.linux": "zsh",
10+
"terminal.integrated.profiles.linux": {
11+
"zsh": {
12+
"path": "/usr/bin/zsh",
13+
"args": []
14+
}
15+
},
1016
"editor.rulers": [100],
1117
// ---- Python specific settings
18+
"python.experiments.enabled": false,
1219
"python.pythonPath": "/usr/local/bin/python",
13-
"python.formatting.provider": "autopep8",
20+
"python.formatting.provider": "black",
1421
"python.linting.pylintEnabled": false,
1522
"jupyter.alwaysTrustNotebooks": true,
1623
"python.languageServer": "Pylance",
@@ -21,7 +28,8 @@
2128
// ---- Python specific extensions
2229
"ms-python.python",
2330
"kevinrose.vsc-python-indent",
24-
"ms-python.vscode-pylance"
31+
"ms-python.vscode-pylance",
32+
"njpwerner.autodocstring"
2533
],
2634
// ---- Run with GPU driver
2735
"runArgs": [

README.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
This repository implements two algorithms for image reconstruction using a Gaussian denoiser in TensorFlow 2.
44

55
Algorithms:
6-
* **DMSP:** S. A. Bigdeli, P. Favaro, M. Jin, and M. Zwicker, [“Deep Mean-Shift Priors for Image Restoration,”](http://papers.nips.cc/paper/6678-deep-mean-shift-priors-for-image-restoration.pdf) in Advances in Neural Information Processing Systems 30, 2017, pp. 763–772.
7-
* **HQS:** K. Zhang, Y. Li, W. Zuo, L. Zhang, L. Van Gool, and R. Timofte, [“Plug-and-Play Image Restoration with Deep Denoiser Prior,”](http://arxiv.org/abs/2008.13751) arXiv:2008.13751 [cs, eess], Aug. 2020
86

7+
- **DMSP:** S. A. Bigdeli, P. Favaro, M. Jin, and M. Zwicker, [“Deep Mean-Shift Priors for Image Restoration,”](http://papers.nips.cc/paper/6678-deep-mean-shift-priors-for-image-restoration.pdf) in Advances in Neural Information Processing Systems 30, 2017, pp. 763–772.
8+
- **HQS:** K. Zhang, Y. Li, W. Zuo, L. Zhang, L. Van Gool, and R. Timofte, [“Plug-and-Play Image Restoration with Deep Denoiser Prior,”](http://arxiv.org/abs/2008.13751) IEEE Trans. Pattern Anal. Mach. Intell., pp. 1–1, 2021
99

1010
## Getting Started
1111

1212
Install using pip
13+
1314
```
1415
$ pip install git+https://github.com/HedgehogCode/deep-plug-and-play-prior
1516
```
@@ -21,10 +22,12 @@ See the example [notebooks](notebooks/) for usage examples.
2122
## Related Repositories
2223

2324
DMSP Implementations (significantly slower):
24-
* Matlab: https://github.com/siavashBigdeli/DMSP (only deblur)
25-
* TensorFlow 1: https://github.com/siavashBigdeli/DMSP-tensorflow (only deblur)
26-
* TensorFlow 2: https://github.com/siavashBigdeli/DMSP-TF2 (deblur and sr (but not bicubic))
25+
26+
- Matlab: https://github.com/siavashBigdeli/DMSP (only deblur)
27+
- TensorFlow 1: https://github.com/siavashBigdeli/DMSP-tensorflow (only deblur)
28+
- TensorFlow 2: https://github.com/siavashBigdeli/DMSP-TF2 (deblur and sr (but not bicubic))
2729

2830
HQS:
29-
* Matlab: https://github.com/cszn/IRCNN
30-
* Pytorch: https://github.com/cszn/DPIR
31+
32+
- Matlab: https://github.com/cszn/IRCNN
33+
- Pytorch: https://github.com/cszn/DPIR

dppp/__init__.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
from .utils import *
22
from .callback import *
33
from .metrics import *
4-
from .dmsp import dmsp_deblur_nb, dmsp_super_resolve, dmsp_inpaint
5-
from .hqs import hqs_deblur_nb, hqs_super_resolve, hqs_inpaint
4+
from .dmsp import (
5+
dmsp_deblur_nb,
6+
dmsp_deblur_blind,
7+
dmsp_super_resolve,
8+
dmsp_inpaint,
9+
)
10+
from .hqs import (
11+
hqs_deblur_nb,
12+
hqs_super_resolve,
13+
hqs_inpaint,
14+
hqs_video_super_resolve,
15+
hqs_lf_super_resolve,
16+
)

dppp/callback.py

Lines changed: 50 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,8 @@
1111
# TENSORBOARD
1212
###############################################################################
1313

14-
def callback_tb_image(tb_log_dir: str,
15-
summary_name: str,
16-
frequency: int
17-
) -> Callback:
14+
15+
def callback_tb_image(tb_log_dir: str, summary_name: str, frequency: int) -> Callback:
1816
tb_writer = tf.summary.create_file_writer(tb_log_dir)
1917

2018
def call(x: TensorLike, step: TensorLike):
@@ -25,10 +23,9 @@ def call(x: TensorLike, step: TensorLike):
2523
return call
2624

2725

28-
def callback_tb_scalar(tb_log_dir: str,
29-
summary_name: str,
30-
summary_fn: Callable[[TensorLike], TensorLike]
31-
) -> Callback:
26+
def callback_tb_scalar(
27+
tb_log_dir: str, summary_name: str, summary_fn: Callable[[TensorLike], TensorLike]
28+
) -> Callback:
3229
tb_writer = tf.summary.create_file_writer(tb_log_dir)
3330

3431
def call(x: TensorLike, step: TensorLike):
@@ -38,67 +35,87 @@ def call(x: TensorLike, step: TensorLike):
3835
return call
3936

4037

41-
def callback_tb_psnr(tb_log_dir: str, summary_name: str, gt_image: TensorLike) -> Callback:
42-
return callback_tb_scalar(tb_log_dir=tb_log_dir, summary_name=summary_name,
43-
summary_fn=lambda x: tf.reduce_mean(dppp.psnr(x, gt_image)))
38+
def callback_tb_psnr(
39+
tb_log_dir: str, summary_name: str, gt_image: TensorLike
40+
) -> Callback:
41+
return callback_tb_scalar(
42+
tb_log_dir=tb_log_dir,
43+
summary_name=summary_name,
44+
summary_fn=lambda x: tf.reduce_mean(dppp.psnr(x, gt_image)),
45+
)
4446

4547

46-
def callback_tb_ssim(tb_log_dir: str, summary_name: str, gt_image: TensorLike) -> Callback:
47-
return callback_tb_scalar(tb_log_dir=tb_log_dir, summary_name=summary_name,
48-
summary_fn=lambda x: tf.reduce_mean(dppp.ssim(x, gt_image)))
48+
def callback_tb_ssim(
49+
tb_log_dir: str, summary_name: str, gt_image: TensorLike
50+
) -> Callback:
51+
return callback_tb_scalar(
52+
tb_log_dir=tb_log_dir,
53+
summary_name=summary_name,
54+
summary_fn=lambda x: tf.reduce_mean(dppp.ssim(x, gt_image)),
55+
)
4956

5057

5158
###############################################################################
5259
# TF.PRINT
5360
###############################################################################
5461

55-
def callback_print_scalar(name: str,
56-
frequency: int,
57-
summary_fn: Callable[[TensorLike], TensorLike]
58-
) -> Callback:
62+
63+
def callback_print_scalar(
64+
name: str, frequency: int, summary_fn: Callable[[TensorLike], TensorLike]
65+
) -> Callback:
5966
def call(x: TensorLike, step: TensorLike):
6067
if step % frequency == 0: # type: ignore
61-
tf.print('Step:', step, ', ', name, ':', summary_fn(x))
68+
tf.print("Step:", step, ", ", name, ":", summary_fn(x))
6269

6370
return call
6471

6572

6673
def callback_print_psnr(name: str, frequency: int, gt_image: TensorLike) -> Callback:
67-
return callback_print_scalar(name=name, frequency=frequency,
68-
summary_fn=lambda x: tf.reduce_mean(dppp.psnr(x, gt_image)))
74+
return callback_print_scalar(
75+
name=name,
76+
frequency=frequency,
77+
summary_fn=lambda x: tf.reduce_mean(dppp.psnr(x, gt_image)),
78+
)
6979

7080

7181
def callback_print_ssim(name: str, frequency: int, gt_image: TensorLike) -> Callback:
72-
return callback_print_scalar(name=name, frequency=frequency,
73-
summary_fn=lambda x: tf.reduce_mean(dppp.ssim(x, gt_image)))
82+
return callback_print_scalar(
83+
name=name,
84+
frequency=frequency,
85+
summary_fn=lambda x: tf.reduce_mean(dppp.ssim(x, gt_image)),
86+
)
7487

7588

7689
###############################################################################
7790
# CSV
7891
###############################################################################
7992

80-
def callback_csv_metric(metrics: Dict[str, Tuple[MetricFnType, int]],
81-
num_steps: int): # TODO typing -> Tuple[Callable[[tf.Tensor, tf.Tensor], None], tf.Variable]:
93+
94+
def callback_csv_metric(metrics: Dict[str, Tuple[MetricFnType, int]], num_steps: int):
8295
metric_names = list(metrics.keys())
83-
csv = tf.Variable('Step,Image_Id,' + ','.join(metric_names) + '\n')
96+
csv = tf.Variable("Step,Image_Id," + ",".join(metric_names) + "\n")
8497

8598
def for_image(image_id: str, gt_image: TensorLike):
86-
87-
@tf.function(input_signature=(tf.TensorSpec(shape=[None, None, None, None], dtype=tf.float32),
88-
tf.TensorSpec(shape=[], dtype=tf.int64)))
99+
@tf.function(
100+
input_signature=(
101+
tf.TensorSpec(shape=[None, None, None, None], dtype=tf.float32),
102+
tf.TensorSpec(shape=[], dtype=tf.int64),
103+
)
104+
)
89105
def call(x: TensorLike, step: TensorLike):
90106
def val_for_metric(m):
91107
metric_fn, per_step = metrics[m]
92108
if step == num_steps - 1 or (step + 1) % per_step == 0: # type: ignore
93109
val = metric_fn(x, gt_image)[0] # type: ignore
94110
else:
95-
val = tf.constant(float('nan'))
111+
val = tf.constant(float("nan"))
96112
return tf.strings.as_string(val)
97113

98114
values = [val_for_metric(m) for m in metric_names]
99-
line = tf.strings.join([tf.strings.as_string(
100-
step), image_id, *values], separator=',')
101-
csv.assign(tf.strings.join([csv, line, '\n']))
115+
line = tf.strings.join(
116+
[tf.strings.as_string(step), image_id, *values], separator=","
117+
)
118+
csv.assign(tf.strings.join([csv, line, "\n"]))
102119

103120
return call
104121

0 commit comments

Comments
 (0)