falseu
commited on
Commit
·
e4050d7
1
Parent(s):
1a779cb
update data
Browse files- README.md +4 -7
- test.py +11 -5
- test_interpolate.py +5 -2
- test_video.py +1 -1
README.md
CHANGED
|
@@ -69,7 +69,7 @@ optional arguments:
|
|
| 69 |
|
| 70 |
### Test Image Interpolation Style Transfer
|
| 71 |
|
| 72 |
-
To test style transfer interpolation, run the script test_interpolate.py. Specify `style_image` with multiple paths separated by comma. Specify `--interpolation_weights` to interpolate once. Specify `--grid_pth` to interpolate with different built-in weights.
|
| 73 |
|
| 74 |
```
|
| 75 |
$ python test_interpolation.py --content_image $IMG --style_image $STYLE --decoder_weight $WEIGHT --cuda
|
|
@@ -88,12 +88,9 @@ optional arguments:
|
|
| 88 |
Do not specify if input grid_pth.
|
| 89 |
--cuda Use CUDA
|
| 90 |
--grid_pth GRID_PTH
|
| 91 |
-
Specify a grid image path (default=None) to perform interpolation style
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
grid image that contains all style transferred images. Provide 4 style
|
| 96 |
-
|
| 97 |
images. Do not specify if input interpolation_weights.
|
| 98 |
```
|
| 99 |
|
|
|
|
| 69 |
|
| 70 |
### Test Image Interpolation Style Transfer
|
| 71 |
|
| 72 |
+
To test style transfer interpolation, run the script test_interpolate.py. Specify `style_image` with multiple paths separated by comma. Specify `--interpolation_weights` to interpolate once. Specify `--grid_pth` to interpolate with different built-in weights and provide 4 style images.
|
| 73 |
|
| 74 |
```
|
| 75 |
$ python test_interpolation.py --content_image $IMG --style_image $STYLE --decoder_weight $WEIGHT --cuda
|
|
|
|
| 88 |
Do not specify if input grid_pth.
|
| 89 |
--cuda Use CUDA
|
| 90 |
--grid_pth GRID_PTH
|
| 91 |
+
Specify a grid image path (default=None) to perform interpolation style
|
| 92 |
+
transfer multiple times with different built-in weights and generate a
|
| 93 |
+
grid image that contains all style transferred images. Provide 4 style
|
|
|
|
|
|
|
|
|
|
| 94 |
images. Do not specify if input interpolation_weights.
|
| 95 |
```
|
| 96 |
|
test.py
CHANGED
|
@@ -16,7 +16,7 @@ parser.add_argument('--content_image', type=str, help='Content image file path')
|
|
| 16 |
parser.add_argument('--content_dir', type=str, help='Content image folder path')
|
| 17 |
parser.add_argument('--style_image', type=str, help='Style image file path')
|
| 18 |
parser.add_argument('--style_dir', type=str, help='Content image folder path')
|
| 19 |
-
parser.add_argument('--decoder_weight', type=str,
|
| 20 |
parser.add_argument('--alpha', type=float, default=1.0, choices=[Range(0.0, 1.0)], help='Alpha [0.0, 1.0] controls style transfer level')
|
| 21 |
parser.add_argument('--cuda', action='store_true', help='Use CUDA')
|
| 22 |
parser.add_argument('--grid_pth', type=str, default=None, help='Specify a grid image path (default=None) if generate a grid image that contains all style transferred images')
|
|
@@ -66,6 +66,9 @@ def main():
|
|
| 66 |
else:
|
| 67 |
style_pths = [Path(f) for f in glob(args.style_dir+'/*')]
|
| 68 |
|
|
|
|
|
|
|
|
|
|
| 69 |
out_dir = './results/'
|
| 70 |
os.makedirs(out_dir, exist_ok=True)
|
| 71 |
|
|
@@ -80,7 +83,7 @@ def main():
|
|
| 80 |
|
| 81 |
# Prepare grid image
|
| 82 |
if args.grid_pth:
|
| 83 |
-
imgs = [np.
|
| 84 |
for style_pth in style_pths:
|
| 85 |
imgs.append(Image.open(style_pth))
|
| 86 |
|
|
@@ -104,7 +107,7 @@ def main():
|
|
| 104 |
|
| 105 |
toc = time.perf_counter() # End time
|
| 106 |
print("Content: " + content_pth.stem + ". Style: " \
|
| 107 |
-
+ style_pth.stem + '. Style Transfer time: %.4f seconds' % (toc-tic))
|
| 108 |
times.append(toc-tic)
|
| 109 |
|
| 110 |
out_pth = out_dir + content_pth.stem + '_style_' + style_pth.stem + '_alpha' + str(args.alpha) + content_pth.suffix
|
|
@@ -113,8 +116,11 @@ def main():
|
|
| 113 |
if args.grid_pth:
|
| 114 |
imgs.append(Image.open(out_pth))
|
| 115 |
|
| 116 |
-
|
| 117 |
-
|
|
|
|
|
|
|
|
|
|
| 118 |
|
| 119 |
if args.grid_pth:
|
| 120 |
print("Generating grid image")
|
|
|
|
| 16 |
parser.add_argument('--content_dir', type=str, help='Content image folder path')
|
| 17 |
parser.add_argument('--style_image', type=str, help='Style image file path')
|
| 18 |
parser.add_argument('--style_dir', type=str, help='Content image folder path')
|
| 19 |
+
parser.add_argument('--decoder_weight', type=str, default='decoder.pth', help='Decoder weight file path')
|
| 20 |
parser.add_argument('--alpha', type=float, default=1.0, choices=[Range(0.0, 1.0)], help='Alpha [0.0, 1.0] controls style transfer level')
|
| 21 |
parser.add_argument('--cuda', action='store_true', help='Use CUDA')
|
| 22 |
parser.add_argument('--grid_pth', type=str, default=None, help='Specify a grid image path (default=None) if generate a grid image that contains all style transferred images')
|
|
|
|
| 66 |
else:
|
| 67 |
style_pths = [Path(f) for f in glob(args.style_dir+'/*')]
|
| 68 |
|
| 69 |
+
assert len(content_pths) > 0, 'Failed to load content image'
|
| 70 |
+
assert len(style_pths) > 0, 'Failed to load style image'
|
| 71 |
+
|
| 72 |
out_dir = './results/'
|
| 73 |
os.makedirs(out_dir, exist_ok=True)
|
| 74 |
|
|
|
|
| 83 |
|
| 84 |
# Prepare grid image
|
| 85 |
if args.grid_pth:
|
| 86 |
+
imgs = [np.ones((1, 1, 3), np.uint8) * 255]
|
| 87 |
for style_pth in style_pths:
|
| 88 |
imgs.append(Image.open(style_pth))
|
| 89 |
|
|
|
|
| 107 |
|
| 108 |
toc = time.perf_counter() # End time
|
| 109 |
print("Content: " + content_pth.stem + ". Style: " \
|
| 110 |
+
+ style_pth.stem + '. Alpha: ' + str(args.alpha) + '. Style Transfer time: %.4f seconds' % (toc-tic))
|
| 111 |
times.append(toc-tic)
|
| 112 |
|
| 113 |
out_pth = out_dir + content_pth.stem + '_style_' + style_pth.stem + '_alpha' + str(args.alpha) + content_pth.suffix
|
|
|
|
| 116 |
if args.grid_pth:
|
| 117 |
imgs.append(Image.open(out_pth))
|
| 118 |
|
| 119 |
+
# Remove runtime of first iteration because it is flawed for some unknown reason
|
| 120 |
+
if len(times) > 1:
|
| 121 |
+
times.pop(0)
|
| 122 |
+
avg = sum(times)/len(times)
|
| 123 |
+
print("Average style transfer time: %.4f seconds" % (avg))
|
| 124 |
|
| 125 |
if args.grid_pth:
|
| 126 |
print("Generating grid image")
|
test_interpolate.py
CHANGED
|
@@ -13,7 +13,7 @@ from glob import glob
|
|
| 13 |
parser = argparse.ArgumentParser()
|
| 14 |
parser.add_argument('--content_image', type=str, help='Test image file path')
|
| 15 |
parser.add_argument('--style_image', type=str, required=True, help='Multiple Style image file path, separated by comma')
|
| 16 |
-
parser.add_argument('--decoder_weight', type=str,
|
| 17 |
parser.add_argument('--alpha', type=float, default=1.0, choices=[Range(0.0, 1.0)], help='Alpha [0.0, 1.0] controls style transfer level')
|
| 18 |
parser.add_argument('--interpolation_weights', type=str, help='Weights of interpolate multiple style images')
|
| 19 |
parser.add_argument('--cuda', action='store_true', help='Use CUDA')
|
|
@@ -67,11 +67,14 @@ def main():
|
|
| 67 |
|
| 68 |
style_pths_list = args.style_image.split(',')
|
| 69 |
style_pths = [Path(pth) for pth in style_pths_list]
|
|
|
|
|
|
|
|
|
|
| 70 |
|
| 71 |
inter_weights = []
|
| 72 |
# If grid mode, use 4 style images, 5x5 interpolation weights
|
| 73 |
if args.grid_pth:
|
| 74 |
-
assert len(style_pths) == 4
|
| 75 |
inter_weights = [ [ min(4-a, 4-b) / 4, min(4-a, b) / 4, min(a, 4-b) / 4, min(a, b) / 4] \
|
| 76 |
for a in range(5) for b in range(5) ]
|
| 77 |
|
|
|
|
| 13 |
parser = argparse.ArgumentParser()
|
| 14 |
parser.add_argument('--content_image', type=str, help='Test image file path')
|
| 15 |
parser.add_argument('--style_image', type=str, required=True, help='Multiple Style image file path, separated by comma')
|
| 16 |
+
parser.add_argument('--decoder_weight', type=str, default='decoder.pth', help='Decoder weight file path')
|
| 17 |
parser.add_argument('--alpha', type=float, default=1.0, choices=[Range(0.0, 1.0)], help='Alpha [0.0, 1.0] controls style transfer level')
|
| 18 |
parser.add_argument('--interpolation_weights', type=str, help='Weights of interpolate multiple style images')
|
| 19 |
parser.add_argument('--cuda', action='store_true', help='Use CUDA')
|
|
|
|
| 67 |
|
| 68 |
style_pths_list = args.style_image.split(',')
|
| 69 |
style_pths = [Path(pth) for pth in style_pths_list]
|
| 70 |
+
|
| 71 |
+
assert len(content_pths) > 0, 'Failed to load content image'
|
| 72 |
+
assert len(style_pths) > 0, 'Failed to load style image'
|
| 73 |
|
| 74 |
inter_weights = []
|
| 75 |
# If grid mode, use 4 style images, 5x5 interpolation weights
|
| 76 |
if args.grid_pth:
|
| 77 |
+
assert len(style_pths) == 4, "Under grid mode, specify 4 style images"
|
| 78 |
inter_weights = [ [ min(4-a, 4-b) / 4, min(4-a, b) / 4, min(a, 4-b) / 4, min(a, b) / 4] \
|
| 79 |
for a in range(5) for b in range(5) ]
|
| 80 |
|
test_video.py
CHANGED
|
@@ -14,7 +14,7 @@ from tqdm import tqdm
|
|
| 14 |
parser = argparse.ArgumentParser()
|
| 15 |
parser.add_argument('--content_video', type=str, required=True, help='Content video file path')
|
| 16 |
parser.add_argument('--style_image', type=str, required=True, help='Style image file path')
|
| 17 |
-
parser.add_argument('--decoder_weight', type=str,
|
| 18 |
parser.add_argument('--alpha', type=float, default=1.0, choices=[Range(0.0, 1.0)], help='Alpha [0.0, 1.0] controls style transfer level')
|
| 19 |
parser.add_argument('--cuda', action='store_true', help='Use CUDA')
|
| 20 |
args = parser.parse_args()
|
|
|
|
| 14 |
parser = argparse.ArgumentParser()
|
| 15 |
parser.add_argument('--content_video', type=str, required=True, help='Content video file path')
|
| 16 |
parser.add_argument('--style_image', type=str, required=True, help='Style image file path')
|
| 17 |
+
parser.add_argument('--decoder_weight', type=str, default='decoder.pth', help='Decoder weight file path')
|
| 18 |
parser.add_argument('--alpha', type=float, default=1.0, choices=[Range(0.0, 1.0)], help='Alpha [0.0, 1.0] controls style transfer level')
|
| 19 |
parser.add_argument('--cuda', action='store_true', help='Use CUDA')
|
| 20 |
args = parser.parse_args()
|