what's going on everybody and welcome to
part 9 of our unconventional neural
network series in this part we're going
to be wrapping up the deep dream and
creating a video from the frames of our
deep dream so what we can see here is
that we've got about 127 frames in and
exemplified here is what I was talking
about where it slowly gets darker and
darker generally you know you can just
probably add three here or four and we
probably could have combat that but
anyway I'm just trying to show a really
quick example so I didn't really bother
worrying about it too much but that's a
at least exemplifies what I was talking
about so now what we're gonna do is
write some code to convert these frames
to video so I'm gonna go ahead and just
do new file
I don't know dream underscore video dot
pi yes and let's open in sublime and I'm
just gonna move this some let me know
how I can clear it like how do I get rid
of this open I know there's like a way
to like change maybe do that Kong let's
see you hide panel hey there it is nice
all right so we're gonna do is I'm gonna
use CV to just because we've already
been using it I'm gonna import OS and
now we're gonna specify the name of the
dream at least in my case that's starry
night the starry night that is and then
dream dream path will put as and in fact
I'm not even sure we need I guess we'll
look into you probably don't you
actually need to define a dream path but
whatever so to be dream and then we'll
use some string formatting and then
format
dream name so now this will be for the
codec part it depends on if you're on
Windows or Linux so if you're on Windows
the codec that you would use here would
be for C C equals C v2 dot video writer
underscore for CC and then it's Astra
X vid and if you were on linux it would
be Linux rather than this it's M jpg
right but all in separate quotes not
really sure here m j p g-- if you're on
linux which i'm not right now so boom
now the next thing that we're gonna do
is we're gonna specify where do we want
this stuff to go okay shut up making the
linter happy out equals c v2 dot video
writer and then we'll just say something
a VI dot format whatever the dream name
is we're gonna use the for CC whatever
that happens to be
then you're gonna specify how many
frames per second you want i'm gonna go
with like 20 because we have so few but
the the more obviously you have the
smoother it is it also depends on what
how quickly you were zooming in and how
big your overall images so on like a
1080p image at the rate that we're
zooming in you can easily do 60 frames a
second for like super smooth but it
really just depends if you did what we
just did here at 60 frames a second it's
like a rook it's a pretty quick zoom and
then finally the size ours is at 800 by
450 it has to match the input if it
doesn't match the input it's gonna get
angry with you okay so this will produce
the 20 frames per second 800 by 450
video now for I in range of basically
however many you have I'll just throw in
a some sort of number here if OS dot
path dot is file basically what we're
gonna do is because we need it bit we
need to know what the length of our
dream is so I guess we're kind of let's
see if we can just take this code so I
think that's basically what we're doing
so it should just be like the exact same
logic I'm doing here I'm sure somebody
can come up with some better logic than
this if you do go ahead and just share
it with us
else we're gonna say dream length equals
whatever that is and then we'll break
all we were trying to figure out is how
how long that dream is that's it
do we still have any here no so at this
point now what we want to do is for I in
range of whatever that dream length is
we're gonna build the frames of our cv2
right video writer so we're gonna say
image path equals OS path dot join and
we're gonna join the dream path and then
basically it's that it was image
underscore whatever the number is dot
jpg and then dot format whatever I is so
that's the path to the actual image
itself for now let's go ahead and print
the image path just so we know where we
are along the way then what we're gonna
go ahead and do is the frame itself is
equal to cv to dot M read whatever that
image path is and then finally we're
going to out dot write the frame and
then when we're all done out dot release
it's like closing the file after you've
done after you've been done modifying it
so let's go ahead and run that see if we
have errors it looks like it's already
done let's move this out of the way
should make starry night dot avi don't
click on that and sure enough there is
our deep dream going at 20 frames per
second and getting dark pretty quickly
okay and this is the other one and
basically I just have it going 1
basically all through all of the
different layers at a time and and then
I'll just do the outro as that plays
also I'll probably put this as a
standalone video I don't really know yet
I'll put a link in the description if I
do otherwise yeah so that's it with the
deep dreaming if you have any questions
comments concerns whatever on deep
dreaming
feel free to leaving below if you've got
fix's for the various things that we we
didn't change and all that you can let
me know like the stuff like the ranges
through like nine just to figure out
where we should start from I'm sure
there's a better more logical way I just
I figure like if you're gonna go through
like you would you would go through the
directories so like no matter what
you're gonna be iterating through a list
so I'm not really sure if there's a
truly a more efficient way or not but
I'd be curious about some sort of more
pythonic way than the way I've done it
there anyway I think that's it in the
next and the coming tutorials what we're
going to be focusing on is we're gonna
kind of change gears into doing math
with neural networks which typically a
neural network is generally better at
doing like nonlinear tasks whereas in
like typically machines and programs are
very good at doing linear things like
math but deep learning is not so good at
deep at linear things because it's
actually looking for nonlinear
relationships or at least that's what
it's good at so doing something like
math which is highly linear in most
cases it's not an easy thing for a
normal Network but if we could get a
neural network to do math especially
maybe even some of the nonlinear forms
of math that could be pretty interesting
so anyways that's what we're doing in
the coming tutorials is trying to get
neural networks to do math but if you
have any questions on deep dreaming and
all that you can feel free leaving below
otherwise you can stay tuned for the
release of this one whenever it's
finally done I am on the final layer
this is the final layer as you can see
there's a lot going on there
but it's probably gonna take a little
longer just to finish all of that
because these are going so slow once you
get that deep into the layers they
process super slow but anyways that's
what you guys have to look forward to if
you're enjoying the content you can
support at Python program internet slash
support if you've got questions comments
concerns whatever tips about better ways
to have written the code you can leave
your comments down below otherwise I
will see you in the coming tutorials
where we write hopefully a neural
network that can sort of understand math
and then do things like try to break
encryption and all that kind of fun
stuff so that's what you guys
look forward to I will see you in
another video