diff --git a/Combined_Dataset/Test_set/Composition_code_revised.py b/Combined_Dataset/Test_set/Composition_code_revised.py index 4b8ab1b..02ce23c 100644 --- a/Combined_Dataset/Test_set/Composition_code_revised.py +++ b/Combined_Dataset/Test_set/Composition_code_revised.py @@ -2,22 +2,22 @@ import time import cv2 as cv import numpy as np -from console_progressbar import ProgressBar +from tqdm import tqdm ############################################################## # Set your paths here # path to provided foreground images -fg_path = 'fg_test/' +fg_path = 'data/fg_test/' # path to provided alpha mattes -a_path = 'mask_test/' +a_path = 'data/mask_test/' # Path to background images (MSCOCO) -bg_path = 'bg_test/' +bg_path = 'data/bg_test/' # Path to folder where you want the composited images to go -out_path = 'merged_test/' +out_path = 'data/merged_test/' ############################################################## @@ -60,10 +60,10 @@ def do_composite_test(): # a_files = os.listdir(a_path) num_samples = len(fg_files) * num_bgs - pb = ProgressBar(total=100, prefix='Compose test images', suffix='', decimals=3, length=50, fill='=') + # pb = ProgressBar(total=100, prefix='Compose test images', suffix='', decimals=3, length=50, fill='=') start = time.time() bcount = 0 - for fcount in range(len(fg_files)): + for fcount in tqdm(range(len(fg_files))): im_name = fg_files[fcount] for i in range(num_bgs): @@ -71,7 +71,7 @@ def do_composite_test(): process(im_name, bg_name, fcount, bcount) bcount += 1 - pb.print_progress_bar(bcount * 100.0 / num_samples) + # pb.print_progress_bar(bcount * 100.0 / num_samples) end = time.time() elapsed = end - start diff --git a/Combined_Dataset/Training_set/Composition_code_revised.py b/Combined_Dataset/Training_set/Composition_code_revised.py index 2714431..80ef1d8 100644 --- a/Combined_Dataset/Training_set/Composition_code_revised.py +++ b/Combined_Dataset/Training_set/Composition_code_revised.py @@ -2,22 +2,22 @@ import time import cv2 as cv import numpy as np -from console_progressbar import ProgressBar +from tqdm import tqdm ############################################################## # Set your paths here # path to provided foreground images -fg_path = 'fg/' +fg_path = 'data/fg/' # path to provided alpha mattes -a_path = 'mask/' +a_path = 'data/mask/' # Path to background images (MSCOCO) -bg_path = 'bg/' +bg_path = 'data/bg/' # Path to folder where you want the composited images to go -out_path = 'merged/' +out_path = 'data/merged/' ############################################################## @@ -60,10 +60,10 @@ def do_composite(): # a_files = os.listdir(a_path) num_samples = len(fg_files) * num_bgs - pb = ProgressBar(total=100, prefix='Compose train images', suffix='', decimals=3, length=50, fill='=') + # pb = ProgressBar(total=100, prefix='Compose train images', suffix='', decimals=3, length=50, fill='=') start = time.time() bcount = 0 - for fcount in range(len(fg_files)): + for fcount in tqdm(range(len(fg_files))): im_name = fg_files[fcount] for i in range(num_bgs): @@ -71,7 +71,7 @@ def do_composite(): process(im_name, bg_name, fcount, bcount) bcount += 1 - pb.print_progress_bar(bcount * 100.0 / num_samples) + # pb.print_progress_bar(bcount * 100.0 / num_samples) end = time.time() elapsed = end - start diff --git a/README.md b/README.md index abde076..5d32daa 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Go to [MSCOCO](http://cocodataset.org/#download) to download: ### PASCAL VOC Go to [PASCAL VOC](http://host.robots.ox.ac.uk/pascal/VOC/) to download: -* VOC challenge 2007 [training/validation data](http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtrainval_06-Nov-2007.tar) +* VOC challenge 2008 [training/validation data](http://host.robots.ox.ac.uk/pascal/VOC/voc2008/VOCtrainval_14-Jul-2008.tar) ## ImageNet Pretrained Models Download [VGG16](https://github.com/fchollet/deep-learning-models/releases/download/v0.1/vgg16_weights_tf_dim_ordering_tf_kernels.h5) into models folder. diff --git a/config.py b/config.py index e5b8460..d5419db 100644 --- a/config.py +++ b/config.py @@ -16,16 +16,15 @@ # Set your paths here # path to provided foreground images -fg_path = 'fg/' +fg_path = 'data/fg/' # path to provided alpha mattes -a_path = 'mask/' +a_path = 'data/mask/' # Path to background images (MSCOCO) -bg_path = 'bg/' +bg_path = 'data/bg/' # Path to folder where you want the composited images to go -out_path = 'merged/' +out_path = 'data/merged/' - -############################################################## \ No newline at end of file +############################################################## diff --git a/custom_layers/unpooling_layer.py b/custom_layers/unpooling_layer.py index faf6abb..633e0ab 100644 --- a/custom_layers/unpooling_layer.py +++ b/custom_layers/unpooling_layer.py @@ -1,6 +1,6 @@ from keras import backend as K from keras.engine.topology import Layer -from keras.layers import Reshape, Concatenate, Lambda, Multiply +from keras.layers import Lambda, Multiply class Unpooling(Layer): diff --git a/data_generator.py b/data_generator.py index 72174aa..b0417b0 100644 --- a/data_generator.py +++ b/data_generator.py @@ -27,7 +27,7 @@ def get_alpha(name): fg_i = int(name.split("_")[0]) name = fg_files[fg_i] - filename = os.path.join('mask', name) + filename = os.path.join('data/mask', name) alpha = cv.imread(filename, 0) return alpha @@ -35,7 +35,7 @@ def get_alpha(name): def get_alpha_test(name): fg_i = int(name.split("_")[0]) name = fg_test_files[fg_i] - filename = os.path.join('mask_test', name) + filename = os.path.join('data/mask_test', name) alpha = cv.imread(filename, 0) return alpha diff --git a/demo.py b/demo.py index 715f45e..e58336b 100644 --- a/demo.py +++ b/demo.py @@ -39,12 +39,12 @@ def composite4(fg, bg, a, w, h): final.load_weights(pretrained_path) print(final.summary()) - out_test_path = 'merged_test/' + out_test_path = 'data/merged_test/' test_images = [f for f in os.listdir(out_test_path) if os.path.isfile(os.path.join(out_test_path, f)) and f.endswith('.png')] samples = random.sample(test_images, 10) - bg_test = 'bg_test/' + bg_test = 'data/bg_test/' test_bgs = [f for f in os.listdir(bg_test) if os.path.isfile(os.path.join(bg_test, f)) and f.endswith('.jpg')] sample_bgs = random.sample(test_bgs, 10) diff --git a/images/0_alpha.png b/images/0_alpha.png index dc6e319..16a7b53 100644 Binary files a/images/0_alpha.png and b/images/0_alpha.png differ diff --git a/images/0_compose.png b/images/0_compose.png index 1bd9b3b..55fdd0d 100644 Binary files a/images/0_compose.png and b/images/0_compose.png differ diff --git a/images/0_image.png b/images/0_image.png index 1cd1198..9dc83fc 100644 Binary files a/images/0_image.png and b/images/0_image.png differ diff --git a/images/0_new_bg.png b/images/0_new_bg.png index 0f6124c..ac6a5d0 100644 Binary files a/images/0_new_bg.png and b/images/0_new_bg.png differ diff --git a/images/0_out.png b/images/0_out.png index 1c26d10..30d4660 100644 Binary files a/images/0_out.png and b/images/0_out.png differ diff --git a/images/0_trimap.png b/images/0_trimap.png index 474a575..11e327c 100644 Binary files a/images/0_trimap.png and b/images/0_trimap.png differ diff --git a/images/1_alpha.png b/images/1_alpha.png index 52c833f..b7a28dd 100644 Binary files a/images/1_alpha.png and b/images/1_alpha.png differ diff --git a/images/1_compose.png b/images/1_compose.png index 08a4643..5bb5fc4 100644 Binary files a/images/1_compose.png and b/images/1_compose.png differ diff --git a/images/1_image.png b/images/1_image.png index c207253..cb740ed 100644 Binary files a/images/1_image.png and b/images/1_image.png differ diff --git a/images/1_new_bg.png b/images/1_new_bg.png index 5364c8c..363f0ec 100644 Binary files a/images/1_new_bg.png and b/images/1_new_bg.png differ diff --git a/images/1_out.png b/images/1_out.png index 5119d87..e9a5995 100644 Binary files a/images/1_out.png and b/images/1_out.png differ diff --git a/images/1_trimap.png b/images/1_trimap.png index 2dfdc43..dce1077 100644 Binary files a/images/1_trimap.png and b/images/1_trimap.png differ diff --git a/images/2_alpha.png b/images/2_alpha.png index fba0e49..b96da58 100644 Binary files a/images/2_alpha.png and b/images/2_alpha.png differ diff --git a/images/2_compose.png b/images/2_compose.png index 5699813..731aa82 100644 Binary files a/images/2_compose.png and b/images/2_compose.png differ diff --git a/images/2_image.png b/images/2_image.png index 27af589..025f053 100644 Binary files a/images/2_image.png and b/images/2_image.png differ diff --git a/images/2_new_bg.png b/images/2_new_bg.png index cb1ba3e..48370b7 100644 Binary files a/images/2_new_bg.png and b/images/2_new_bg.png differ diff --git a/images/2_out.png b/images/2_out.png index 7cec98a..8c5ffad 100644 Binary files a/images/2_out.png and b/images/2_out.png differ diff --git a/images/2_trimap.png b/images/2_trimap.png index eea9ebe..adf3509 100644 Binary files a/images/2_trimap.png and b/images/2_trimap.png differ diff --git a/images/3_alpha.png b/images/3_alpha.png index d3add4c..d88745d 100644 Binary files a/images/3_alpha.png and b/images/3_alpha.png differ diff --git a/images/3_compose.png b/images/3_compose.png index a78932d..902c200 100644 Binary files a/images/3_compose.png and b/images/3_compose.png differ diff --git a/images/3_image.png b/images/3_image.png index a1b7c8e..7a576ef 100644 Binary files a/images/3_image.png and b/images/3_image.png differ diff --git a/images/3_new_bg.png b/images/3_new_bg.png index 163fdcd..014fbfe 100644 Binary files a/images/3_new_bg.png and b/images/3_new_bg.png differ diff --git a/images/3_out.png b/images/3_out.png index 3e39dc3..f4968bd 100644 Binary files a/images/3_out.png and b/images/3_out.png differ diff --git a/images/3_trimap.png b/images/3_trimap.png index 24b8d3a..d389914 100644 Binary files a/images/3_trimap.png and b/images/3_trimap.png differ diff --git a/images/4_alpha.png b/images/4_alpha.png index 0394026..9220a97 100644 Binary files a/images/4_alpha.png and b/images/4_alpha.png differ diff --git a/images/4_compose.png b/images/4_compose.png index 1d445f5..b98383e 100644 Binary files a/images/4_compose.png and b/images/4_compose.png differ diff --git a/images/4_image.png b/images/4_image.png index 5f0ab1a..3d9cc92 100644 Binary files a/images/4_image.png and b/images/4_image.png differ diff --git a/images/4_new_bg.png b/images/4_new_bg.png index 2b0bdbd..b2951ac 100644 Binary files a/images/4_new_bg.png and b/images/4_new_bg.png differ diff --git a/images/4_out.png b/images/4_out.png index c4fcf1f..54255a6 100644 Binary files a/images/4_out.png and b/images/4_out.png differ diff --git a/images/4_trimap.png b/images/4_trimap.png index c77160f..5661e59 100644 Binary files a/images/4_trimap.png and b/images/4_trimap.png differ diff --git a/images/5_alpha.png b/images/5_alpha.png index f5f1489..a7d6382 100644 Binary files a/images/5_alpha.png and b/images/5_alpha.png differ diff --git a/images/5_compose.png b/images/5_compose.png index 7f89f8d..e8cb497 100644 Binary files a/images/5_compose.png and b/images/5_compose.png differ diff --git a/images/5_image.png b/images/5_image.png index 9fcc8bd..6faeb5e 100644 Binary files a/images/5_image.png and b/images/5_image.png differ diff --git a/images/5_new_bg.png b/images/5_new_bg.png index 77b99f7..f44abf0 100644 Binary files a/images/5_new_bg.png and b/images/5_new_bg.png differ diff --git a/images/5_out.png b/images/5_out.png index 77ebe4d..0df1691 100644 Binary files a/images/5_out.png and b/images/5_out.png differ diff --git a/images/5_trimap.png b/images/5_trimap.png index 6860b9c..1763869 100644 Binary files a/images/5_trimap.png and b/images/5_trimap.png differ diff --git a/images/6_alpha.png b/images/6_alpha.png index 284bb70..8536234 100644 Binary files a/images/6_alpha.png and b/images/6_alpha.png differ diff --git a/images/6_compose.png b/images/6_compose.png index 3935e84..e7a4554 100644 Binary files a/images/6_compose.png and b/images/6_compose.png differ diff --git a/images/6_image.png b/images/6_image.png index b2b7f98..fe673bf 100644 Binary files a/images/6_image.png and b/images/6_image.png differ diff --git a/images/6_new_bg.png b/images/6_new_bg.png index f8191bf..431310d 100644 Binary files a/images/6_new_bg.png and b/images/6_new_bg.png differ diff --git a/images/6_out.png b/images/6_out.png index e48efb1..56b1682 100644 Binary files a/images/6_out.png and b/images/6_out.png differ diff --git a/images/6_trimap.png b/images/6_trimap.png index d809886..1fdfc14 100644 Binary files a/images/6_trimap.png and b/images/6_trimap.png differ diff --git a/images/7_alpha.png b/images/7_alpha.png index d4f2b74..ab0555a 100644 Binary files a/images/7_alpha.png and b/images/7_alpha.png differ diff --git a/images/7_compose.png b/images/7_compose.png index 7704072..0ea2bbc 100644 Binary files a/images/7_compose.png and b/images/7_compose.png differ diff --git a/images/7_image.png b/images/7_image.png index cd7d781..567fc42 100644 Binary files a/images/7_image.png and b/images/7_image.png differ diff --git a/images/7_new_bg.png b/images/7_new_bg.png index ebd13aa..3f8273d 100644 Binary files a/images/7_new_bg.png and b/images/7_new_bg.png differ diff --git a/images/7_out.png b/images/7_out.png index 48ce3cf..dda6b83 100644 Binary files a/images/7_out.png and b/images/7_out.png differ diff --git a/images/7_trimap.png b/images/7_trimap.png index 5c522d5..07be750 100644 Binary files a/images/7_trimap.png and b/images/7_trimap.png differ diff --git a/images/8_alpha.png b/images/8_alpha.png index 753c928..fdcd2c0 100644 Binary files a/images/8_alpha.png and b/images/8_alpha.png differ diff --git a/images/8_compose.png b/images/8_compose.png index 4c331f1..81def05 100644 Binary files a/images/8_compose.png and b/images/8_compose.png differ diff --git a/images/8_image.png b/images/8_image.png index ba33cec..77d78ed 100644 Binary files a/images/8_image.png and b/images/8_image.png differ diff --git a/images/8_new_bg.png b/images/8_new_bg.png index d5c2189..f66b5de 100644 Binary files a/images/8_new_bg.png and b/images/8_new_bg.png differ diff --git a/images/8_out.png b/images/8_out.png index c116a9f..e5af5c8 100644 Binary files a/images/8_out.png and b/images/8_out.png differ diff --git a/images/8_trimap.png b/images/8_trimap.png index 6468b66..0fba15e 100644 Binary files a/images/8_trimap.png and b/images/8_trimap.png differ diff --git a/images/9_alpha.png b/images/9_alpha.png index 35d5992..f9df533 100644 Binary files a/images/9_alpha.png and b/images/9_alpha.png differ diff --git a/images/9_compose.png b/images/9_compose.png index d01ec7a..50d263c 100644 Binary files a/images/9_compose.png and b/images/9_compose.png differ diff --git a/images/9_image.png b/images/9_image.png index 6a96039..812251d 100644 Binary files a/images/9_image.png and b/images/9_image.png differ diff --git a/images/9_new_bg.png b/images/9_new_bg.png index 359b0a9..839532e 100644 Binary files a/images/9_new_bg.png and b/images/9_new_bg.png differ diff --git a/images/9_out.png b/images/9_out.png index 5747f85..58b42c3 100644 Binary files a/images/9_out.png and b/images/9_out.png differ diff --git a/images/9_trimap.png b/images/9_trimap.png index 5e0aea0..ed224bc 100644 Binary files a/images/9_trimap.png and b/images/9_trimap.png differ diff --git a/pre-process.py b/pre_process.py similarity index 84% rename from pre-process.py rename to pre_process.py index a31cd61..19bf49f 100644 --- a/pre-process.py +++ b/pre_process.py @@ -10,30 +10,30 @@ if __name__ == '__main__': # path to provided foreground images - fg_path = 'fg/' + fg_path = 'data/fg/' # path to provided alpha mattes - a_path = 'mask/' + a_path = 'data/mask/' # Path to background images (MSCOCO) - bg_path = 'bg/' + bg_path = 'data/bg/' # Path to folder where you want the composited images to go - out_path = 'merged/' + out_path = 'data/merged/' train_folder = 'Combined_Dataset/Training_set/' # if not os.path.exists('Combined_Dataset'): - zip_file = 'Adobe_Deep_Matting_Dataset.zip' + zip_file = 'data/Adobe_Deep_Matting_Dataset.zip' print('Extracting {}...'.format(zip_file)) zip_ref = zipfile.ZipFile(zip_file, 'r') - zip_ref.extractall('.') + zip_ref.extractall('data') zip_ref.close() if not os.path.exists(bg_path): - zip_file = 'train2014.zip' + zip_file = 'data/train2014.zip' print('Extracting {}...'.format(zip_file)) zip_ref = zipfile.ZipFile(zip_file, 'r') - zip_ref.extractall('.') + zip_ref.extractall('data') zip_ref.close() with open(os.path.join(train_folder, 'training_bg_names.txt')) as f: @@ -41,7 +41,7 @@ os.makedirs(bg_path) for bg_name in training_bg_names: - src_path = os.path.join('train2014', bg_name) + src_path = os.path.join('data/train2014', bg_name) dest_path = os.path.join(bg_path, bg_name) shutil.move(src_path, dest_path) @@ -70,13 +70,13 @@ # do_composite() # path to provided foreground images - fg_test_path = 'fg_test/' + fg_test_path = 'data/fg_test/' # path to provided alpha mattes - a_test_path = 'mask_test/' + a_test_path = 'data/mask_test/' # Path to background images (PASCAL VOC) - bg_test_path = 'bg_test/' + bg_test_path = 'data/bg_test/' # Path to folder where you want the composited images to go - out_test_path = 'merged_test/' + out_test_path = 'data/merged_test/' # test data gen test_folder = 'Combined_Dataset/Test_set/' @@ -84,18 +84,18 @@ if not os.path.exists(bg_test_path): os.makedirs(bg_test_path) - tar_file = 'VOCtrainval_14-Jul-2008.tar' + tar_file = 'data/VOCtrainval_14-Jul-2008.tar' print('Extracting {}...'.format(tar_file)) tar = tarfile.open(tar_file) - tar.extractall() + tar.extractall('data') tar.close() - tar_file = 'VOC2008test.tar' + tar_file = 'data/VOC2008test.tar' print('Extracting {}...'.format(tar_file)) tar = tarfile.open(tar_file) - tar.extractall() + tar.extractall('data') tar.close() with open(os.path.join(test_folder, 'test_bg_names.txt')) as f: @@ -103,7 +103,7 @@ for bg_name in test_bg_names: tokens = bg_name.split('_') - src_path = os.path.join('VOCdevkit/VOC2008/JPEGImages', bg_name) + src_path = os.path.join('data/VOCdevkit/VOC2008/JPEGImages', bg_name) dest_path = os.path.join(bg_test_path, bg_name) shutil.move(src_path, dest_path) diff --git a/test_alphamatting.py b/test_alphamatting.py index d97f808..93f8c57 100644 --- a/test_alphamatting.py +++ b/test_alphamatting.py @@ -18,20 +18,16 @@ filename = os.path.join('alphamatting/input_lowres', image_name) im = cv.imread(filename) im_h, im_w = im.shape[:2] - + for id in [1, 2, 3]: trimap_name = os.path.join('alphamatting/trimap_lowres/Trimap{}'.format(id), image_name) trimap = cv.imread(trimap_name, 0) - - for i in range(0, np.ceil(im_h/320)): - for j in range(0, np.ceil(im_w/320)): - x = j * 320 - y = i * 320 - w = min(320, im_w - x) - h = min(320, im_h - y) - im_crop = im[y:y+h,x:x+w] - tri_crop = trimap[y:y+h,x:x+w] - - - + for i in range(0, np.ceil(im_h / 320)): + for j in range(0, np.ceil(im_w / 320)): + x = j * 320 + y = i * 320 + w = min(320, im_w - x) + h = min(320, im_h - y) + im_crop = im[y:y + h, x:x + w] + tri_crop = trimap[y:y + h, x:x + w] diff --git a/utils.py b/utils.py index b4f1603..3006e37 100644 --- a/utils.py +++ b/utils.py @@ -107,4 +107,3 @@ def draw_str(dst, target, s): x, y = target cv.putText(dst, s, (x + 1, y + 1), cv.FONT_HERSHEY_PLAIN, 1.0, (0, 0, 0), thickness=2, lineType=cv.LINE_AA) cv.putText(dst, s, (x, y), cv.FONT_HERSHEY_PLAIN, 1.0, (255, 255, 255), lineType=cv.LINE_AA) -