├── .gitignore
├── LICENSE
├── README.md
├── Test
├── Set14
│ ├── baboon.bmp
│ ├── barbara.bmp
│ ├── bridge.bmp
│ ├── coastguard.bmp
│ ├── comic.bmp
│ ├── face.bmp
│ ├── flowers.bmp
│ ├── foreman.bmp
│ ├── lenna.bmp
│ ├── man.bmp
│ ├── monarch.bmp
│ ├── pepper.bmp
│ ├── ppt3.bmp
│ └── zebra.bmp
└── Set5
│ ├── baby_GT.bmp
│ ├── bird_GT.bmp
│ ├── butterfly_GT.bmp
│ ├── head_GT.bmp
│ └── woman_GT.bmp
├── Train
├── t1.bmp
├── t10.bmp
├── t11.bmp
├── t12.bmp
├── t13.bmp
├── t14.bmp
├── t15.bmp
├── t16.bmp
├── t17.bmp
├── t18.bmp
├── t19.bmp
├── t2.bmp
├── t20.bmp
├── t21.bmp
├── t22.bmp
├── t23.bmp
├── t24.bmp
├── t25.bmp
├── t26.bmp
├── t27.bmp
├── t28.bmp
├── t29.bmp
├── t3.bmp
├── t30.bmp
├── t31.bmp
├── t32.bmp
├── t33.bmp
├── t34.bmp
├── t35.bmp
├── t36.bmp
├── t37.bmp
├── t38.bmp
├── t39.bmp
├── t4.bmp
├── t40.bmp
├── t42.bmp
├── t43.bmp
├── t44.bmp
├── t45.bmp
├── t46.bmp
├── t47.bmp
├── t48.bmp
├── t49.bmp
├── t5.bmp
├── t50.bmp
├── t51.bmp
├── t52.bmp
├── t53.bmp
├── t54.bmp
├── t55.bmp
├── t56.bmp
├── t57.bmp
├── t58.bmp
├── t59.bmp
├── t6.bmp
├── t60.bmp
├── t61.bmp
├── t62.bmp
├── t63.bmp
├── t64.bmp
├── t65.bmp
├── t66.bmp
├── t7.bmp
├── t8.bmp
├── t9.bmp
├── tt1.bmp
├── tt10.bmp
├── tt12.bmp
├── tt13.bmp
├── tt14.bmp
├── tt15.bmp
├── tt16.bmp
├── tt17.bmp
├── tt18.bmp
├── tt19.bmp
├── tt2.bmp
├── tt20.bmp
├── tt21.bmp
├── tt22.bmp
├── tt23.bmp
├── tt24.bmp
├── tt25.bmp
├── tt26.bmp
├── tt27.bmp
├── tt3.bmp
├── tt4.bmp
├── tt5.bmp
├── tt6.bmp
├── tt7.bmp
├── tt8.bmp
└── tt9.bmp
├── checkpoint
└── srcnn_21
│ ├── SRCNN.model-2550000
│ ├── SRCNN.model-2550000.meta
│ └── checkpoint
├── main.py
├── model.py
├── result
├── bicubic.png
├── orig.png
└── srcnn.png
└── utils.py
/.gitignore:
--------------------------------------------------------------------------------
1 | # Byte-compiled / optimized / DLL files
2 | __pycache__/
3 | *.py[cod]
4 | *$py.class
5 |
6 | # C extensions
7 | *.so
8 |
9 | # Distribution / packaging
10 | .Python
11 | env/
12 | build/
13 | develop-eggs/
14 | dist/
15 | downloads/
16 | eggs/
17 | .eggs/
18 | lib/
19 | lib64/
20 | parts/
21 | sdist/
22 | var/
23 | *.egg-info/
24 | .installed.cfg
25 | *.egg
26 |
27 | # PyInstaller
28 | # Usually these files are written by a python script from a template
29 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
30 | *.manifest
31 | *.spec
32 |
33 | # Installer logs
34 | pip-log.txt
35 | pip-delete-this-directory.txt
36 |
37 | # Unit test / coverage reports
38 | htmlcov/
39 | .tox/
40 | .coverage
41 | .coverage.*
42 | .cache
43 | nosetests.xml
44 | coverage.xml
45 | *,cover
46 | .hypothesis/
47 |
48 | # Translations
49 | *.mo
50 | *.pot
51 |
52 | # Django stuff:
53 | *.log
54 | local_settings.py
55 |
56 | # Flask stuff:
57 | instance/
58 | .webassets-cache
59 |
60 | # Scrapy stuff:
61 | .scrapy
62 |
63 | # Sphinx documentation
64 | docs/_build/
65 |
66 | # PyBuilder
67 | target/
68 |
69 | # IPython Notebook
70 | .ipynb_checkpoints
71 |
72 | # pyenv
73 | .python-version
74 |
75 | # celery beat schedule file
76 | celerybeat-schedule
77 |
78 | # dotenv
79 | .env
80 |
81 | # virtualenv
82 | venv/
83 | ENV/
84 |
85 | # Spyder project settings
86 | .spyderproject
87 |
88 | # Rope project settings
89 | .ropeproject
90 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2016 tegg89
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SRCNN-Tensorflow
2 | Tensorflow implementation of Convolutional Neural Networks for super-resolution. The original Matlab and Caffe from official website can be found [here](http://mmlab.ie.cuhk.edu.hk/projects/SRCNN.html).
3 |
4 | ## Prerequisites
5 | * Tensorflow
6 | * Scipy version > 0.18 ('mode' option from scipy.misc.imread function)
7 | * h5py
8 | * matplotlib
9 |
10 | This code requires Tensorflow. Also scipy is used instead of Matlab or OpenCV. Especially, installing OpenCV at Linux is sort of complicated. So, with reproducing this paper, I used scipy instead. For more imformation about scipy, click [here](https://www.scipy.org/).
11 |
12 | ## Usage
13 | For training, `python main.py`
14 |
15 | For testing, `python main.py --is_train False --stride 21`
16 |
17 | ## Result
18 | After training 15,000 epochs, I got similar super-resolved image to reference paper. Training time takes 12 hours 16 minutes and 1.41 seconds. My desktop performance is Intel I7-6700 CPU, GTX970, and 16GB RAM. Result images are shown below.
19 | Original butterfly image:
20 | 
21 | Bicubic interpolated image:
22 | 
23 | Super-resolved image:
24 | 
25 |
26 | ## References
27 | * [liliumao/Tensorflow-srcnn](https://github.com/liliumao/Tensorflow-srcnn)
28 | * - I referred to this repository which is same implementation using Matlab code and Caffe model.
29 |
30 |
31 | * [carpedm20/DCGAN-tensorflow](https://github.com/carpedm20/DCGAN-tensorflow)
32 | * - I have followed and learned training process and structure of this repository.
33 |
34 |
--------------------------------------------------------------------------------
/Test/Set14/baboon.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Test/Set14/baboon.bmp
--------------------------------------------------------------------------------
/Test/Set14/barbara.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Test/Set14/barbara.bmp
--------------------------------------------------------------------------------
/Test/Set14/bridge.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Test/Set14/bridge.bmp
--------------------------------------------------------------------------------
/Test/Set14/coastguard.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Test/Set14/coastguard.bmp
--------------------------------------------------------------------------------
/Test/Set14/comic.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Test/Set14/comic.bmp
--------------------------------------------------------------------------------
/Test/Set14/face.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Test/Set14/face.bmp
--------------------------------------------------------------------------------
/Test/Set14/flowers.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Test/Set14/flowers.bmp
--------------------------------------------------------------------------------
/Test/Set14/foreman.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Test/Set14/foreman.bmp
--------------------------------------------------------------------------------
/Test/Set14/lenna.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Test/Set14/lenna.bmp
--------------------------------------------------------------------------------
/Test/Set14/man.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Test/Set14/man.bmp
--------------------------------------------------------------------------------
/Test/Set14/monarch.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Test/Set14/monarch.bmp
--------------------------------------------------------------------------------
/Test/Set14/pepper.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Test/Set14/pepper.bmp
--------------------------------------------------------------------------------
/Test/Set14/ppt3.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Test/Set14/ppt3.bmp
--------------------------------------------------------------------------------
/Test/Set14/zebra.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Test/Set14/zebra.bmp
--------------------------------------------------------------------------------
/Test/Set5/baby_GT.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Test/Set5/baby_GT.bmp
--------------------------------------------------------------------------------
/Test/Set5/bird_GT.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Test/Set5/bird_GT.bmp
--------------------------------------------------------------------------------
/Test/Set5/butterfly_GT.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Test/Set5/butterfly_GT.bmp
--------------------------------------------------------------------------------
/Test/Set5/head_GT.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Test/Set5/head_GT.bmp
--------------------------------------------------------------------------------
/Test/Set5/woman_GT.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Test/Set5/woman_GT.bmp
--------------------------------------------------------------------------------
/Train/t1.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t1.bmp
--------------------------------------------------------------------------------
/Train/t10.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t10.bmp
--------------------------------------------------------------------------------
/Train/t11.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t11.bmp
--------------------------------------------------------------------------------
/Train/t12.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t12.bmp
--------------------------------------------------------------------------------
/Train/t13.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t13.bmp
--------------------------------------------------------------------------------
/Train/t14.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t14.bmp
--------------------------------------------------------------------------------
/Train/t15.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t15.bmp
--------------------------------------------------------------------------------
/Train/t16.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t16.bmp
--------------------------------------------------------------------------------
/Train/t17.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t17.bmp
--------------------------------------------------------------------------------
/Train/t18.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t18.bmp
--------------------------------------------------------------------------------
/Train/t19.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t19.bmp
--------------------------------------------------------------------------------
/Train/t2.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t2.bmp
--------------------------------------------------------------------------------
/Train/t20.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t20.bmp
--------------------------------------------------------------------------------
/Train/t21.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t21.bmp
--------------------------------------------------------------------------------
/Train/t22.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t22.bmp
--------------------------------------------------------------------------------
/Train/t23.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t23.bmp
--------------------------------------------------------------------------------
/Train/t24.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t24.bmp
--------------------------------------------------------------------------------
/Train/t25.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t25.bmp
--------------------------------------------------------------------------------
/Train/t26.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t26.bmp
--------------------------------------------------------------------------------
/Train/t27.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t27.bmp
--------------------------------------------------------------------------------
/Train/t28.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t28.bmp
--------------------------------------------------------------------------------
/Train/t29.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t29.bmp
--------------------------------------------------------------------------------
/Train/t3.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t3.bmp
--------------------------------------------------------------------------------
/Train/t30.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t30.bmp
--------------------------------------------------------------------------------
/Train/t31.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t31.bmp
--------------------------------------------------------------------------------
/Train/t32.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t32.bmp
--------------------------------------------------------------------------------
/Train/t33.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t33.bmp
--------------------------------------------------------------------------------
/Train/t34.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t34.bmp
--------------------------------------------------------------------------------
/Train/t35.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t35.bmp
--------------------------------------------------------------------------------
/Train/t36.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t36.bmp
--------------------------------------------------------------------------------
/Train/t37.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t37.bmp
--------------------------------------------------------------------------------
/Train/t38.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t38.bmp
--------------------------------------------------------------------------------
/Train/t39.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t39.bmp
--------------------------------------------------------------------------------
/Train/t4.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t4.bmp
--------------------------------------------------------------------------------
/Train/t40.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t40.bmp
--------------------------------------------------------------------------------
/Train/t42.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t42.bmp
--------------------------------------------------------------------------------
/Train/t43.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t43.bmp
--------------------------------------------------------------------------------
/Train/t44.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t44.bmp
--------------------------------------------------------------------------------
/Train/t45.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t45.bmp
--------------------------------------------------------------------------------
/Train/t46.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t46.bmp
--------------------------------------------------------------------------------
/Train/t47.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t47.bmp
--------------------------------------------------------------------------------
/Train/t48.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t48.bmp
--------------------------------------------------------------------------------
/Train/t49.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t49.bmp
--------------------------------------------------------------------------------
/Train/t5.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t5.bmp
--------------------------------------------------------------------------------
/Train/t50.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t50.bmp
--------------------------------------------------------------------------------
/Train/t51.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t51.bmp
--------------------------------------------------------------------------------
/Train/t52.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t52.bmp
--------------------------------------------------------------------------------
/Train/t53.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t53.bmp
--------------------------------------------------------------------------------
/Train/t54.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t54.bmp
--------------------------------------------------------------------------------
/Train/t55.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t55.bmp
--------------------------------------------------------------------------------
/Train/t56.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t56.bmp
--------------------------------------------------------------------------------
/Train/t57.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t57.bmp
--------------------------------------------------------------------------------
/Train/t58.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t58.bmp
--------------------------------------------------------------------------------
/Train/t59.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t59.bmp
--------------------------------------------------------------------------------
/Train/t6.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t6.bmp
--------------------------------------------------------------------------------
/Train/t60.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t60.bmp
--------------------------------------------------------------------------------
/Train/t61.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t61.bmp
--------------------------------------------------------------------------------
/Train/t62.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t62.bmp
--------------------------------------------------------------------------------
/Train/t63.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t63.bmp
--------------------------------------------------------------------------------
/Train/t64.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t64.bmp
--------------------------------------------------------------------------------
/Train/t65.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t65.bmp
--------------------------------------------------------------------------------
/Train/t66.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t66.bmp
--------------------------------------------------------------------------------
/Train/t7.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t7.bmp
--------------------------------------------------------------------------------
/Train/t8.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t8.bmp
--------------------------------------------------------------------------------
/Train/t9.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/t9.bmp
--------------------------------------------------------------------------------
/Train/tt1.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/tt1.bmp
--------------------------------------------------------------------------------
/Train/tt10.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/tt10.bmp
--------------------------------------------------------------------------------
/Train/tt12.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/tt12.bmp
--------------------------------------------------------------------------------
/Train/tt13.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/tt13.bmp
--------------------------------------------------------------------------------
/Train/tt14.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/tt14.bmp
--------------------------------------------------------------------------------
/Train/tt15.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/tt15.bmp
--------------------------------------------------------------------------------
/Train/tt16.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/tt16.bmp
--------------------------------------------------------------------------------
/Train/tt17.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/tt17.bmp
--------------------------------------------------------------------------------
/Train/tt18.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/tt18.bmp
--------------------------------------------------------------------------------
/Train/tt19.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/tt19.bmp
--------------------------------------------------------------------------------
/Train/tt2.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/tt2.bmp
--------------------------------------------------------------------------------
/Train/tt20.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/tt20.bmp
--------------------------------------------------------------------------------
/Train/tt21.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/tt21.bmp
--------------------------------------------------------------------------------
/Train/tt22.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/tt22.bmp
--------------------------------------------------------------------------------
/Train/tt23.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/tt23.bmp
--------------------------------------------------------------------------------
/Train/tt24.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/tt24.bmp
--------------------------------------------------------------------------------
/Train/tt25.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/tt25.bmp
--------------------------------------------------------------------------------
/Train/tt26.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/tt26.bmp
--------------------------------------------------------------------------------
/Train/tt27.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/tt27.bmp
--------------------------------------------------------------------------------
/Train/tt3.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/tt3.bmp
--------------------------------------------------------------------------------
/Train/tt4.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/tt4.bmp
--------------------------------------------------------------------------------
/Train/tt5.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/tt5.bmp
--------------------------------------------------------------------------------
/Train/tt6.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/tt6.bmp
--------------------------------------------------------------------------------
/Train/tt7.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/tt7.bmp
--------------------------------------------------------------------------------
/Train/tt8.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/tt8.bmp
--------------------------------------------------------------------------------
/Train/tt9.bmp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/Train/tt9.bmp
--------------------------------------------------------------------------------
/checkpoint/srcnn_21/SRCNN.model-2550000:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/checkpoint/srcnn_21/SRCNN.model-2550000
--------------------------------------------------------------------------------
/checkpoint/srcnn_21/SRCNN.model-2550000.meta:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/checkpoint/srcnn_21/SRCNN.model-2550000.meta
--------------------------------------------------------------------------------
/checkpoint/srcnn_21/checkpoint:
--------------------------------------------------------------------------------
1 | model_checkpoint_path: "SRCNN.model-2550000"
2 | all_model_checkpoint_paths: "SRCNN.model-2550000"
3 |
--------------------------------------------------------------------------------
/main.py:
--------------------------------------------------------------------------------
1 | from model import SRCNN
2 | from utils import input_setup
3 |
4 | import numpy as np
5 | import tensorflow as tf
6 |
7 | import pprint
8 | import os
9 |
10 | flags = tf.app.flags
11 | flags.DEFINE_integer("epoch", 15000, "Number of epoch [15000]")
12 | flags.DEFINE_integer("batch_size", 128, "The size of batch images [128]")
13 | flags.DEFINE_integer("image_size", 33, "The size of image to use [33]")
14 | flags.DEFINE_integer("label_size", 21, "The size of label to produce [21]")
15 | flags.DEFINE_float("learning_rate", 1e-4, "The learning rate of gradient descent algorithm [1e-4]")
16 | flags.DEFINE_integer("c_dim", 1, "Dimension of image color. [1]")
17 | flags.DEFINE_integer("scale", 3, "The size of scale factor for preprocessing input image [3]")
18 | flags.DEFINE_integer("stride", 14, "The size of stride to apply input image [14]")
19 | flags.DEFINE_string("checkpoint_dir", "checkpoint", "Name of checkpoint directory [checkpoint]")
20 | flags.DEFINE_string("sample_dir", "sample", "Name of sample directory [sample]")
21 | flags.DEFINE_boolean("is_train", True, "True for training, False for testing [True]")
22 | FLAGS = flags.FLAGS
23 |
24 | pp = pprint.PrettyPrinter()
25 |
26 | def main(_):
27 | pp.pprint(flags.FLAGS.__flags)
28 |
29 | if not os.path.exists(FLAGS.checkpoint_dir):
30 | os.makedirs(FLAGS.checkpoint_dir)
31 | if not os.path.exists(FLAGS.sample_dir):
32 | os.makedirs(FLAGS.sample_dir)
33 |
34 | with tf.Session() as sess:
35 | srcnn = SRCNN(sess,
36 | image_size=FLAGS.image_size,
37 | label_size=FLAGS.label_size,
38 | batch_size=FLAGS.batch_size,
39 | c_dim=FLAGS.c_dim,
40 | checkpoint_dir=FLAGS.checkpoint_dir,
41 | sample_dir=FLAGS.sample_dir)
42 |
43 | srcnn.train(FLAGS)
44 |
45 | if __name__ == '__main__':
46 | tf.app.run()
47 |
--------------------------------------------------------------------------------
/model.py:
--------------------------------------------------------------------------------
1 | from utils import (
2 | read_data,
3 | input_setup,
4 | imsave,
5 | merge
6 | )
7 |
8 | import time
9 | import os
10 | import matplotlib.pyplot as plt
11 |
12 | import numpy as np
13 | import tensorflow as tf
14 |
15 | try:
16 | xrange
17 | except:
18 | xrange = range
19 |
20 | class SRCNN(object):
21 |
22 | def __init__(self,
23 | sess,
24 | image_size=33,
25 | label_size=21,
26 | batch_size=128,
27 | c_dim=1,
28 | checkpoint_dir=None,
29 | sample_dir=None):
30 |
31 | self.sess = sess
32 | self.is_grayscale = (c_dim == 1)
33 | self.image_size = image_size
34 | self.label_size = label_size
35 | self.batch_size = batch_size
36 |
37 | self.c_dim = c_dim
38 |
39 | self.checkpoint_dir = checkpoint_dir
40 | self.sample_dir = sample_dir
41 | self.build_model()
42 |
43 | def build_model(self):
44 | self.images = tf.placeholder(tf.float32, [None, self.image_size, self.image_size, self.c_dim], name='images')
45 | self.labels = tf.placeholder(tf.float32, [None, self.label_size, self.label_size, self.c_dim], name='labels')
46 |
47 | self.weights = {
48 | 'w1': tf.Variable(tf.random_normal([9, 9, 1, 64], stddev=1e-3), name='w1'),
49 | 'w2': tf.Variable(tf.random_normal([1, 1, 64, 32], stddev=1e-3), name='w2'),
50 | 'w3': tf.Variable(tf.random_normal([5, 5, 32, 1], stddev=1e-3), name='w3')
51 | }
52 | self.biases = {
53 | 'b1': tf.Variable(tf.zeros([64]), name='b1'),
54 | 'b2': tf.Variable(tf.zeros([32]), name='b2'),
55 | 'b3': tf.Variable(tf.zeros([1]), name='b3')
56 | }
57 |
58 | self.pred = self.model()
59 |
60 | # Loss function (MSE)
61 | self.loss = tf.reduce_mean(tf.square(self.labels - self.pred))
62 |
63 | self.saver = tf.train.Saver()
64 |
65 | def train(self, config):
66 | if config.is_train:
67 | input_setup(self.sess, config)
68 | else:
69 | nx, ny = input_setup(self.sess, config)
70 |
71 | if config.is_train:
72 | data_dir = os.path.join('./{}'.format(config.checkpoint_dir), "train.h5")
73 | else:
74 | data_dir = os.path.join('./{}'.format(config.checkpoint_dir), "test.h5")
75 |
76 | train_data, train_label = read_data(data_dir)
77 |
78 | # Stochastic gradient descent with the standard backpropagation
79 | self.train_op = tf.train.GradientDescentOptimizer(config.learning_rate).minimize(self.loss)
80 |
81 | tf.initialize_all_variables().run()
82 |
83 | counter = 0
84 | start_time = time.time()
85 |
86 | if self.load(self.checkpoint_dir):
87 | print(" [*] Load SUCCESS")
88 | else:
89 | print(" [!] Load failed...")
90 |
91 | if config.is_train:
92 | print("Training...")
93 |
94 | for ep in xrange(config.epoch):
95 | # Run by batch images
96 | batch_idxs = len(train_data) // config.batch_size
97 | for idx in xrange(0, batch_idxs):
98 | batch_images = train_data[idx*config.batch_size : (idx+1)*config.batch_size]
99 | batch_labels = train_label[idx*config.batch_size : (idx+1)*config.batch_size]
100 |
101 | counter += 1
102 | _, err = self.sess.run([self.train_op, self.loss], feed_dict={self.images: batch_images, self.labels: batch_labels})
103 |
104 | if counter % 10 == 0:
105 | print("Epoch: [%2d], step: [%2d], time: [%4.4f], loss: [%.8f]" \
106 | % ((ep+1), counter, time.time()-start_time, err))
107 |
108 | if counter % 500 == 0:
109 | self.save(config.checkpoint_dir, counter)
110 |
111 | else:
112 | print("Testing...")
113 |
114 | result = self.pred.eval({self.images: train_data, self.labels: train_label})
115 |
116 | result = merge(result, [nx, ny])
117 | result = result.squeeze()
118 | image_path = os.path.join(os.getcwd(), config.sample_dir)
119 | image_path = os.path.join(image_path, "test_image.png")
120 | imsave(result, image_path)
121 |
122 | def model(self):
123 | conv1 = tf.nn.relu(tf.nn.conv2d(self.images, self.weights['w1'], strides=[1,1,1,1], padding='VALID') + self.biases['b1'])
124 | conv2 = tf.nn.relu(tf.nn.conv2d(conv1, self.weights['w2'], strides=[1,1,1,1], padding='VALID') + self.biases['b2'])
125 | conv3 = tf.nn.conv2d(conv2, self.weights['w3'], strides=[1,1,1,1], padding='VALID') + self.biases['b3']
126 | return conv3
127 |
128 | def save(self, checkpoint_dir, step):
129 | model_name = "SRCNN.model"
130 | model_dir = "%s_%s" % ("srcnn", self.label_size)
131 | checkpoint_dir = os.path.join(checkpoint_dir, model_dir)
132 |
133 | if not os.path.exists(checkpoint_dir):
134 | os.makedirs(checkpoint_dir)
135 |
136 | self.saver.save(self.sess,
137 | os.path.join(checkpoint_dir, model_name),
138 | global_step=step)
139 |
140 | def load(self, checkpoint_dir):
141 | print(" [*] Reading checkpoints...")
142 | model_dir = "%s_%s" % ("srcnn", self.label_size)
143 | checkpoint_dir = os.path.join(checkpoint_dir, model_dir)
144 |
145 | ckpt = tf.train.get_checkpoint_state(checkpoint_dir)
146 | if ckpt and ckpt.model_checkpoint_path:
147 | ckpt_name = os.path.basename(ckpt.model_checkpoint_path)
148 | self.saver.restore(self.sess, os.path.join(checkpoint_dir, ckpt_name))
149 | return True
150 | else:
151 | return False
152 |
--------------------------------------------------------------------------------
/result/bicubic.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/result/bicubic.png
--------------------------------------------------------------------------------
/result/orig.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/result/orig.png
--------------------------------------------------------------------------------
/result/srcnn.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tegg89/SRCNN-Tensorflow/78be1a24697935fc39a3a8cf59a6632264afade7/result/srcnn.png
--------------------------------------------------------------------------------
/utils.py:
--------------------------------------------------------------------------------
1 | """
2 | Scipy version > 0.18 is needed, due to 'mode' option from scipy.misc.imread function
3 | """
4 |
5 | import os
6 | import glob
7 | import h5py
8 | import random
9 | import matplotlib.pyplot as plt
10 |
11 | from PIL import Image # for loading images as YCbCr format
12 | import scipy.misc
13 | import scipy.ndimage
14 | import numpy as np
15 |
16 | import tensorflow as tf
17 |
18 | try:
19 | xrange
20 | except:
21 | xrange = range
22 |
23 | FLAGS = tf.app.flags.FLAGS
24 |
25 | def read_data(path):
26 | """
27 | Read h5 format data file
28 |
29 | Args:
30 | path: file path of desired file
31 | data: '.h5' file format that contains train data values
32 | label: '.h5' file format that contains train label values
33 | """
34 | with h5py.File(path, 'r') as hf:
35 | data = np.array(hf.get('data'))
36 | label = np.array(hf.get('label'))
37 | return data, label
38 |
39 | def preprocess(path, scale=3):
40 | """
41 | Preprocess single image file
42 | (1) Read original image as YCbCr format (and grayscale as default)
43 | (2) Normalize
44 | (3) Apply image file with bicubic interpolation
45 |
46 | Args:
47 | path: file path of desired file
48 | input_: image applied bicubic interpolation (low-resolution)
49 | label_: image with original resolution (high-resolution)
50 | """
51 | image = imread(path, is_grayscale=True)
52 | label_ = modcrop(image, scale)
53 |
54 | # Must be normalized
55 | image = image / 255.
56 | label_ = label_ / 255.
57 |
58 | input_ = scipy.ndimage.interpolation.zoom(label_, (1./scale), prefilter=False)
59 | input_ = scipy.ndimage.interpolation.zoom(input_, (scale/1.), prefilter=False)
60 |
61 | return input_, label_
62 |
63 | def prepare_data(sess, dataset):
64 | """
65 | Args:
66 | dataset: choose train dataset or test dataset
67 |
68 | For train dataset, output data would be ['.../t1.bmp', '.../t2.bmp', ..., '.../t99.bmp']
69 | """
70 | if FLAGS.is_train:
71 | filenames = os.listdir(dataset)
72 | data_dir = os.path.join(os.getcwd(), dataset)
73 | data = glob.glob(os.path.join(data_dir, "*.bmp"))
74 | else:
75 | data_dir = os.path.join(os.sep, (os.path.join(os.getcwd(), dataset)), "Set5")
76 | data = glob.glob(os.path.join(data_dir, "*.bmp"))
77 |
78 | return data
79 |
80 | def make_data(sess, data, label):
81 | """
82 | Make input data as h5 file format
83 | Depending on 'is_train' (flag value), savepath would be changed.
84 | """
85 | if FLAGS.is_train:
86 | savepath = os.path.join(os.getcwd(), 'checkpoint/train.h5')
87 | else:
88 | savepath = os.path.join(os.getcwd(), 'checkpoint/test.h5')
89 |
90 | with h5py.File(savepath, 'w') as hf:
91 | hf.create_dataset('data', data=data)
92 | hf.create_dataset('label', data=label)
93 |
94 | def imread(path, is_grayscale=True):
95 | """
96 | Read image using its path.
97 | Default value is gray-scale, and image is read by YCbCr format as the paper said.
98 | """
99 | if is_grayscale:
100 | return scipy.misc.imread(path, flatten=True, mode='YCbCr').astype(np.float)
101 | else:
102 | return scipy.misc.imread(path, mode='YCbCr').astype(np.float)
103 |
104 | def modcrop(image, scale=3):
105 | """
106 | To scale down and up the original image, first thing to do is to have no remainder while scaling operation.
107 |
108 | We need to find modulo of height (and width) and scale factor.
109 | Then, subtract the modulo from height (and width) of original image size.
110 | There would be no remainder even after scaling operation.
111 | """
112 | if len(image.shape) == 3:
113 | h, w, _ = image.shape
114 | h = h - np.mod(h, scale)
115 | w = w - np.mod(w, scale)
116 | image = image[0:h, 0:w, :]
117 | else:
118 | h, w = image.shape
119 | h = h - np.mod(h, scale)
120 | w = w - np.mod(w, scale)
121 | image = image[0:h, 0:w]
122 | return image
123 |
124 | def input_setup(sess, config):
125 | """
126 | Read image files and make their sub-images and saved them as a h5 file format.
127 | """
128 | # Load data path
129 | if config.is_train:
130 | data = prepare_data(sess, dataset="Train")
131 | else:
132 | data = prepare_data(sess, dataset="Test")
133 |
134 | sub_input_sequence = []
135 | sub_label_sequence = []
136 | padding = abs(config.image_size - config.label_size) / 2 # 6
137 |
138 | if config.is_train:
139 | for i in xrange(len(data)):
140 | input_, label_ = preprocess(data[i], config.scale)
141 |
142 | if len(input_.shape) == 3:
143 | h, w, _ = input_.shape
144 | else:
145 | h, w = input_.shape
146 |
147 | for x in range(0, h-config.image_size+1, config.stride):
148 | for y in range(0, w-config.image_size+1, config.stride):
149 | sub_input = input_[x:x+config.image_size, y:y+config.image_size] # [33 x 33]
150 | sub_label = label_[x+int(padding):x+int(padding)+config.label_size, y+int(padding):y+int(padding)+config.label_size] # [21 x 21]
151 |
152 | # Make channel value
153 | sub_input = sub_input.reshape([config.image_size, config.image_size, 1])
154 | sub_label = sub_label.reshape([config.label_size, config.label_size, 1])
155 |
156 | sub_input_sequence.append(sub_input)
157 | sub_label_sequence.append(sub_label)
158 |
159 | else:
160 | input_, label_ = preprocess(data[2], config.scale)
161 |
162 | if len(input_.shape) == 3:
163 | h, w, _ = input_.shape
164 | else:
165 | h, w = input_.shape
166 |
167 | # Numbers of sub-images in height and width of image are needed to compute merge operation.
168 | nx = ny = 0
169 | for x in range(0, h-config.image_size+1, config.stride):
170 | nx += 1; ny = 0
171 | for y in range(0, w-config.image_size+1, config.stride):
172 | ny += 1
173 | sub_input = input_[x:x+config.image_size, y:y+config.image_size] # [33 x 33]
174 | sub_label = label_[x+int(padding):x+int(padding)+config.label_size, y+int(padding):y+int(padding)+config.label_size] # [21 x 21]
175 |
176 | sub_input = sub_input.reshape([config.image_size, config.image_size, 1])
177 | sub_label = sub_label.reshape([config.label_size, config.label_size, 1])
178 |
179 | sub_input_sequence.append(sub_input)
180 | sub_label_sequence.append(sub_label)
181 |
182 | """
183 | len(sub_input_sequence) : the number of sub_input (33 x 33 x ch) in one image
184 | (sub_input_sequence[0]).shape : (33, 33, 1)
185 | """
186 | # Make list to numpy array. With this transform
187 | arrdata = np.asarray(sub_input_sequence) # [?, 33, 33, 1]
188 | arrlabel = np.asarray(sub_label_sequence) # [?, 21, 21, 1]
189 |
190 | make_data(sess, arrdata, arrlabel)
191 |
192 | if not config.is_train:
193 | return nx, ny
194 |
195 | def imsave(image, path):
196 | return scipy.misc.imsave(path, image)
197 |
198 | def merge(images, size):
199 | h, w = images.shape[1], images.shape[2]
200 | img = np.zeros((h*size[0], w*size[1], 1))
201 | for idx, image in enumerate(images):
202 | i = idx % size[1]
203 | j = idx // size[1]
204 | img[j*h:j*h+h, i*w:i*w+w, :] = image
205 |
206 | return img
207 |
--------------------------------------------------------------------------------