From 4f5e2ced93ebb21b42c8568b044c143a4be4a651 Mon Sep 17 00:00:00 2001
From: Sanghyun Son <thstkdgus35@snu.ac.kr>
Date: Mon, 20 Aug 2018 11:09:15 +0900
Subject: [PATCH] fix dependency, directory structure

---
 README.md                           | 17 +++++-----
 code/tools/downsampling_jpeg.m      | 44 --------------------------
 code/tools/jpeg2binary.py           | 49 -----------------------------
 {code => src}/__init__.py           |  0
 {code => src}/data/__init__.py      |  0
 {code => src}/data/benchmark.py     |  0
 {code => src}/data/common.py        |  2 --
 {code => src}/data/demo.py          |  0
 {code => src}/data/div2k.py         |  0
 {code => src}/data/srdata.py        |  0
 {code => src}/dataloader.py         |  0
 {code => src}/demo.sh               |  5 ++-
 {code => src}/loss/__init__.py      |  0
 {code => src}/loss/adversarial.py   |  0
 {code => src}/loss/discriminator.py |  0
 {code => src}/loss/vgg.py           |  0
 {code => src}/main.py               |  0
 {code => src}/model/__init__.py     |  0
 {code => src}/model/common.py       |  0
 {code => src}/model/ddbpn.py        |  0
 {code => src}/model/edsr.py         |  0
 {code => src}/model/mdsr.py         |  0
 {code => src}/model/rdn.py          |  0
 {code => src}/option.py             |  0
 {code => src}/template.py           |  0
 {code => src}/trainer.py            |  0
 {code => src}/utility.py            |  0
 27 files changed, 13 insertions(+), 104 deletions(-)
 delete mode 100644 code/tools/downsampling_jpeg.m
 delete mode 100644 code/tools/jpeg2binary.py
 rename {code => src}/__init__.py (100%)
 rename {code => src}/data/__init__.py (100%)
 rename {code => src}/data/benchmark.py (100%)
 rename {code => src}/data/common.py (97%)
 rename {code => src}/data/demo.py (100%)
 rename {code => src}/data/div2k.py (100%)
 rename {code => src}/data/srdata.py (100%)
 rename {code => src}/dataloader.py (100%)
 rename {code => src}/demo.sh (88%)
 rename {code => src}/loss/__init__.py (100%)
 rename {code => src}/loss/adversarial.py (100%)
 rename {code => src}/loss/discriminator.py (100%)
 rename {code => src}/loss/vgg.py (100%)
 rename {code => src}/main.py (100%)
 rename {code => src}/model/__init__.py (100%)
 rename {code => src}/model/common.py (100%)
 rename {code => src}/model/ddbpn.py (100%)
 rename {code => src}/model/edsr.py (100%)
 rename {code => src}/model/mdsr.py (100%)
 rename {code => src}/model/rdn.py (100%)
 rename {code => src}/option.py (100%)
 rename {code => src}/template.py (100%)
 rename {code => src}/trainer.py (100%)
 rename {code => src}/utility.py (100%)

diff --git a/README.md b/README.md
index bd61eee..8554980 100755
--- a/README.md
+++ b/README.md
@@ -26,10 +26,11 @@ We provide scripts for reproducing all the results from our paper. You can train
 * Python-based.
 
 ## Dependencies
-* Python (Tested with 3.6)
+* Python 3.6
 * PyTorch >= 0.4.0
 * numpy
 * scipy
+* skimage
 * matplotlib
 * tqdm
 
@@ -50,9 +51,9 @@ cd EDSR-PyTorch
 ## Quick start (Demo)
 You can test our super-resolution algorithm with your own images. Place your images in ``test`` folder. (like ``test/<your_image>``) We support **png** and **jpeg** files.
 
-Run the script in ``code`` folder. Before you run the demo, please uncomment the appropriate line in ```demo.sh``` that you want to execute.
+Run the script in ``src`` folder. Before you run the demo, please uncomment the appropriate line in ```demo.sh``` that you want to execute.
 ```bash
-cd code       # You are now in */EDSR-PyTorch/code
+cd src       # You are now in */EDSR-PyTorch/src
 sh demo.sh
 ```
 
@@ -91,16 +92,16 @@ For these datasets, we first convert the result images to YCbCr color space and
 ## How to train EDSR and MDSR
 We used [DIV2K](http://www.vision.ee.ethz.ch/%7Etimofter/publications/Agustsson-CVPRW-2017.pdf) dataset to train our model. Please download it from [here](https://cv.snu.ac.kr/research/EDSR/DIV2K.tar) (7.1GB).
 
-Unpack the tar file to any place you want. Then, change the ```dir_data``` argument in ```code/option.py``` to the place where DIV2K images are located.
+Unpack the tar file to any place you want. Then, change the ```dir_data``` argument in ```src/option.py``` to the place where DIV2K images are located.
 
 We recommend you to pre-process the images before training. This step will decode all **png** files and save them as binaries. Use ``--ext sep_reset`` argument on your first run. You can skip the decoding part and use saved binaries with ``--ext sep`` argument.
 
 If you have enough RAM (>= 32GB), you can use ``--ext bin`` argument to pack all DIV2K images in one binary file.
 
-You can train EDSR and MDSR by yourself. All scripts are provided in the ``code/demo.sh``. Note that EDSR (x3, x4) requires pre-trained EDSR (x2). You can ignore this constraint by removing ```--pre_train <x2 model>``` argument.
+You can train EDSR and MDSR by yourself. All scripts are provided in the ``src/demo.sh``. Note that EDSR (x3, x4) requires pre-trained EDSR (x2). You can ignore this constraint by removing ```--pre_train <x2 model>``` argument.
 
 ```bash
-cd code       # You are now in */EDSR-PyTorch/code
+cd src       # You are now in */EDSR-PyTorch/src
 sh demo.sh
 ```
 
@@ -111,7 +112,7 @@ sh demo.sh
   * Training details are included.
 
 * Jan 09, 2018
-  * Missing files are included (```code/data/MyImage.py```).
+  * Missing files are included (```src/data/MyImage.py```).
   * Some links are fixed.
 
 * Jan 16, 2018
@@ -128,7 +129,7 @@ sh demo.sh
 * Feb 23, 2018
   * Now PyTorch 0.3.1 is default. Use legacy/0.3.0 branch if you use the old version.
    
-  * With a new ``code/data/DIV2K.py`` code, one can easily create new data class for super-resolution.
+  * With a new ``src/data/DIV2K.py`` code, one can easily create new data class for super-resolution.
   * New binary data pack. (Please remove the ``DIV2K_decoded`` folder from your dataset if you have.)
   * With ``--ext bin``, this code will automatically generates and saves the binary data pack that corresponds to previous ``DIV2K_decoded``. (This requires huge RAM (~45GB, Swap can be used.), so please be careful.)
   * If you cannot make the binary pack, just use the default setting (``--ext img``).
diff --git a/code/tools/downsampling_jpeg.m b/code/tools/downsampling_jpeg.m
deleted file mode 100644
index 16eb8fa..0000000
--- a/code/tools/downsampling_jpeg.m
+++ /dev/null
@@ -1,44 +0,0 @@
-scale = [2, 3, 4];
-dataset = 'DIV2K';
-apath = '../../../../dataset';
-quality = 87; 
-hrDir = fullfile(apath, dataset, 'DIV2K_train_HR');
-lrDir = fullfile(apath, dataset, ['DIV2K_train_LR_bicubic', num2str(quality)]);
-
-if ~exist(lrDir, 'dir')
-    mkdir(lrDir)
-end
-
-for sc = 1:length(scale)
-    lrSubDir = fullfile(lrDir, sprintf('X%d', scale(sc)));
-    if ~exist(lrSubDir, 'dir')
-        mkdir(lrSubDir);
-    end
-end
-
-hrImgs = dir(fullfile(hrDir, '*.png'));
-for idx = 1:length(hrImgs)
-    imgName = hrImgs(idx).name;
-    try
-        hrImg = imread(fullfile(hrDir, imgName));
-    catch
-        disp(imgName);
-        continue;
-    end
-    [h, w, ~] = size(hrImg);
-    for sc = 1:length(scale)
-        ch = floor(h / scale(sc)) * scale(sc);
-        cw = floor(w / scale(sc)) * scale(sc);
-        cropped = hrImg(1:ch, 1:cw, :);
-        lrImg = imresize(cropped, 1 / scale(sc), 'bicubic');
-        [~, woExt, ext] = fileparts(imgName);
-        lrName = sprintf('%sx%d%s', woExt, scale(sc), '.jpeg');
-        imwrite( ...
-            lrImg, ...
-            fullfile(lrDir, sprintf('X%d', scale(sc)), lrName), ...
-            'quality', quality);
-    end
-    if mod(idx, 100) == 0
-        fprintf('Processed %d / %d images\n', idx, length(hrImgs));
-    end
-end
diff --git a/code/tools/jpeg2binary.py b/code/tools/jpeg2binary.py
deleted file mode 100644
index 7373f14..0000000
--- a/code/tools/jpeg2binary.py
+++ /dev/null
@@ -1,49 +0,0 @@
-import os
-import argparse
-
-import skimage
-import skimage.io as sio
-
-import torch
-
-parser = argparse.ArgumentParser(description='Pre-processing DIV2K .jpeg images')
-
-parser.add_argument('--pathFrom', default='../../../../dataset/DIV2K',
-                    help='directory of images to convert')
-parser.add_argument('--pathTo', default='../../../../dataset/DIV2K_decoded',
-                    help='directory of images to save')
-parser.add_argument('--split', default=False,
-                    help='save individual images')
-parser.add_argument('--select', default='',
-                    help='select certain path')
-
-args = parser.parse_args()
-
-for (path, dirs, files) in os.walk(args.pathFrom):
-    print(path)
-    targetDir = path.replace(args.pathFrom, args.pathTo)
-    if len(args.select) > 0 and path.find(args.select) == -1:
-        continue
-
-    if not os.path.exists(targetDir):
-        os.mkdir(targetDir)
-
-    if len(dirs) == 0:
-        pack = {}
-        n = 0
-        for fileName in files:
-            (idx, ext) = os.path.splitext(fileName)
-            if ext == '.jpeg':
-                png = sio.imread(os.path.join(path, fileName))
-                tensor = torch.Tensor(png.astype(float)).byte()
-                if args.split:
-                    torch.save(tensor, os.path.join(targetDir, idx + '.pt'))
-                else:
-                    pack[int(idx.split('x')[0])] = tensor
-                n += 1
-                if n % 100 == 0:
-                    print('Converted ' + str(n) + ' images.')
-        if len(pack) > 0:
-            torch.save(pack, targetDir + '/pack.pt')
-            print('Saved pt binary.')
-            del pack
diff --git a/code/__init__.py b/src/__init__.py
similarity index 100%
rename from code/__init__.py
rename to src/__init__.py
diff --git a/code/data/__init__.py b/src/data/__init__.py
similarity index 100%
rename from code/data/__init__.py
rename to src/data/__init__.py
diff --git a/code/data/benchmark.py b/src/data/benchmark.py
similarity index 100%
rename from code/data/benchmark.py
rename to src/data/benchmark.py
diff --git a/code/data/common.py b/src/data/common.py
similarity index 97%
rename from code/data/common.py
rename to src/data/common.py
index 3a36160..848653f 100644
--- a/code/data/common.py
+++ b/src/data/common.py
@@ -1,9 +1,7 @@
 import random
 
 import numpy as np
-import skimage.io as sio
 import skimage.color as sc
-import skimage.transform as st
 
 import torch
 from torchvision import transforms
diff --git a/code/data/demo.py b/src/data/demo.py
similarity index 100%
rename from code/data/demo.py
rename to src/data/demo.py
diff --git a/code/data/div2k.py b/src/data/div2k.py
similarity index 100%
rename from code/data/div2k.py
rename to src/data/div2k.py
diff --git a/code/data/srdata.py b/src/data/srdata.py
similarity index 100%
rename from code/data/srdata.py
rename to src/data/srdata.py
diff --git a/code/dataloader.py b/src/dataloader.py
similarity index 100%
rename from code/dataloader.py
rename to src/dataloader.py
diff --git a/code/demo.sh b/src/demo.sh
similarity index 88%
rename from code/demo.sh
rename to src/demo.sh
index f4cb947..fc11a01 100644
--- a/code/demo.sh
+++ b/src/demo.sh
@@ -42,8 +42,11 @@
 #python main.py --data_test Urban100 --scale 4 --n_resblocks 32 --n_feats 256 --res_scale 0.1 --pre_train ../experiment/model/EDSR_x4.pt --test_only --self_ensemble
 #python main.py --data_test DIV2K --ext img --n_val 100 --scale 4 --n_resblocks 32 --n_feats 256 --res_scale 0.1 --pre_train ../experiment/model/EDSR_x4.pt --test_only --self_ensemble
 
+python main.py --data_test DIV2K --ext img --n_val 10 --scale 2 --n_resblocks 32 --n_feats 256 --res_scale 0.1 --pre_train ../experiment/model/EDSR_x2.pt --test_only
+python main.py --data_test DIV2K --ext img --n_val 10 --scale 2 --n_resblocks 32 --n_feats 256 --res_scale 0.1 --pre_train ../experiment/model/EDSR_x2.pt --test_only --self_ensemble
+
 # Test your own images
-python main.py --data_test Demo --scale 4 --pre_train ../experiment/model/EDSR_baseline_x4.pt --test_only --save_results
+#python main.py --data_test Demo --scale 4 --pre_train ../experiment/model/EDSR_baseline_x4.pt --test_only --save_results
 
 # Advanced - Test with JPEG images 
 #python main.py --model MDSR --data_test Demo --scale 2+3+4 --pre_train ../experiment/model/MDSR_baseline_jpeg.pt --test_only --save_results
diff --git a/code/loss/__init__.py b/src/loss/__init__.py
similarity index 100%
rename from code/loss/__init__.py
rename to src/loss/__init__.py
diff --git a/code/loss/adversarial.py b/src/loss/adversarial.py
similarity index 100%
rename from code/loss/adversarial.py
rename to src/loss/adversarial.py
diff --git a/code/loss/discriminator.py b/src/loss/discriminator.py
similarity index 100%
rename from code/loss/discriminator.py
rename to src/loss/discriminator.py
diff --git a/code/loss/vgg.py b/src/loss/vgg.py
similarity index 100%
rename from code/loss/vgg.py
rename to src/loss/vgg.py
diff --git a/code/main.py b/src/main.py
similarity index 100%
rename from code/main.py
rename to src/main.py
diff --git a/code/model/__init__.py b/src/model/__init__.py
similarity index 100%
rename from code/model/__init__.py
rename to src/model/__init__.py
diff --git a/code/model/common.py b/src/model/common.py
similarity index 100%
rename from code/model/common.py
rename to src/model/common.py
diff --git a/code/model/ddbpn.py b/src/model/ddbpn.py
similarity index 100%
rename from code/model/ddbpn.py
rename to src/model/ddbpn.py
diff --git a/code/model/edsr.py b/src/model/edsr.py
similarity index 100%
rename from code/model/edsr.py
rename to src/model/edsr.py
diff --git a/code/model/mdsr.py b/src/model/mdsr.py
similarity index 100%
rename from code/model/mdsr.py
rename to src/model/mdsr.py
diff --git a/code/model/rdn.py b/src/model/rdn.py
similarity index 100%
rename from code/model/rdn.py
rename to src/model/rdn.py
diff --git a/code/option.py b/src/option.py
similarity index 100%
rename from code/option.py
rename to src/option.py
diff --git a/code/template.py b/src/template.py
similarity index 100%
rename from code/template.py
rename to src/template.py
diff --git a/code/trainer.py b/src/trainer.py
similarity index 100%
rename from code/trainer.py
rename to src/trainer.py
diff --git a/code/utility.py b/src/utility.py
similarity index 100%
rename from code/utility.py
rename to src/utility.py
-- 
GitLab