Skip to content
Open
Show file tree
Hide file tree
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
26 changes: 6 additions & 20 deletions 2018-Python-Practice-master/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@
from datetime import datetime

import tensorflow as tf
from styler.video import Video
from styler.utils import save_video

'''
1. import `Video` and `save_video` from the correct module of package "styler"
'''
from ... import Video
from ... import save_video


vedio_path = './input/jaguar.mp4'
model_file = 'data/vg-30.pb'
model_name = 'vg-30'
logging.basicConfig(
Expand Down Expand Up @@ -38,30 +34,20 @@ def main():
out = graph.get_tensor_by_name("import/%s/output:0" % model_name)
shape = image.get_shape().as_list()

'''
2. set the `path` to your input
'''
with Video(...) as v:
with Video(vedio_path) as v:
frames = v.read_frames(image_h=shape[1], image_w=shape[2])

logging.info("Processing image")
start_time = datetime.now()

'''
3. Write a list comprehension to iterate through all frames,
and make it be processed by Tensorflow.
'''
processed = [
session.run(out, feed_dict={image: [frame]})
...
for frame in frames
]

'''
4. Pass the results as a argument into function
'''
save_video('result.mp4',
fps=30, h=shape[1], w=shape[2],
frames=...)
frames=processed)

logging.info("Processing took %f" % (
(datetime.now() - start_time).total_seconds()))
Expand Down
19 changes: 7 additions & 12 deletions 2018-Python-Practice-master/styler/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,13 @@ def __len__(self):
return len(self.frames)

def read_frames(self, image_h, image_w):
'''
5.
- Read video frames from `self.cap` and collect frames into list
- Apply `resize()` on each frame before add it to list
- Also assign frames to "self" object
- Return your results
'''
frames = []
# 5-1 /5-2 Read video and collect them

self.frames = ... # 5-3 let object have the result
return ... # return your results
while self.cap.isOpened():
ret, frame = self.cap.read()
if ret:
self.frames.append(resize(frame, image_h, image_w))
else: break

return self.frames

def __exit__(self, exc_type, exc_val, exc_tb):
self.cap.release()