├── Benchmarks ├── BSD100 │ ├── 101085_HR.png │ ├── 101087_HR.png │ ├── 102061_HR.png │ ├── 103070_HR.png │ ├── 105025_HR.png │ ├── 106024_HR.png │ ├── 108005_HR.png │ ├── 108070_HR.png │ ├── 108082_HR.png │ ├── 109053_HR.png │ ├── 119082_HR.png │ ├── 12084_HR.png │ ├── 123074_HR.png │ ├── 126007_HR.png │ ├── 130026_HR.png │ ├── 134035_HR.png │ ├── 14037_HR.png │ ├── 143090_HR.png │ ├── 145086_HR.png │ ├── 147091_HR.png │ ├── 148026_HR.png │ ├── 148089_HR.png │ ├── 156065_HR.png │ ├── 157055_HR.png │ ├── 159008_HR.png │ ├── 160068_HR.png │ ├── 16077_HR.png │ ├── 163085_HR.png │ ├── 167062_HR.png │ ├── 167083_HR.png │ ├── 170057_HR.png │ ├── 175032_HR.png │ ├── 175043_HR.png │ ├── 182053_HR.png │ ├── 189080_HR.png │ ├── 19021_HR.png │ ├── 196073_HR.png │ ├── 197017_HR.png │ ├── 208001_HR.png │ ├── 210088_HR.png │ ├── 21077_HR.png │ ├── 216081_HR.png │ ├── 219090_HR.png │ ├── 220075_HR.png │ ├── 223061_HR.png │ ├── 227092_HR.png │ ├── 229036_HR.png │ ├── 236037_HR.png │ ├── 24077_HR.png │ ├── 241004_HR.png │ ├── 241048_HR.png │ ├── 253027_HR.png │ ├── 253055_HR.png │ ├── 260058_HR.png │ ├── 271035_HR.png │ ├── 285079_HR.png │ ├── 291000_HR.png │ ├── 295087_HR.png │ ├── 296007_HR.png │ ├── 296059_HR.png │ ├── 299086_HR.png │ ├── 300091_HR.png │ ├── 302008_HR.png │ ├── 304034_HR.png │ ├── 304074_HR.png │ ├── 306005_HR.png │ ├── 3096_HR.png │ ├── 33039_HR.png │ ├── 351093_HR.png │ ├── 361010_HR.png │ ├── 37073_HR.png │ ├── 376043_HR.png │ ├── 38082_HR.png │ ├── 38092_HR.png │ ├── 385039_HR.png │ ├── 41033_HR.png │ ├── 41069_HR.png │ ├── 42012_HR.png │ ├── 42049_HR.png │ ├── 43074_HR.png │ ├── 45096_HR.png │ ├── 54082_HR.png │ ├── 55073_HR.png │ ├── 58060_HR.png │ ├── 62096_HR.png │ ├── 65033_HR.png │ ├── 66053_HR.png │ ├── 69015_HR.png │ ├── 69020_HR.png │ ├── 69040_HR.png │ ├── 76053_HR.png │ ├── 78004_HR.png │ ├── 8023_HR.png │ ├── 85048_HR.png │ ├── 86000_HR.png │ ├── 86016_HR.png │ ├── 86068_HR.png │ ├── 87046_HR.png │ ├── 89072_HR.png │ └── 97033_HR.png ├── Set14 │ ├── baboon_HR.png │ ├── barbara_HR.png │ ├── bridge_HR.png │ ├── coastguard_HR.png │ ├── comic_HR.png │ ├── face_HR.png │ ├── flowers_HR.png │ ├── foreman_HR.png │ ├── lenna_HR.png │ ├── man_HR.png │ ├── monarch_HR.png │ ├── pepper_HR.png │ ├── ppt3_HR.png │ └── zebra_HR.png └── Set5 │ ├── baby_HR.png │ ├── bird_HR.png │ ├── butterfly_HR.png │ ├── head_HR.png │ └── woman_HR.png ├── LICENSE ├── README.md ├── benchmark.py ├── srgan.py ├── train.py ├── utilities.py └── vgg19.py /Benchmarks/BSD100/101085_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/101085_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/101087_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/101087_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/102061_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/102061_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/103070_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/103070_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/105025_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/105025_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/106024_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/106024_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/108005_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/108005_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/108070_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/108070_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/108082_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/108082_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/109053_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/109053_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/119082_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/119082_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/12084_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/12084_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/123074_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/123074_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/126007_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/126007_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/130026_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/130026_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/134035_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/134035_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/14037_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/14037_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/143090_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/143090_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/145086_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/145086_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/147091_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/147091_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/148026_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/148026_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/148089_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/148089_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/156065_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/156065_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/157055_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/157055_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/159008_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/159008_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/160068_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/160068_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/16077_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/16077_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/163085_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/163085_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/167062_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/167062_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/167083_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/167083_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/170057_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/170057_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/175032_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/175032_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/175043_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/175043_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/182053_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/182053_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/189080_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/189080_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/19021_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/19021_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/196073_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/196073_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/197017_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/197017_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/208001_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/208001_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/210088_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/210088_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/21077_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/21077_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/216081_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/216081_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/219090_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/219090_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/220075_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/220075_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/223061_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/223061_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/227092_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/227092_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/229036_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/229036_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/236037_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/236037_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/24077_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/24077_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/241004_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/241004_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/241048_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/241048_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/253027_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/253027_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/253055_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/253055_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/260058_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/260058_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/271035_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/271035_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/285079_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/285079_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/291000_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/291000_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/295087_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/295087_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/296007_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/296007_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/296059_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/296059_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/299086_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/299086_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/300091_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/300091_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/302008_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/302008_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/304034_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/304034_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/304074_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/304074_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/306005_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/306005_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/3096_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/3096_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/33039_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/33039_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/351093_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/351093_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/361010_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/361010_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/37073_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/37073_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/376043_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/376043_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/38082_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/38082_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/38092_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/38092_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/385039_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/385039_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/41033_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/41033_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/41069_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/41069_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/42012_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/42012_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/42049_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/42049_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/43074_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/43074_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/45096_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/45096_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/54082_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/54082_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/55073_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/55073_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/58060_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/58060_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/62096_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/62096_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/65033_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/65033_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/66053_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/66053_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/69015_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/69015_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/69020_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/69020_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/69040_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/69040_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/76053_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/76053_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/78004_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/78004_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/8023_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/8023_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/85048_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/85048_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/86000_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/86000_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/86016_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/86016_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/86068_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/86068_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/87046_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/87046_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/89072_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/89072_HR.png -------------------------------------------------------------------------------- /Benchmarks/BSD100/97033_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/BSD100/97033_HR.png -------------------------------------------------------------------------------- /Benchmarks/Set14/baboon_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/Set14/baboon_HR.png -------------------------------------------------------------------------------- /Benchmarks/Set14/barbara_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/Set14/barbara_HR.png -------------------------------------------------------------------------------- /Benchmarks/Set14/bridge_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/Set14/bridge_HR.png -------------------------------------------------------------------------------- /Benchmarks/Set14/coastguard_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/Set14/coastguard_HR.png -------------------------------------------------------------------------------- /Benchmarks/Set14/comic_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/Set14/comic_HR.png -------------------------------------------------------------------------------- /Benchmarks/Set14/face_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/Set14/face_HR.png -------------------------------------------------------------------------------- /Benchmarks/Set14/flowers_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/Set14/flowers_HR.png -------------------------------------------------------------------------------- /Benchmarks/Set14/foreman_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/Set14/foreman_HR.png -------------------------------------------------------------------------------- /Benchmarks/Set14/lenna_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/Set14/lenna_HR.png -------------------------------------------------------------------------------- /Benchmarks/Set14/man_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/Set14/man_HR.png -------------------------------------------------------------------------------- /Benchmarks/Set14/monarch_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/Set14/monarch_HR.png -------------------------------------------------------------------------------- /Benchmarks/Set14/pepper_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/Set14/pepper_HR.png -------------------------------------------------------------------------------- /Benchmarks/Set14/ppt3_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/Set14/ppt3_HR.png -------------------------------------------------------------------------------- /Benchmarks/Set14/zebra_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/Set14/zebra_HR.png -------------------------------------------------------------------------------- /Benchmarks/Set5/baby_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/Set5/baby_HR.png -------------------------------------------------------------------------------- /Benchmarks/Set5/bird_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/Set5/bird_HR.png -------------------------------------------------------------------------------- /Benchmarks/Set5/butterfly_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/Set5/butterfly_HR.png -------------------------------------------------------------------------------- /Benchmarks/Set5/head_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/Set5/head_HR.png -------------------------------------------------------------------------------- /Benchmarks/Set5/woman_HR.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/trevor-m/tensorflow-SRGAN/21d43e595ae8699a7ab66665d4990df7fbaa9497/Benchmarks/Set5/woman_HR.png -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Trevor Morris 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 | # SRGan in Tensorflow 2 | 3 | This is an implementation of the paper [Photo-Realistic Single Image Super-Resolution Using a Generative Adversarial Network](https://arxiv.org/abs/1609.04802) using TensorFlow. 4 | 5 | ## Usage 6 | 7 | ### Set up 8 | 9 | 1. Download the VGG19 weights provided by [TensorFlow-Slim](http://download.tensorflow.org/models/vgg_19_2016_08_28.tar.gz). Place the vgg_19.ckpt file in this directory. 10 | 2. Download a dataset of images. I recommend [ImageNet](http://image-net.org/challenges/LSVRC/2014/index) or [Places205](http://places.csail.mit.edu/index.html). Specify the directory containing your dataset using the `--train-dir` argument when training the model. 11 | 12 | ### Training 13 | 14 | SRResNet-MSE 15 | ``` 16 | python train.py --name srresnet-mse --content-loss mse --train-dir path/to/dataset 17 | ``` 18 | 19 | SRResNet-VGG22 20 | ``` 21 | python train.py --name srresnet-vgg22 --content-loss vgg22 --train-dir path/to/dataset 22 | ``` 23 | 24 | SRGAN-MSE 25 | ``` 26 | python train.py --name srgan-mse --use-gan --content-loss mse --train-dir path/to/dataset --load results/srresnet-mse/weights-1000000 27 | ``` 28 | 29 | SRGAN-VGG22 30 | ``` 31 | python train.py --name srgan-vgg22 --use-gan --content-loss vgg22 --train-dir path/to/dataset --load results/srresnet-mse/weights-1000000 32 | ``` 33 | 34 | SRGAN-VGG54 35 | ``` 36 | python train.py --name srgan-vgg54 --use-gan --content-loss vgg54 --train-dir path/to/dataset --load results/srresnet-mse/weights-1000000 37 | ``` 38 | 39 | ## Results 40 | | **Set5** | Ledig SRResNet | This SRResNet | Ledig SRGAN | This SRGAN | 41 | | --- | --- | --- | --- | --- | 42 | | PSNR | 32.05 | 32.11 | 29.40 | 28.21 | 43 | | SSIM | 0.9019| 0.8933 | 0.8472 | 0.8200 | 44 | 45 | | **Set14** | Ledig SRResNet | This SRResNet | Ledig SRGAN | This SRGAN | 46 | | --- | --- | --- | --- | --- | 47 | | PSNR | 28.49 | 28.61 | 26.02 | 25.74 | 48 | | SSIM | 0.8184| 0.7809 | 0.7397 | 0.6909 | 49 | 50 | | **BSD100** | Ledig SRResNet | This SRResNet | Ledig SRGAN | This SRGAN | 51 | | --- | --- | --- | --- | --- | 52 | | PSNR | 27.58 | 27.57 | 25.16 | 24.80 | 53 | | SSIM | 0.7620 | 0.7346 | 0.6688 | 0.6314 | 54 | -------------------------------------------------------------------------------- /benchmark.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import glob 3 | import os 4 | from scipy import misc 5 | from skimage.measure import compare_ssim 6 | from skimage.color import rgb2ycbcr,rgb2yuv 7 | 8 | from skimage.measure import compare_psnr 9 | from utilities import preprocess, downsample 10 | 11 | class Benchmark: 12 | """A collection of images to test a model on.""" 13 | 14 | def __init__(self, path, name): 15 | self.path = path 16 | self.name = name 17 | #self.images_lr, self.names = self.load_images_by_model(model='LR') 18 | self.images_hr, self.names = self.load_images_by_model(model='HR') 19 | self.images_lr = [] 20 | for img in self.images_hr: 21 | self.images_lr.append(downsample(img, 4)) 22 | 23 | def load_images_by_model(self, model, file_format='png'): 24 | """Loads all images that match '*_{model}.{file_format}' and returns sorted list of filenames and names""" 25 | # Get files that match the pattern 26 | filenames = sorted(glob.glob(os.path.join(self.path, '*_' + model + '.' + file_format))) 27 | # Extract name/prefix eg: '/.../baby_LR.png' -> 'baby' 28 | names = [os.path.basename(x).split('_')[0] for x in filenames] 29 | return self.load_images(filenames), names 30 | 31 | def load_images(self, images): 32 | """Given a list of file names, return a list of images""" 33 | out = [] 34 | for image in images: 35 | out.append(misc.imread(image, mode='RGB').astype(np.uint8)) 36 | return out 37 | 38 | def deprocess(self, image): 39 | """Deprocess image output by model (from -1 to 1 float to 0 to 255 uint8)""" 40 | image = np.clip(255 * 0.5 * (image + 1.0), 0.0, 255.0).astype(np.uint8) 41 | return image 42 | 43 | def luminance(self, image): 44 | # Get luminance 45 | lum = rgb2ycbcr(image)[:,:,0] 46 | # Crop off 4 border pixels 47 | lum = lum[4:lum.shape[0]-4, 4:lum.shape[1]-4] 48 | #lum = lum.astype(np.float64) 49 | return lum 50 | 51 | def PSNR(self, gt, pred): 52 | #gt = gt.astype(np.float64) 53 | #pred = pred.astype(np.float64) 54 | #mse = np.mean((pred - gt)**2) 55 | #psnr = 10*np.log10(255*255/mse) 56 | #return psnr 57 | return compare_psnr(gt, pred, data_range=255) 58 | 59 | def SSIM(self, gt, pred): 60 | ssim = compare_ssim(gt, pred, data_range=255, gaussian_weights=True) 61 | return ssim 62 | 63 | def test_images(self, gt, pred): 64 | """Applies metrics to compare image lists pred vs gt""" 65 | avg_psnr = 0 66 | avg_ssim = 0 67 | individual_psnr = [] 68 | individual_ssim = [] 69 | 70 | for i in range(len(pred)): 71 | # compare to gt 72 | psnr = self.PSNR(self.luminance(gt[i]), self.luminance(pred[i])) 73 | ssim = self.SSIM(self.luminance(gt[i]), self.luminance(pred[i])) 74 | # save results to log_path ex: 'results/experiment1/Set5/baby/1000.png' 75 | #if save_images: 76 | # path = os.path.join(log_path, self.name, self.names[i]) 77 | # gather results 78 | individual_psnr.append(psnr) 79 | individual_ssim.append(ssim) 80 | avg_psnr += psnr 81 | avg_ssim += ssim 82 | 83 | avg_psnr /= len(pred) 84 | avg_ssim /= len(pred) 85 | return avg_psnr, avg_ssim, individual_psnr, individual_ssim 86 | 87 | def validate(self): 88 | """Tests metrics by using images output by other models""" 89 | for model in ['bicubic', 'SRGAN-MSE', 'SRGAN-VGG22', 'SRGAN-VGG54', 'SRResNet-MSE', 'SRResNet-VGG22']: 90 | model_output,_ = self.load_images_by_model(model) 91 | psnr, ssim, _, _ = self.test_images(self.images_hr, model_output) 92 | print('Validate %-6s for %-14s: PSNR: %.2f, SSIM: %.4f' % (self.name, model, psnr, ssim)) 93 | 94 | def save_image(self, image, path): 95 | if not os.path.exists(os.path.split(path)[0]): 96 | os.makedirs(os.path.split(path)[0]) 97 | misc.toimage(image, cmin=0, cmax=255).save(path) 98 | 99 | def save_images(self, images, log_path, iteration): 100 | count = 0 101 | for output, lr, hr, name in zip(images, self.images_lr, self.images_hr, self.names): 102 | # Save output 103 | path = os.path.join(log_path, self.name, name, '%d_out.png' % iteration) 104 | self.save_image(output, path) 105 | # Save ground truth 106 | path = os.path.join(log_path, self.name, name, '%d_hr.png' % iteration) 107 | self.save_image(hr, path) 108 | # Save low res 109 | path = os.path.join(log_path, self.name, name, '%d_lr.png' % iteration) 110 | self.save_image(lr, path) 111 | 112 | # Hack so that we only do first 14 images in BSD100 instead of the whole thing 113 | count += 1 114 | if count >= 14: 115 | break 116 | 117 | def evaluate(self, sess, g_y_pred, log_path=None, iteration=0): 118 | """Evaluate benchmark, returning the score and saving images.""" 119 | pred = [] 120 | for i, lr in enumerate(self.images_lr): 121 | # feed images 1 by 1 because they have different sizes 122 | lr = lr / 255.0 123 | output = sess.run(g_y_pred, feed_dict={'d_training:0': False, 'g_training:0': False, 'input_lowres:0': lr[np.newaxis]}) 124 | # deprocess output 125 | pred.append(self.deprocess(np.squeeze(output, axis=0))) 126 | # save images 127 | if log_path: 128 | self.save_images(pred, log_path, iteration) 129 | return self.test_images(self.images_hr, pred) 130 | -------------------------------------------------------------------------------- /srgan.py: -------------------------------------------------------------------------------- 1 | import tensorflow as tf 2 | from vgg19 import vgg_19 3 | 4 | class SRGanGenerator: 5 | """SRGAN Generator Model from Ledig et. al. 2017 6 | 7 | Reference: https://arxiv.org/pdf/1609.04802.pdf 8 | """ 9 | def __init__(self, discriminator, training, content_loss='mse', use_gan=True, learning_rate=1e-4, num_blocks=16, num_upsamples=2): 10 | self.learning_rate = learning_rate 11 | self.num_blocks = num_blocks 12 | self.num_upsamples = num_upsamples 13 | self.use_gan = use_gan 14 | self.discriminator = discriminator 15 | self.training = training 16 | self.reuse_vgg = False 17 | if content_loss not in ['mse', 'L1', 'vgg22', 'vgg54']: 18 | print('Invalid content loss function. Must be \'mse\', \'vgg22\', or \'vgg54\'.') 19 | exit() 20 | self.content_loss = content_loss 21 | 22 | def ResidualBlock(self, x, kernel_size, filters, strides=1): 23 | """Residual block a la ResNet""" 24 | skip = x 25 | x = tf.layers.conv2d(x, kernel_size=kernel_size, filters=filters, strides=strides, padding='same', use_bias=False) 26 | x = tf.layers.batch_normalization(x, training=self.training) 27 | x = tf.contrib.keras.layers.PReLU(shared_axes=[1,2])(x) 28 | x = tf.layers.conv2d(x, kernel_size=kernel_size, filters=filters, strides=strides, padding='same', use_bias=False) 29 | x = tf.layers.batch_normalization(x, training=self.training) 30 | x = x + skip 31 | return x 32 | 33 | def Upsample2xBlock(self, x, kernel_size, filters, strides=1): 34 | """Upsample 2x via SubpixelConv""" 35 | x = tf.layers.conv2d(x, kernel_size=kernel_size, filters=filters, strides=strides, padding='same') 36 | x = tf.depth_to_space(x, 2) 37 | x = tf.contrib.keras.layers.PReLU(shared_axes=[1,2])(x) 38 | return x 39 | 40 | def forward(self, x): 41 | """Builds the forward pass network graph""" 42 | with tf.variable_scope('generator') as scope: 43 | x = tf.layers.conv2d(x, kernel_size=9, filters=64, strides=1, padding='same') 44 | x = tf.contrib.keras.layers.PReLU(shared_axes=[1,2])(x) 45 | skip = x 46 | 47 | # B x ResidualBlocks 48 | for i in range(self.num_blocks): 49 | x = self.ResidualBlock(x, kernel_size=3, filters=64, strides=1) 50 | 51 | x = tf.layers.conv2d(x, kernel_size=3, filters=64, strides=1, padding='same', use_bias=False) 52 | x = tf.layers.batch_normalization(x, training=self.training) 53 | x = x + skip 54 | 55 | # Upsample blocks 56 | for i in range(self.num_upsamples): 57 | x = self.Upsample2xBlock(x, kernel_size=3, filters=256) 58 | 59 | x = tf.layers.conv2d(x, kernel_size=9, filters=3, strides=1, padding='same', name='forward') 60 | return x 61 | 62 | def vgg_forward(self, x, layer, scope): 63 | # apply vgg preprocessing 64 | # move to range 0-255 65 | x = 255.0 * (0.5 * (x + 1.0)) 66 | # subtract means 67 | mean = tf.constant([123.68, 116.779, 103.939], dtype=tf.float32, shape=[1, 1, 1, 3], name='img_mean') # RGB means from VGG paper 68 | x = x - mean 69 | # convert to BGR 70 | x = x[:,:,:,::-1] 71 | # send through vgg19 72 | _,layers = vgg_19(x, is_training=False, reuse=self.reuse_vgg) 73 | self.reuse_vgg = True 74 | return layers[scope + layer] 75 | 76 | def _content_loss(self, y, y_pred): 77 | """MSE, VGG22, or VGG54""" 78 | if self.content_loss == 'mse': 79 | return tf.reduce_mean(tf.square(y - y_pred)) 80 | if self.content_loss == 'L1': 81 | return tf.reduce_mean(tf.abs(y - y_pred)) 82 | if self.content_loss == 'vgg22': 83 | with tf.name_scope('vgg19_1') as scope: 84 | vgg_y = self.vgg_forward(y, 'vgg_19/conv2/conv2_2', scope) 85 | with tf.name_scope('vgg19_2') as scope: 86 | vgg_y_pred = self.vgg_forward(y_pred, 'vgg_19/conv2/conv2_2', scope) 87 | return 0.006*tf.reduce_mean(tf.square(vgg_y - vgg_y_pred)) + 2e-8*tf.reduce_sum(tf.image.total_variation(y_pred)) 88 | 89 | if self.content_loss == 'vgg54': 90 | with tf.name_scope('vgg19_1') as scope: 91 | vgg_y = self.vgg_forward(y, 'vgg_19/conv5/conv5_4', scope) 92 | with tf.name_scope('vgg19_2') as scope: 93 | vgg_y_pred = self.vgg_forward(y_pred, 'vgg_19/conv5/conv5_4', scope) 94 | return 0.006*tf.reduce_mean(tf.square(vgg_y - vgg_y_pred)) 95 | 96 | def _adversarial_loss(self, y_pred): 97 | """For GAN.""" 98 | y_discrim, y_discrim_logits = self.discriminator.forward(y_pred) 99 | return tf.reduce_mean(tf.nn.sigmoid_cross_entropy_with_logits(logits=y_discrim_logits, labels=tf.ones_like(y_discrim_logits))) 100 | 101 | def loss_function(self, y, y_pred): 102 | """Loss function""" 103 | if self.use_gan: 104 | # Weighted sum of content loss and adversarial loss 105 | return self._content_loss(y, y_pred) + 1e-3*self._adversarial_loss(y_pred) 106 | # Content loss only 107 | return self._content_loss(y, y_pred) 108 | 109 | def optimize(self, loss): 110 | #tf.control_dependencies([discrim_train 111 | # update_ops needs to be here for batch normalization to work 112 | update_ops = tf.get_collection(tf.GraphKeys.UPDATE_OPS, scope='generator') 113 | with tf.control_dependencies(update_ops): 114 | return tf.train.AdamOptimizer(self.learning_rate).minimize(loss, var_list=tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES, scope='generator')) 115 | 116 | 117 | class SRGanDiscriminator: 118 | """SRGAN Discriminator Model from Ledig et. al. 2017 119 | 120 | Reference: https://arxiv.org/pdf/1609.04802.pdf 121 | """ 122 | def __init__(self, training, learning_rate=1e-4, image_size=96): 123 | self.graph_created = False 124 | self.learning_rate = learning_rate 125 | self.training = training 126 | self.image_size = image_size 127 | 128 | def ConvolutionBlock(self, x, kernel_size, filters, strides): 129 | """Conv2D + BN + LeakyReLU""" 130 | x = tf.layers.conv2d(x, kernel_size=kernel_size, filters=filters, strides=strides, padding='same', use_bias=False) 131 | x = tf.layers.batch_normalization(x, training=self.training) 132 | x = tf.contrib.keras.layers.LeakyReLU(alpha=0.2)(x) 133 | return x 134 | 135 | def forward(self, x): 136 | """Builds the forward pass network graph""" 137 | with tf.variable_scope('discriminator') as scope: 138 | # Reuse variables when graph is applied again 139 | if self.graph_created: 140 | scope.reuse_variables() 141 | self.graph_created = True 142 | 143 | # Image dimensions are fixed to the training size because of the FC layer 144 | x.set_shape([None, self.image_size, self.image_size, 3]) 145 | 146 | x = tf.layers.conv2d(x, kernel_size=3, filters=64, strides=1, padding='same') 147 | x = tf.contrib.keras.layers.LeakyReLU(alpha=0.2)(x) 148 | 149 | x = self.ConvolutionBlock(x, 3, 64, 2) 150 | x = self.ConvolutionBlock(x, 3, 128, 1) 151 | x = self.ConvolutionBlock(x, 3, 128, 2) 152 | x = self.ConvolutionBlock(x, 3, 256, 1) 153 | x = self.ConvolutionBlock(x, 3, 256, 2) 154 | x = self.ConvolutionBlock(x, 3, 512, 1) 155 | x = self.ConvolutionBlock(x, 3, 512, 2) 156 | 157 | x = tf.contrib.layers.flatten(x) 158 | x = tf.layers.dense(x, 1024) 159 | x = tf.contrib.keras.layers.LeakyReLU(alpha=0.2)(x) 160 | logits = tf.layers.dense(x, 1) 161 | x = tf.sigmoid(logits) 162 | return x, logits 163 | 164 | def loss_function(self, y_real_pred, y_fake_pred, y_real_pred_logits, y_fake_pred_logits): 165 | """Discriminator wants to maximize log(y_real) + log(1-y_fake).""" 166 | loss_real = tf.reduce_mean(tf.losses.sigmoid_cross_entropy(tf.ones_like(y_real_pred_logits), y_real_pred_logits)) 167 | loss_fake = tf.reduce_mean(tf.losses.sigmoid_cross_entropy(tf.zeros_like(y_fake_pred_logits), y_fake_pred_logits)) 168 | return loss_real + loss_fake 169 | 170 | def optimize(self, loss): 171 | update_ops = tf.get_collection(tf.GraphKeys.UPDATE_OPS, scope='discriminator') 172 | with tf.control_dependencies(update_ops): 173 | return tf.train.AdamOptimizer(self.learning_rate).minimize(loss, var_list=tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES, scope='discriminator')) 174 | -------------------------------------------------------------------------------- /train.py: -------------------------------------------------------------------------------- 1 | """Training program for SRGAN implementation. 2 | 3 | Benchmark data sets provided by the paper are available here: https://twitter.app.box.com/s/lcue6vlrd01ljkdtdkhmfvk7vtjhetog 4 | """ 5 | import tensorflow as tf 6 | from tensorflow.python.training import queue_runner 7 | import numpy as np 8 | import argparse 9 | import srgan 10 | from benchmark import Benchmark 11 | import os 12 | import sys 13 | from utilities import build_inputs, downsample_batch, build_log_dir, preprocess, evaluate_model, test_examples 14 | 15 | def main(): 16 | parser = argparse.ArgumentParser() 17 | parser.add_argument('--load', type=str, help='Checkpoint to load all weights from.') 18 | parser.add_argument('--load-gen', type=str, help='Checkpoint to load generator weights only from.') 19 | parser.add_argument('--name', type=str, help='Name of experiment.') 20 | parser.add_argument('--overfit', action='store_true', help='Overfit to a single image.') 21 | parser.add_argument('--batch-size', type=int, default=16, help='Mini-batch size.') 22 | parser.add_argument('--log-freq', type=int, default=10000, help='How many training iterations between validation/checkpoints.') 23 | parser.add_argument('--learning-rate', type=float, default=1e-4, help='Learning rate for Adam.') 24 | parser.add_argument('--content-loss', type=str, default='mse', choices=['mse', 'vgg22', 'vgg54'], help='Metric to use for content loss.') 25 | parser.add_argument('--use-gan', action='store_true', help='Add adversarial loss term to generator and trains discriminator.') 26 | parser.add_argument('--image-size', type=int, default=96, help='Size of random crops used for training samples.') 27 | parser.add_argument('--vgg-weights', type=str, default='vgg_19.ckpt', help='File containing VGG19 weights (tf.slim)') 28 | parser.add_argument('--train-dir', type=str, help='Directory containing training images') 29 | parser.add_argument('--validate-benchmarks', action='store_true', help='If set, validates that the benchmarking metrics are correct for the images provided by the authors of the SRGAN paper.') 30 | parser.add_argument('--gpu', type=str, default='0', help='Which GPU to use') 31 | args = parser.parse_args() 32 | os.environ['CUDA_VISIBLE_DEVICES'] = args.gpu 33 | 34 | # Set up models 35 | d_training = tf.placeholder(tf.bool, name='d_training') 36 | g_training = tf.placeholder(tf.bool, name='g_training') 37 | discriminator = srgan.SRGanDiscriminator(training=g_training, image_size=args.image_size) 38 | generator = srgan.SRGanGenerator(discriminator=discriminator, training=d_training, learning_rate=args.learning_rate, content_loss=args.content_loss, use_gan=args.use_gan) 39 | # Generator 40 | g_x = tf.placeholder(tf.float32, [None, None, None, 3], name='input_lowres') 41 | g_y = tf.placeholder(tf.float32, [None, None, None, 3], name='input_highres') 42 | g_y_pred = generator.forward(g_x) 43 | g_loss = generator.loss_function(g_y, g_y_pred) 44 | g_train_step = generator.optimize(g_loss) 45 | # Discriminator 46 | d_x_real = tf.placeholder(tf.float32, [None, None, None, 3], name='input_real') 47 | d_y_real_pred, d_y_real_pred_logits = discriminator.forward(d_x_real) 48 | d_y_fake_pred, d_y_fake_pred_logits = discriminator.forward(g_y_pred) 49 | d_loss = discriminator.loss_function(d_y_real_pred, d_y_fake_pred, d_y_real_pred_logits, d_y_fake_pred_logits) 50 | d_train_step = discriminator.optimize(d_loss) 51 | 52 | # Set up benchmarks 53 | benchmarks = [Benchmark('Benchmarks/Set5', name='Set5'), 54 | Benchmark('Benchmarks/Set14', name='Set14'), 55 | Benchmark('Benchmarks/BSD100', name='BSD100')] 56 | if args.validate_benchmarks: 57 | for benchmark in benchmarks: 58 | benchmark.validate() 59 | 60 | # Create log folder 61 | if args.load and not args.name: 62 | log_path = os.path.dirname(args.load) 63 | else: 64 | log_path = build_log_dir(args, sys.argv) 65 | 66 | with tf.Session() as sess: 67 | # Build input pipeline 68 | get_train_batch, get_val_batch, get_eval_batch = build_inputs(args, sess) 69 | # Initialize 70 | sess.run(tf.local_variables_initializer()) 71 | sess.run(tf.global_variables_initializer()) 72 | # Start input pipeline thread(s) 73 | coord = tf.train.Coordinator() 74 | threads = tf.train.start_queue_runners(sess=sess, coord=coord) 75 | 76 | # Load saved weights 77 | iteration = 0 78 | saver = tf.train.Saver() 79 | # Load generator 80 | if args.load_gen: 81 | gen_saver = tf.train.Saver(tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES, scope='generator')) 82 | iteration = int(args.load_gen.split('-')[-1]) 83 | gen_saver.restore(sess, args.load_gen) 84 | # Load all 85 | if args.load: 86 | iteration = int(args.load.split('-')[-1]) 87 | saver.restore(sess, args.load) 88 | # Load VGG 89 | if 'vgg' in args.content_loss: 90 | vgg_saver = tf.train.Saver(tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES, scope='vgg_19')) 91 | vgg_saver.restore(sess, args.vgg_weights) 92 | 93 | # Train 94 | while True: 95 | if iteration % args.log_freq == 0: 96 | # Test every log-freq iterations 97 | val_error = evaluate_model(g_loss, get_val_batch, sess, 119, args.batch_size) 98 | eval_error = evaluate_model(g_loss, get_eval_batch, sess, 119, args.batch_size) 99 | # Log error 100 | print('[%d] Test: %.7f, Train: %.7f' % (iteration, val_error, eval_error), end='') 101 | # Evaluate benchmarks 102 | log_line = '' 103 | for benchmark in benchmarks: 104 | psnr, ssim, _, _ = benchmark.evaluate(sess, g_y_pred, log_path, iteration) 105 | print(' [%s] PSNR: %.2f, SSIM: %.4f' %( benchmark.name, psnr, ssim), end='') 106 | log_line += ',%.7f, %.7f' %(psnr, ssim) 107 | print() 108 | # Write to log 109 | with open(log_path + '/loss.csv', 'a') as f: 110 | f.write('%d, %.15f, %.15f%s\n' % (iteration, val_error, eval_error, log_line)) 111 | # Save checkpoint 112 | saver.save(sess, os.path.join(log_path, 'weights'), global_step=iteration, write_meta_graph=False) 113 | 114 | # Train discriminator 115 | if args.use_gan: 116 | batch_hr = sess.run(get_train_batch) 117 | batch_lr = downsample_batch(batch_hr, factor=4) 118 | batch_lr, batch_hr = preprocess(batch_lr, batch_hr) 119 | sess.run(d_train_step, feed_dict={d_training: True, g_training: True, g_x: batch_lr, g_y: batch_hr, d_x_real: batch_hr}) 120 | # Train generator 121 | batch_hr = sess.run(get_train_batch) 122 | batch_lr = downsample_batch(batch_hr, factor=4) 123 | batch_lr, batch_hr = preprocess(batch_lr, batch_hr) 124 | sess.run(g_train_step, feed_dict={d_training: True, g_training: True, g_x: batch_lr, g_y: batch_hr}) 125 | 126 | iteration += 1 127 | 128 | # Stop queue threads 129 | coord.request_stop() 130 | coord.join(threads) 131 | 132 | 133 | if __name__ == "__main__": 134 | main() 135 | -------------------------------------------------------------------------------- /utilities.py: -------------------------------------------------------------------------------- 1 | import tensorflow as tf 2 | import numpy as np 3 | import pickle 4 | import skimage.transform 5 | import skimage.filters 6 | import datetime 7 | import os 8 | import shutil 9 | import math 10 | from scipy import misc 11 | import scipy.ndimage 12 | import glob 13 | 14 | def process_individual_image(filename_queue, img_size, random_crop=False): 15 | """Individual loading & processing for each image""" 16 | image_file = tf.read_file(filename_queue) 17 | image = tf.image.decode_image(image_file, 3) 18 | if random_crop: 19 | # for training, take a random crop of the image 20 | image_shape = tf.shape(image) 21 | # if smaller than img_size, pad with 0s to prevent error 22 | image = tf.image.pad_to_bounding_box(image, 0, 0, tf.maximum(img_size, image_shape[0]), tf.maximum(img_size, image_shape[1])) 23 | image = tf.random_crop(image, size=[img_size, img_size, 3]) 24 | image.set_shape((img_size, img_size, 3)) 25 | else: 26 | # for testing, always take a center crop of the image 27 | image = tf.image.resize_image_with_crop_or_pad(image, img_size, img_size) 28 | image.set_shape((img_size, img_size, 3)) 29 | return image 30 | 31 | def build_input_pipeline(filenames, batch_size, img_size, random_crop=False, shuffle=True, num_threads=1): 32 | """Builds a tensor which provides randomly sampled pictures from the list of filenames provided""" 33 | train_file_list = tf.constant(filenames) 34 | filename_queue = tf.train.string_input_producer(train_file_list, shuffle=shuffle) 35 | image = process_individual_image(filename_queue.dequeue(), img_size, random_crop) 36 | image_batch = tf.train.batch([image], batch_size=batch_size, 37 | num_threads=num_threads, 38 | capacity=10 * batch_size) 39 | return image_batch 40 | 41 | def build_inputs(args, sess): 42 | if args.overfit: 43 | # Overfit to a single image 44 | train_filenames = np.array(['overfit.png']) 45 | val_filenames = np.array(['overfit.png']) 46 | eval_filenames = np.array(['overfit.png']) 47 | #args.batch_size = 1 48 | args.num_test = 1 49 | else: 50 | # Regular dataset 51 | train_filenames = np.array(glob.glob(os.path.join(args.train_dir, '**', '*.*'), recursive=True)) 52 | val_filenames = np.array(glob.glob(os.path.join('Benchmarks', '**', '*_HR.png'), recursive=True)) 53 | eval_indices = np.random.randint(len(train_filenames), size=len(val_filenames)) 54 | eval_filenames = train_filenames[eval_indices[:119]] 55 | 56 | # Create input pipelines 57 | get_train_batch = build_input_pipeline(train_filenames, batch_size=args.batch_size, img_size=args.image_size, random_crop=True) 58 | get_val_batch = build_input_pipeline(val_filenames, batch_size=args.batch_size, img_size=args.image_size) 59 | get_eval_batch = build_input_pipeline(eval_filenames, batch_size=args.batch_size, img_size=args.image_size) 60 | return get_train_batch, get_val_batch, get_eval_batch 61 | 62 | def downsample(image, factor): 63 | """Downsampling function which matches photoshop""" 64 | return scipy.misc.imresize(image, 1.0/factor, interp='bicubic') 65 | 66 | def downsample_batch(batch, factor): 67 | downsampled = np.zeros((batch.shape[0], batch.shape[1]//factor, batch.shape[2]//factor, 3)) 68 | for i in range(batch.shape[0]): 69 | downsampled[i,:,:,:] = downsample(batch[i,:,:,:], factor) 70 | return downsampled 71 | 72 | def build_log_dir(args, arguments): 73 | """Set up a timestamped directory for results and logs for this training session""" 74 | if args.name: 75 | log_path = args.name #(name + '_') if name else '' 76 | else: 77 | log_path = datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S') 78 | log_path = os.path.join('results', log_path) 79 | if not os.path.exists(log_path): 80 | os.makedirs(log_path) 81 | print('Logging results for this session in folder "%s".' % log_path) 82 | # Output csv header 83 | with open(log_path + '/loss.csv', 'a') as f: 84 | f.write('iteration, val_error, eval_error, set5_psnr, set5_ssim, set14_psnr, set14_ssim, bsd100_psnr, bsd100_ssim\n') 85 | # Copy this code to folder 86 | shutil.copy2('srgan.py', os.path.join(log_path, 'srgan.py')) 87 | shutil.copy2('train.py', os.path.join(log_path, 'train.py')) 88 | shutil.copy2('utilities.py', os.path.join(log_path, 'utilities.py')) 89 | # Write command line arguments to file 90 | with open(log_path + '/args.txt', 'w+') as f: 91 | f.write(' '.join(arguments)) 92 | return log_path 93 | 94 | def preprocess(lr, hr): 95 | """Preprocess lr and hr batch""" 96 | lr = lr / 255.0 97 | hr = (hr / 255.0) * 2.0 - 1.0 98 | return lr, hr 99 | 100 | def save_image(path, data, highres=False): 101 | # transform from [-1, 1] to [0, 1] 102 | if highres: 103 | data = (data + 1.0) * 0.5 104 | # transform from [0, 1] to [0, 255], clip, and convert to uint8 105 | data = np.clip(data * 255.0, 0.0, 255.0).astype(np.uint8) 106 | misc.toimage(data, cmin=0, cmax=255).save(path) 107 | 108 | def evaluate_model(loss_function, get_batch, sess, num_images, batch_size): 109 | """Tests the model over all num_images using input tensor get_batch""" 110 | loss = 0 111 | total = 0 112 | for i in range(int(math.ceil(num_images/batch_size))): 113 | batch_hr = sess.run(get_batch) 114 | batch_lr = downsample_batch(batch_hr, factor=4) 115 | batch_lr, batch_hr = preprocess(batch_lr, batch_hr) 116 | loss += sess.run(loss_function, feed_dict={'g_training:0': False, 'd_training:0': False, 'input_lowres:0': batch_lr, 'input_highres:0':batch_hr}) 117 | total += 1 118 | loss = loss / total 119 | return loss 120 | -------------------------------------------------------------------------------- /vgg19.py: -------------------------------------------------------------------------------- 1 | import tensorflow as tf 2 | import tensorflow.contrib.slim as slim 3 | 4 | # VGG19 net 5 | def vgg_19(inputs, 6 | num_classes=1000, 7 | is_training=False, 8 | dropout_keep_prob=0.5, 9 | spatial_squeeze=True, 10 | scope='vgg_19', 11 | reuse = False, 12 | fc_conv_padding='VALID'): 13 | """Oxford Net VGG 19-Layers version E Example. 14 | Note: All the fully_connected layers have been transformed to conv2d layers. 15 | To use in classification mode, resize input to 224x224. 16 | Args: 17 | inputs: a tensor of size [batch_size, height, width, channels]. 18 | num_classes: number of predicted classes. 19 | is_training: whether or not the model is being trained. 20 | dropout_keep_prob: the probability that activations are kept in the dropout 21 | layers during training. 22 | spatial_squeeze: whether or not should squeeze the spatial dimensions of the 23 | outputs. Useful to remove unnecessary dimensions for classification. 24 | scope: Optional scope for the variables. 25 | fc_conv_padding: the type of padding to use for the fully connected layer 26 | that is implemented as a convolutional layer. Use 'SAME' padding if you 27 | are applying the network in a fully convolutional manner and want to 28 | get a prediction map downsampled by a factor of 32 as an output. Otherwise, 29 | the output prediction map will be (input / 32) - 6 in case of 'VALID' padding. 30 | Returns: 31 | the last op containing the log predictions and end_points dict. 32 | """ 33 | with tf.variable_scope(scope, 'vgg_19', [inputs], reuse=reuse) as sc: 34 | end_points_collection = sc.name + '_end_points' 35 | # Collect outputs for conv2d, fully_connected and max_pool2d. 36 | with slim.arg_scope([slim.conv2d, slim.fully_connected, slim.max_pool2d], 37 | outputs_collections=end_points_collection): 38 | net = slim.repeat(inputs, 2, slim.conv2d, 64, 3, scope='conv1', reuse=reuse) 39 | net = slim.max_pool2d(net, [2, 2], scope='pool1') 40 | net = slim.repeat(net, 2, slim.conv2d, 128, 3, scope='conv2',reuse=reuse) 41 | net = slim.max_pool2d(net, [2, 2], scope='pool2') 42 | net = slim.repeat(net, 4, slim.conv2d, 256, 3, scope='conv3', reuse=reuse) 43 | net = slim.max_pool2d(net, [2, 2], scope='pool3') 44 | net = slim.repeat(net, 4, slim.conv2d, 512, 3, scope='conv4',reuse=reuse) 45 | net = slim.max_pool2d(net, [2, 2], scope='pool4') 46 | net = slim.repeat(net, 4, slim.conv2d, 512, 3, scope='conv5',reuse=reuse) 47 | net = slim.max_pool2d(net, [2, 2], scope='pool5') 48 | # Use conv2d instead of fully_connected layers. 49 | # Convert end_points_collection into a end_point dict. 50 | end_points = slim.utils.convert_collection_to_dict(end_points_collection) 51 | 52 | return net, end_points --------------------------------------------------------------------------------