Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed first frame query in render_video() #101

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions neural_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ def parse_args():
default='frame_{}.ppm',
help='Filename format of the input content frames.')

parser.add_argument('--optical_flow_dir', type=str,
default='./video_input',
help='Relative or absolute directory path to forward and backward optical flow and consistency frames.')

parser.add_argument('--backward_optical_flow_frmt', type=str,
default='backward_{}_{}.flo',
help='Filename format of the backward optical flow files.')
Expand Down Expand Up @@ -574,7 +578,7 @@ def stylize(content_img, style_imgs, init_img, frame=None):
L_total += theta * L_tv

# video temporal loss
if args.video and frame > 1:
if args.video and frame > args.start_frame:
gamma = args.temporal_weight
L_temporal = sum_shortterm_temporal_losses(sess, net, frame, init_img)
L_total += gamma * L_temporal
Expand Down Expand Up @@ -762,7 +766,7 @@ def get_prev_warped_frame(frame):
prev_frame = frame - 1
# backwards flow: current frame -> previous frame
fn = args.backward_optical_flow_frmt.format(str(frame), str(prev_frame))
path = os.path.join(args.video_input_dir, fn)
path = os.path.join(args.optical_flow_dir, fn)
flow = read_flow_file(path)
warped_img = warp_image(prev_img, flow).astype(np.float32)
img = preprocess(warped_img)
Expand All @@ -771,8 +775,8 @@ def get_prev_warped_frame(frame):
def get_content_weights(frame, prev_frame):
forward_fn = args.content_weights_frmt.format(str(prev_frame), str(frame))
backward_fn = args.content_weights_frmt.format(str(frame), str(prev_frame))
forward_path = os.path.join(args.video_input_dir, forward_fn)
backward_path = os.path.join(args.video_input_dir, backward_fn)
forward_path = os.path.join(args.optical_flow_dir, forward_fn)
backward_path = os.path.join(args.optical_flow_dir, backward_fn)
forward_weights = read_weights_file(forward_path)
backward_weights = read_weights_file(backward_path)
return forward_weights #, backward_weights
Expand Down Expand Up @@ -829,7 +833,7 @@ def render_video():
for frame in range(args.start_frame, args.end_frame+1):
with tf.Graph().as_default():
print('\n---- RENDERING VIDEO FRAME: {}/{} ----\n'.format(frame, args.end_frame))
if frame == 1:
if frame == args.start_frame:
content_frame = get_content_frame(frame)
style_imgs = get_style_images(content_frame)
init_img = get_init_image(args.first_frame_type, content_frame, style_imgs, frame)
Expand Down