Deep Dream Video - Unconventional Neural Networks in Python and Tensorflow p.9




What's going on everyone and welcome to part 9 of our "unconventional" neural networks series. We've created many deep dream images up to this point, and now we're looking to convert them to video.

To do this, we're going to use cv2's VideoWriter, but there are many ways where you can take many images and make them videos. We'll start with some imports:

import cv2
import os

dream_name = 'starry_night'
dream_path = 'dream/{}'.format(dream_name)

Now for the video codec:

# windows:
fourcc = cv2.VideoWriter_fourcc(*'XVID')
# Linux:
#fourcc = cv2.VideoWriter_fourcc('M','J','P','G')

Next for the output file format/settings:

out = cv2.VideoWriter('{}.avi'.format(dream_name),fourcc, 30.0, (800,450))

This means it's a 30FPS 800x450 video that will be output.

Next, somehow we're going to iterate over files, so I am just going to look for the stopping point:

for i in range(999999999999999999999999999):
    if os.path.isfile('dream/{}/img_{}.jpg'.format(dream_name,i+1)):
        pass
    else:
        dream_length = i
        break

Now that we have the maximum length:

for i in range(dream_length):
    img_path = os.path.join(dream_path,'img_{}.jpg'.format(i))
    print(img_path)
    frame = cv2.imread(img_path)
    out.write(frame)

out.release()

We write this frame out to our file for every frame we have. Once we're done, our video is complete! Now you can make something like:


Alright. In the next tutorials, we're going to be switching gears and playing around with sequence to sequence models. Just about everything life can be mapped to being a sequence causing another sequence, where both the input sequence and output sequence might be varying in length.

The next tutorial:





  • Generative Model Basics (Character-Level) - Unconventional Neural Networks in Python and Tensorflow p.1
  • Generating Pythonic code with Character Generative Model - Unconventional Neural Networks in Python and Tensorflow p.2
  • Generating with MNIST - Unconventional Neural Networks in Python and Tensorflow p.3
  • Classification Generator Training Attempt - Unconventional Neural Networks in Python and Tensorflow p.4
  • Classification Generator Testing Attempt - Unconventional Neural Networks in Python and Tensorflow p.5
  • Drawing a Number by Request with Generative Model - Unconventional Neural Networks in Python and Tensorflow p.6
  • Deep Dream - Unconventional Neural Networks in Python and Tensorflow p.7
  • Deep Dream Frames - Unconventional Neural Networks in Python and Tensorflow p.8
  • Deep Dream Video - Unconventional Neural Networks in Python and Tensorflow p.9
  • Doing Math with Neural Networks - Unconventional Neural Networks in Python and Tensorflow p.10
  • Doing Math with Neural Networks testing addition results - Unconventional Neural Networks in Python and Tensorflow p.11
  • Complex Math - Unconventional Neural Networks in Python and Tensorflow p.12