Last active
January 16, 2018 02:45
-
-
Save SeaOfOcean/35f3fd72e55da59c8dc3a210f2b7f69e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# load model and apply quantization | |
model = Model.loadModel("bigdl_messi.model").quantize() | |
# load dataset | |
myclip = VideoFileClip("messi_clip.mp4") | |
video_rdd = sc.parallelize(myclip.iter_frames(fps=5)) | |
image_frame = DistributedImageFrame(video_rdd) | |
# Define Predictor Configure | |
preprocess = Pipeline([Resize(300, 300), ChannelNormalize(123.0, 117.0, 104.0), MatToTensor(), ImageFrameToSample()]) | |
postprocess = ScaleDetection() | |
label_map = {0: '__background__', 1: 'messi'} | |
configure = Configure(preprocess, postprocess, 2, label_map) | |
# Predict and visualize detection back to clips | |
predictor = Predictor(model, configure) | |
output = predictor.predict(image_frame) | |
visualizer = Visualizer(predictor.configure.label_map()) | |
results = visualizer(output).get_image(to_chw=False).collect() | |
# save clip to video | |
clip = ImageSequenceClip(results, fps=5) | |
%time clip.write_videofile('/tmp/out.mp4', audio=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment