From 7defeeb1358f13fde19e129a8d7f49e8a2e3bbd6 Mon Sep 17 00:00:00 2001 From: Yo Date: Fri, 27 Mar 2020 13:18:25 +0100 Subject: [PATCH 1/5] Correct data soource path for step 4 debug --- normalization.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/normalization.py b/normalization.py index ff89a05..6c001c3 100644 --- a/normalization.py +++ b/normalization.py @@ -13,8 +13,8 @@ target_img = cv2.imread('./data/target/train/train_label/00001.png')[:,:,0] target_img_rgb = cv2.imread('./data/target/train/train_img/00001.png') -source_img = cv2.imread('./data/target/train/train_label/00001.png')[:,:,0] -source_img_rgb = cv2.imread('./data/target/train/train_img/00001.png') +source_img = cv2.imread('./data/source/test_label_ori/00001.png')[:,:,0] +source_img_rgb = cv2.imread('./data/source/test_img/00001.png') path = './data/source/test_label_ori/' save_dir = Path('./data/source/') From 1825c8fa637a321cf657d4cd380a6648782d6e9a Mon Sep 17 00:00:00 2001 From: Yo Date: Fri, 27 Mar 2020 13:19:09 +0100 Subject: [PATCH 2/5] Correct docs on path of transfer output --- README.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 2522dba..6306d34 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ We train and evaluate on Ubuntu 16.04, so if you don't have linux environment, y * If you break the traning and want to continue last training, set `load_pretrain = './checkpoints/target/` in `./src/config/train_opt.py` * Run `normalization.py` rescale the label images, you can use two sample images from `./data/target/train/train_label/` and `./data/source/test_label_ori/` to complete normalization between two skeleton size -* Run `transfer.py` and get results in `./result` +* Run `transfer.py` and get results in `./results` #### Face enhancement network ![](/result/fig2.png) @@ -42,7 +42,7 @@ We train and evaluate on Ubuntu 16.04, so if you don't have linux environment, y * Run `./face_enhancer/main.py` train face enhancer and run`./face_enhancer/enhance.py` to gain results
This is comparision in original (left), generated image before face enhancement (median) and after enhancement (right). FaceGAN can learn the residual error between the real picture and the generated picture faces. -#### Performance of face enhancement +#### Performance of face enhancement ![](/result/37500_enhanced_full.png) ![](/result/37500_enhanced_head.png) @@ -66,5 +66,3 @@ Ubuntu 16.04
Python 3.6.5
Pytorch 0.4.1
OpenCV 3.4.4
- - From b8449a607d366c4a269033c3aa01788e60d63fd6 Mon Sep 17 00:00:00 2001 From: Yo Date: Fri, 27 Mar 2020 22:22:19 +0100 Subject: [PATCH 3/5] Correct path in face preparation script --- README.md | 9 +++++---- face_enhancer/prepare.py | 10 +++++----- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 6306d34..f2c083f 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ We train and evaluate on Ubuntu 16.04, so if you don't have linux environment, y #### Make source pictures * Put source video mv.mp4 in `./data/source/` and run `make_source.py`, the label images and coordinate of head will save in `./data/source/test_label_ori/` and `./data/source/pose_souce.npy` (will use in step6). If you want to capture video by camera, you can directly run `./src/utils/save_img.py` #### Make target pictures -* Put target video mv.mp4 in `./data/target/` and run `make_target.py`, `pose.npy` will save in `./data/target/`, which contain the coordinate of faces (will use in step6). +* Rename your own target video as mv.mp4 and put it in `./data/target/` and run `make_target.py`, `pose.npy` will save in `./data/target/`, which contain the coordinate of faces (will use in step6). ![](/result/fig3.png) #### Train and use pose2vid network * Run `train_pose2vid.py` and check loss and full training process in `./checkpoints/` @@ -38,8 +38,9 @@ We train and evaluate on Ubuntu 16.04, so if you don't have linux environment, y ![](/result/fig2.png) #### Train and use face enhancement network -* Run `./face_enhancer/prepare.py` and check the results in `./data/face/test_sync` and `./data/face/test_real`. -* Run `./face_enhancer/main.py` train face enhancer and run`./face_enhancer/enhance.py` to gain results
+* Run `cd ./face_enhancer`. +* Run `prepare.py` and check the results in `data` directory at the root of the repo (`data/face/test_sync` and `data/face/test_real`). +* Run `main.py` to rain the face enhancer. Then run `enhance.py` to obtain the results
This is comparision in original (left), generated image before face enhancement (median) and after enhancement (right). FaceGAN can learn the residual error between the real picture and the generated picture faces. #### Performance of face enhancement @@ -47,7 +48,7 @@ This is comparision in original (left), generated image before face enhancement ![](/result/37500_enhanced_head.png) #### Gain results -* Run `make_gif.py` and make result pictures to gif picture +* `cd` back to the root dir and run `make_gif.py` to create a gif out of the resulting images. ![Result](/result/output.gif) diff --git a/face_enhancer/prepare.py b/face_enhancer/prepare.py index cf2eed4..f2bbc36 100644 --- a/face_enhancer/prepare.py +++ b/face_enhancer/prepare.py @@ -32,15 +32,17 @@ from pathlib import Path from tqdm import tqdm import sys -pix2pixhd_dir = Path('../src/pix2pixHD/') -sys.path.append(str(pix2pixhd_dir)) +root_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +sys.path.append(root_dir) +pix2pixhd_dir=os.path.join(root_dir, "src/pix2pixHD/") +sys.path.append(pix2pixhd_dir) from data.data_loader import CreateDataLoader from models.models import create_model import util.util as util from util.visualizer import Visualizer from util import html -import src.config.test_opt as opt +from src.config import test_opt as opt os.environ['CUDA_VISIBLE_DEVICES'] = "0" opt.checkpoints_dir = '../checkpoints/' opt.dataroot='../data/target/' @@ -74,5 +76,3 @@ for img_idx in tqdm(range(len(os.listdir(synthesized_image_dir)))): img = cv2.imread(synthesized_image_dir+' {:05}_synthesized_image.jpg'.format(img_idx)) cv2.imwrite(str(test_sync_dir) + '{:05}.png'.format(img_idx), img) - - From b9e931f97cbcfb6489a80aceb6b5a45c9f3c62d1 Mon Sep 17 00:00:00 2001 From: Yo Date: Fri, 27 Mar 2020 22:35:38 +0100 Subject: [PATCH 4/5] Correct path in face preparation script --- face_enhancer/prepare.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/face_enhancer/prepare.py b/face_enhancer/prepare.py index f2bbc36..3dc41f5 100644 --- a/face_enhancer/prepare.py +++ b/face_enhancer/prepare.py @@ -3,15 +3,15 @@ import cv2 from tqdm import tqdm -face_sync_dir = Path('../data/face/ ') +face_sync_dir = Path('../data/face/') face_sync_dir.mkdir(exist_ok=True) -test_sync_dir = Path('../data/face/test_sync/ ') +test_sync_dir = Path('../data/face/test_sync/') test_sync_dir.mkdir(exist_ok=True) -test_real_dir = Path('../data/face/test_real/ ') +test_real_dir = Path('../data/face/test_real/') test_real_dir.mkdir(exist_ok=True) -test_img = Path('../data/target/test_img/ ') +test_img = Path('../data/target/test_img/') test_img.mkdir(exist_ok=True) -test_label = Path('../data/target/test_label/ ') +test_label = Path('../data/target/test_label/') test_label.mkdir(exist_ok=True) train_dir = '../data/target/train/train_img/' From 2de8ea78ca1383d28811f8ced792ce5667837510 Mon Sep 17 00:00:00 2001 From: Yo Date: Sat, 28 Mar 2020 01:49:10 +0100 Subject: [PATCH 5/5] Add check for empty items in list of face training images --- face_enhancer/dataset.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/face_enhancer/dataset.py b/face_enhancer/dataset.py index 604065e..dec7882 100644 --- a/face_enhancer/dataset.py +++ b/face_enhancer/dataset.py @@ -12,8 +12,10 @@ def __init__(self, root, cache=None, is_test=False): with open(cache, 'rb') as f: self.root, self.images, self.size = pickle.load(f) else: - self.images = sorted(os.listdir(os.path.join(root, 'test_real'))) self.root = root + self.images = sorted(os.listdir(os.path.join(root, 'test_real'))) + if self.images[0] == " ": + self.images.pop(0) tmp = imread(os.path.join(self.root, 'test_real', self.images[0])) self.size = tmp.shape[:-1] if cache is not None: @@ -84,4 +86,3 @@ def __getitem__(self, item): def __len__(self): return len(self.image_dataset) -