Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
cl0ver012 committed Jan 6, 2019
1 parent e0b18c9 commit f6115b9
Show file tree
Hide file tree
Showing 70 changed files with 54 additions and 60 deletions.
16 changes: 8 additions & 8 deletions Combined_Dataset/Test_set/Composition_code_revised.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/'


##############################################################
Expand Down Expand Up @@ -60,18 +60,18 @@ 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):
bg_name = bg_files[bcount]
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
Expand Down
16 changes: 8 additions & 8 deletions Combined_Dataset/Training_set/Composition_code_revised.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/'


##############################################################
Expand Down Expand Up @@ -60,18 +60,18 @@ 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):
bg_name = bg_files[bcount]
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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 5 additions & 6 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/'


##############################################################
##############################################################
2 changes: 1 addition & 1 deletion custom_layers/unpooling_layer.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
4 changes: 2 additions & 2 deletions data_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@
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


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

Expand Down
4 changes: 2 additions & 2 deletions demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Binary file modified images/0_alpha.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/0_compose.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/0_image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/0_new_bg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/0_out.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/0_trimap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/1_alpha.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/1_compose.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/1_image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/1_new_bg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/1_out.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/1_trimap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/2_alpha.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/2_compose.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/2_image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/2_new_bg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/2_out.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/2_trimap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/3_alpha.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/3_compose.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/3_image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/3_new_bg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/3_out.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/3_trimap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/4_alpha.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/4_compose.png
Binary file modified images/4_image.png
Binary file modified images/4_new_bg.png
Binary file modified images/4_out.png
Binary file modified images/4_trimap.png
Binary file modified images/5_alpha.png
Binary file modified images/5_compose.png
Binary file modified images/5_image.png
Binary file modified images/5_new_bg.png
Binary file modified images/5_out.png
Binary file modified images/5_trimap.png
Binary file modified images/6_alpha.png
Binary file modified images/6_compose.png
Binary file modified images/6_image.png
Binary file modified images/6_new_bg.png
Binary file modified images/6_out.png
Binary file modified images/6_trimap.png
Binary file modified images/7_alpha.png
Binary file modified images/7_compose.png
Binary file modified images/7_image.png
Binary file modified images/7_new_bg.png
Binary file modified images/7_out.png
Binary file modified images/7_trimap.png
Binary file modified images/8_alpha.png
Binary file modified images/8_compose.png
Binary file modified images/8_image.png
Binary file modified images/8_new_bg.png
Binary file modified images/8_out.png
Binary file modified images/8_trimap.png
Binary file modified images/9_alpha.png
Binary file modified images/9_compose.png
Binary file modified images/9_image.png
Binary file modified images/9_new_bg.png
Binary file modified images/9_out.png
Binary file modified images/9_trimap.png
36 changes: 18 additions & 18 deletions pre-process.py → pre_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,38 @@

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:
training_bg_names = f.read().splitlines()

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)

Expand Down Expand Up @@ -70,40 +70,40 @@
# 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/'

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:
test_bg_names = f.read().splitlines()

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)

Expand Down
22 changes: 9 additions & 13 deletions test_alphamatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
1 change: 0 additions & 1 deletion utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit f6115b9

Please sign in to comment.