Skip to content

Commit f5650de

Browse files
committed
Add ffmpeg support for unix systems, refactor
1 parent 1719b37 commit f5650de

File tree

3 files changed

+4
-5
lines changed

3 files changed

+4
-5
lines changed

neural_style_transfer.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def neural_style_transfer(config):
7070
# feature maps need to be of same size for content image and init image
7171
style_img_resized = utils.prepare_img(style_img_path, np.asarray(content_img.shape[2:]), device)
7272
init_img = style_img_resized
73+
7374
# we are tuning optimizing_img's pixels! (that's why requires_grad=True)
7475
optimizing_img = Variable(init_img, requires_grad=True)
7576

@@ -80,9 +81,7 @@ def neural_style_transfer(config):
8081
style_img_set_of_feature_maps = neural_net(style_img)
8182

8283
target_content_representation = content_img_set_of_feature_maps[content_feature_maps_index_name[0]].squeeze(axis=0)
83-
8484
target_style_representation = [utils.gram_matrix(x) for cnt, x in enumerate(style_img_set_of_feature_maps) if cnt in style_feature_maps_indices_names[0]]
85-
8685
target_representations = [target_content_representation, target_style_representation]
8786

8887
# magic numbers in general are a big no no - some things in this code are left like this by design to avoid clutter

utils/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def prepare_img(img_path, target_shape, device):
4141
img = load_image(img_path, target_shape=target_shape)
4242

4343
# normalize using ImageNet's mean
44-
# [0, 255] range works much better than [0, 1] range
44+
# [0, 255] range worked much better for me than [0, 1] range (even though PyTorch models were trained on latter)
4545
transform = transforms.Compose([
4646
transforms.ToTensor(),
4747
transforms.Lambda(lambda x: x.mul(255)),

utils/video_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ def create_video_from_intermediate_results(results_path, img_format):
1212
first_frame = 0
1313
number_of_frames_to_process = len(os.listdir(results_path)) # default don't trim take process every frame
1414

15-
ffmpeg = 'ffmpeg.exe'
16-
if shutil.which(ffmpeg): # if ffmpeg.exe is in system path
15+
ffmpeg = 'ffmpeg'
16+
if shutil.which(ffmpeg): # if ffmpeg is in system path
1717
img_name_format = '%' + str(img_format[0]) + 'd' + img_format[1] # example: '%4d.png' for (4, '.png')
1818
pattern = os.path.join(results_path, img_name_format)
1919
out_video_path = os.path.join(results_path, out_file_name)

0 commit comments

Comments
 (0)