Feed-forward method | Neural Style Transfer #5

Aleksa Gordić - The AI Epiphany
2 Jun 202007:04

Summary

TLDRDieses Video bietet eine kurze und übersichtliche Einführung in das schnelle neuronale Stilübertragungsverfahren von Johnson. Der Uploader hat das Originalpapier neu erstellt und zeigt die Ergebnisse mithilfe von vorgefertigten Modellen. Es wird erläutert, wie man seine Umgebung einrichtet, die vorausgetrainierten Modelle lädt und das Stylisierungsskript ausführt. Der Fokus liegt auf der Verwendung von PyTorch-Modellen und der Bedeutung des Einstellungsmodus für die Inferenz. Ein Blick auf die Funktionsweise des Skripts zeigt, wie das Modell die Stilisierung durchführt und das Ergebnis speichert. Das nächste Video wird sich mit dem Training befassen, einschließlich der Verwendung von TensorBoard für Debugging und die Visualisierung von Trainingsmetriken.

Takeaways

  • 🖌️ Der Videoinhalt behandelt das schnelle neuronale Stilübertragungsverfahren von Johnson, welches auf einer CMM-basierten Methode beruht im Gegensatz zur optimierungsbasierten Gatos-Methode.
  • 📈 Der Videoersteller hat das Originalpapier von Johnson rekonstruiert und zeigt Ergebnisse mithilfe von vorgefertigten Modellen, die er zuvor trainiert hat.
  • 🔍 Im Video werden vier verschiedene Modelle vorgestellt, wobei das obere Modell vollständig trainiert wurde und das untere Modell auf der gesamten ms-coco-Datenbank trainiert wurde, was etwa 83.000 Bilder umfasst.
  • 💾 Es wird ein Download-Skript für vorgefertigte Modelle vorgestellt, das diese aus einem Dropbox-Ordner herunterlädt, entpackt und in einen lokalen Ordner speichert.
  • 🛠️ Die zweite Schritt ist das Ausführen eines Sterilisationsskripts, das mit Standardparametern Ergebnisse liefert und wie das Skript funktioniert wird kurz erklärt.
  • 📁 Das Skript speichert die Ergebnisse in einem bestimmten Ordner, sodass sie später leicht gefunden werden können.
  • 🔧 Die Funktionsweise des Sterilisationsskripts wird detailliert erklärt, einschließlich der Überprüfung der Modelldateien, Erstellung des Ausgabeverzeichnisses und der Argumente, die für das Styling verwendet werden.
  • 🖥️ Das Skript prüft, ob die Hardware GPU-Unterstützung hat, und lädt dann das Modell, das die Stilisierung durchführt, und setzt es in den Evaluierungsmodus für die Inferenz.
  • 🎨 Die 'prepare_image'-Funktion wird besprochen, die Bilder lädt, normalisiert und auf GPU lädt, falls verfügbar, und fügt eine Patch-Dimension hinzu, um die Modellebene einzuhalten.
  • 🔄 Im nächsten Video wird der Fokus auf das Trainieren von Modellen liegen, einschließlich der Verwendung von Tensorboard zur Visualisierung von Trainingsmetriken.

Q & A

  • Was ist das Hauptthema des Videos?

    -Das Hauptthema des Videos ist die schnelle neuronale Stilübertragung basierend auf der Arbeit von Johnson, insbesondere im Vergleich zur Gatos-Methode, die auf Optimierung basiert.

  • Was ist der Unterschied zwischen der CMM-basierten und der Gatos-basierten Ansätze?

    -Die CMM-basierte Methode, die im Video behandelt wird, ist eine andere Art der neuronalen Stilübertragung als die Gatos-Methode, die auf einer Optimierungsbasis beruht. Die CMM-basierte Methode scheint schneller zu sein und verwendet eine andere Technik.

  • Wie viele Modelle wurden im Video erwähnt und wie viele davon wurden vollständig trainiert?

    -Im Video wurden vier Modelle erwähnt, aber nur das obere Modell wurde vollständig trainiert, indem es eine Box des gesamten ms-coco-Datensatzes von etwa 83.000 Bildern durchgegangen ist.

  • Was ist der Zweck des Resource-Download-Skripts, das im Video erwähnt wird?

    -Das Resource-Download-Skript dient dazu, vorkalkulierte Modelle herunterzuladen, die der Uploader auf Dropbox hochgeladen hat, und sie in den Ordner 'Marvel's binaries' zu entpacken und zu speichern.

  • Wie funktioniert der 'sterilization'-Skript, das im Video verwendet wird?

    -Das 'sterilization'-Skript ist dafür verantwortlich, die vorkalkulierten Modelle mit einem Inhaltsbild zu verwenden, um ein gestyltes Bild zu erzeugen. Es wird mit Standardparametern ausgeführt und verwendet das Standardinhaltsbild, das im Datenordner 'cannon images' zu finden ist.

  • Wie kann man die Ergebnisse des 'sterilization'-Skripts finden?

    -Die Ergebnisse des 'sterilization'-Skripts werden im Ordner 'output images' gespeichert, wo sie später abgerufen werden können.

  • Was passiert, wenn man die Breite des Ausgabebildes im 'sterilization'-Skript ändert?

    -Ändert man die Breite des Ausgabebildes, so wird dies die Größe des gestylten Bildes beeinflussen. Im Video wird gezeigt, dass eine höhere Breite zu einer angenehmeneren Stilisierung führt.

  • Was ist die Bedeutung von 'torch.no_grad()' im Kontext des Videos?

    -In dem Video wird 'torch.no_grad()' verwendet, um PyTorch zu verhindern, Gradienten zu berechnen, was Speicherplatz sparen würde, da für die Inferenz keine Gradienten benötigt werden.

  • Was wird im nächsten Video behandelt?

    -Im nächsten Video wird es um das Trainieren von Modelle gehen, wobei TensorBoard verwendet wird, um die Trainingsmetriken zu debuggen und zu visualisieren.

  • Wie kann man das Repo aus dem Video ausprobieren und lernen?

    -Man kann das Repo aus dem Video ausprobieren, indem man die Schritte im Video befolgt, die Modelle herunterlädt und das 'sterilization'-Skript ausführt. Dies bietet eine gute Lern Erfahrung und ermöglicht es, das Funktionsweise der neuronalen Stilübertragung zu verstehen.

Outlines

00:00

🎨 'Fast Neural Style Transfer'-Videovorstellung

In diesem Video wird ein kurzer Überblick über das Rekonstruieren der ursprünglichen Johnson-Papers zur schnellen neuronalen Stilübertragung gegeben. Der Fokus liegt auf dem CMM-basierten Ansatz im Gegensatz zum optimierungsbasierten Gatos-Ansatz. Es werden die Ergebnisse mithilfe von vorgefertigten Modellen präsentiert, die bereits trainiert wurden. Es wird gezeigt, wie die Stilbilder in der linken Spalte und die Ausgabe der trainierten Modelle in der rechten Spalte dargestellt werden. Es wird betont, dass das obere Modell vollständig trainiert wurde und auf ca. 83.000 Bildern des MSCOCO-Datensatzes trainiert wurde, während die drei unteren Modelle noch zusätzlich trainiert werden müssen. Der Prozess der Einrichtung wird in einer Zeitlupe gezeigt, und es wird erklärt, wie man die Umgebung konfiguriert, die vortrainierten Modelle herunterlädt und die Ergebnisse erhält. Der Fokus liegt auf der Verwendung des Sterilisationsskripts mit Standardparametern, um Ergebnisse zu erhalten.

05:01

🛠️ Detaillierte Erklärung des Sterilisationsskripts

Der zweite Absatz konzentriert sich auf die Funktionsweise des Sterilisationsskripts. Es wird erklärt, wie das Skript die Standardpositionen für die Ein- und Ausgabe von Bildern, die Modelle und die Fehlerprüfung verwendet. Es wird gezeigt, wie die Argumente wie das Content-Bild, die Bildbreite und das Standardmodell 'Mosaic' verarbeitet werden. Der Prozess der Bildverarbeitung, einschließlich der Überprüfung der GPU-Unterstützung, der Erstellung des Bildpfades, der Normalisierung und der Verwendung des Transfertransformatormodells zur Stilisierung, wird detailliert beschrieben. Es wird auch die Verwendung von Torch.no_grad() zur Verringerung der Speicherauslastung und die Speicherung des gestylisierten Bildes in das Ausgabeverzeichnis erläutert. Schließlich wird die Funktion 'prepare image' aus der Utils-Bibliothek erklärt, die das Bild lädt, normalisiert und auf die GPU überträgt, um die Modellerwartungen zu erfüllen.

Mindmap

Keywords

💡Neural Style Transfer

Neural Style Transfer ist eine Technik aus der künstlichen Intelligenz, die es ermöglicht, die visuelle Struktur eines Inhaltsbildes mit dem Stil eines Stilbildes zu kombinieren. Im Video wird dies durch die Rekonstruktion des ursprünglichen Johnson-Papers demonstriert, das auf schnelle neuronale Stilübertragung abzielt. Das Ziel ist es, ein Bild so zu transformieren, dass es die visuellen Merkmale eines anderen Bildes annehmen kann, während es seine eigene Struktur beibehält.

💡CMM-basierte Ansätze

CMM steht für Content-Mode-Mapping und bezieht sich auf eine Klasse von Algorithmen, die in der Bildverarbeitung verwendet werden. Im Kontext des Videos ist der CMM-basierte Ansatz im Gegensatz zum Gatos-Ansatz, der auf einer optimierungsbasierten Methode beruht. Der CMM-Ansatz wird verwendet, um die Effizienz der neuronalen Stilübertragung zu erhöhen, indem er die Verarbeitung beschleunigt und weniger Ressourcen benötigt.

💡Vortrainierte Modelle

Vortrainierte Modelle sind künstliche neuronale Netzwerke, die auf großen Datenmengen trainiert wurden und dann für neue, ähnliche Aufgaben verwendet werden können. Im Video werden vortrainierte Modelle verwendet, um die Leistung der neuronalen Stilübertragung zu demonstrieren. Der Sprecher erwähnt, dass einige Modelle zusätzlich trainiert werden müssen, um optimale Ergebnisse zu erzielen.

💡Dataset

Ein Dataset ist eine Sammlung von Daten, die für die Ausbildung von künstlichen neuronalen Netzwerken verwendet wird. Im Video wird auf das MSCOCO-Dataset verwiesen, das eine große Anzahl von Bildern enthält und für die vollständige Schulung eines der Modelle verwendet wurde, um die Effizienz der neuronalen Stilübertragung zu demonstrieren.

💡Stilbild

Ein Stilbild ist ein Bild, das verwendet wird, um den Stil zu definieren, der auf ein Inhaltsbild übertragen werden soll. Im Video werden verschiedene Stilbilder verwendet, um die Fähigkeiten der Modelle zu testen und zu zeigen, wie sie verschiedene Stile auf ein Inhaltsbild anwenden können.

💡Inhaltsbild

Ein Inhaltsbild ist das Bild, das die visuellen Informationen behält, während es den Stil eines anderen Bildes annimmt. Im Video wird das Inhaltsbild verwendet, um die Auswirkungen der neuronalen Stilübertragung zu demonstrieren und zu zeigen, wie das Modell die gewünschten visuellen Merkmale beibehält.

💡PyTorch

PyTorch ist ein beliebtes Open-Source-Maschinelle-Lern-Framework, das von der Community entwickelt und verwendet wird. Im Video wird PyTorch verwendet, um die neuronalen Netzwerke zu implementieren, die für die Stilübertragung verantwortlich sind. Es wird erwähnt, dass die Modelle in PyTorch gespeichert und geladen werden, um die Inferenz durchzuführen.

💡TensorBoard

TensorBoard ist ein Tool, das entwickelt wurde, um die Trainingsprozesse von künstlichen neuronalen Netzwerken zu visualisieren. Im Video wird erwähnt, dass es in einem zukünftigen Video verwendet werden wird, um die Trainingsmetriken zu debuggen und zu visualisieren, was für die Verbesserung der Leistung der Modelle und das Verständnis ihrer Funktionsweise wichtig ist.

💡Stylized Static Image

Ein gestyltes statisches Bild ist das Ergebnis der neuronalen Stilübertragung, bei dem ein Inhaltsbild den Stil eines Stilbildes annimmt. Im Video wird die Funktion 'stylized_static_image' verwendet, um die Transformation des Inhaltsbildes durch das Modell zu demonstrieren und das endgültige gestylte Bild zu erzeugen.

💡GPU-Unterstützung

Die Unterstützung von GPUs (Graphics Processing Units) ist für die schnelle Verarbeitung von Daten und die effiziente Ausführung von künstlichen neuronalen Netzwerken von Bedeutung. Im Video wird erwähnt, dass das Modell überprüft, ob die GPU-Unterstützung verfügbar ist, um die Verarbeitung der Bilder zu beschleunigen und die Leistung der neuronalen Stilübertragung zu optimieren.

Highlights

Video is a concise tutorial on neural style transfer.

Reconstruction of Johnson's paper on fast neural style transfer is discussed.

Comparison between CMM-based and Gatos optimization-based approaches.

Presentation of pre-trained models and their results.

Explanation of the top row model being fully trained on 83,000 images.

Mention of the need for additional training for the bottom row models.

Demonstration of a time-lapse setup from a previous video.

Instructions for configuring the conda environment and downloading pre-trained models.

Details on running the sterilization script with default parameters.

Description of the default content image used in the sterilization script.

Explanation of the sterilization script's functionality and parameters.

Guide on how to find the saved stylized image in the output directory.

Overview of the script's error checking for PyTorch models.

Process of creating the output directory for image storage.

Description of the 'stylized static image' function and its parameters.

Discussion on checking for GPU support and image preparation.

Instantiation of the transfer transformer model for stylization.

Importance of setting the model to eval mode for inference.

Explanation of the process to convert the stylized image to a non-PI format.

Details on the 'prepare image' function and image normalization.

Mention of the next video covering training and use of tensor board.

Encouragement for viewers to experiment with the provided repo.

Call to action for subscribing, liking, and sharing the video.

Transcripts

play00:00

okay so this video is gonna be really

play00:01

nice and short I went ahead and

play00:03

reconstructed original Johnson's paper

play00:05

on fast neural style transfer since the

play00:08

CMM based approach as opposed to the

play00:10

Gatos approach which was optimization

play00:13

based let's see if some results I got

play00:16

using the for pre-trained models I

play00:18

trained beforehand so in the left column

play00:20

you can see the style images I used and

play00:23

on the right you can see the output from

play00:26

the models I trained so keep in mind

play00:27

that the the model in the top row is the

play00:30

only one that was fully trained so it's

play00:32

all like it did to e box of the whole ms

play00:36

cocoa dataset so that's around 83,000

play00:40

images whereas the three bottom ones

play00:42

still need to be additionally trained

play00:44

now I'm just gonna do a quick time-lapse

play00:46

of the setup because we already did that

play00:48

in the previous coding video

play00:50

[Music]

play00:51

[Applause]

play00:55

[Music]

play01:01

once you have your con environment

play01:04

configured there are only two more steps

play01:05

to get some results so the first one is

play01:08

go ahead and run this resource download

play01:11

or script and it will just go ahead and

play01:14

download the pre trained models that

play01:16

I've uploaded right here to this your

play01:19

URL on Dropbox it will then unzip them

play01:22

and place them in this folder here

play01:24

Marvel's binaries so you'll have for

play01:27

pre-trained models on your disposal and

play01:29

the second step is just go ahead and run

play01:31

this sterilization script it's located

play01:33

here just run it with the default

play01:36

parameters and we'll get some results

play01:37

this is the result we get using the

play01:40

default content image that's located

play01:42

here just go to data cannon images and

play01:46

this one is used by default so I'm just

play01:51

gonna go and show you a little bit about

play01:53

how the sterilization script itself

play01:55

brooks i'm gonna go ahead and stop this

play01:57

one here mm-hmm

play01:58

oops and I'm just gonna show you where

play02:01

it's actually saved it saved to the

play02:03

output images directory here so you can

play02:06

be able you'll be able to find it later

play02:07

on in this directory okay let's see how

play02:10

the script works let me close this one

play02:12

and zoom this in a little bit like this

play02:17

so what we have here is a couple of

play02:20

default locations first one is for

play02:22

continum ages and we already saw that

play02:24

one that's in here we have output images

play02:27

where the images will get dumped

play02:30

binaries where we have our models and

play02:34

this is just basic error checking here

play02:36

basically checking if if we only have

play02:39

Pytor models inside of the of this

play02:41

binaries here directory and I just

play02:46

create the output directory where we'll

play02:49

dump images and here the arguments those

play02:52

are just the content image that you want

play02:54

to use that you want to pass through the

play02:56

model then we have the you wanna set the

play03:00

width of the output image and it's set

play03:02

to 500 by default here we have default

play03:06

model that's called mosaic and we just

play03:11

wrap all of those parameters

play03:12

called stylized static image function

play03:14

let's see what this function actually

play03:16

does so we go up side here we can first

play03:20

see we first want to check out if the

play03:22

device has GPU or only CPU support and

play03:27

then we basically just create this image

play03:31

path we pass it through this function

play03:35

called prepare image which will kind of

play03:37

add a badge I mention and do some

play03:40

normalization will check the function a

play03:43

bit later and I just instantiate here

play03:46

the transfer transformer model which is

play03:49

the actual model that performs the

play03:51

stylization we figure out the state so

play03:56

we just load the state from by torch

play04:00

model that's in binaries here we print

play04:04

some metadata and we finally load the

play04:07

weights inside of the the model and we

play04:10

just put it into this eval mode which is

play04:12

really important if you want to do

play04:13

inference I want to do this when I call

play04:16

this function here and finally we just

play04:18

wrap this into this context torch no

play04:21

gret which will basically forbid pi

play04:24

torch to calculate radians which will

play04:28

which would kind of be a huge memory

play04:30

overhead so we call the model on the can

play04:33

image we just paste it to CPU we convert

play04:38

it to non PI here and because we had the

play04:40

badge dimension that we previously added

play04:42

we gotta extract the zeroth bet here and

play04:47

that's the stylized image when we just

play04:48

save the image that's the image we saw a

play04:51

couple of minutes ago that was dumped

play04:53

here into your output image folder this

play04:55

one just check out that prepare image we

play04:58

saw in the utils here so this is how it

play05:00

looks like

play05:01

you basically just loads damage from the

play05:03

specified path specified by this

play05:05

variable image path and that will just

play05:08

basically create an umpire image

play05:10

normalized to zero to one range and then

play05:14

we'll pretty much add this normalization

play05:18

transform that byte order provides us

play05:21

with and we'll use image net mean and

play05:25

standard deviation

play05:26

to normalize our images after we apply

play05:30

the transformation here we just push to

play05:33

push the this this image onto the GPU if

play05:37

you have one and we just add this patch

play05:40

dimension in front because that's that's

play05:43

because models are always expecting

play05:46

dispatch dimensions so pretty pretty

play05:48

simple stuff in the next video I'll I'll

play05:51

cover training that they'll be a bit

play05:53

more challenging we're gonna figure out

play05:55

how to use tensor board and just debug

play05:57

and visualize our our training metrics

play06:00

so let me just go ahead and try one more

play06:04

image here so I'm gonna use image called

play06:07

figures and let me set the width here to

play06:11

350 say we'll use the same model mosaic

play06:15

and if I start the one if I run it this

play06:19

is what we get so how good the output

play06:21

image will be actually depends also on

play06:23

the sides that you put here in the width

play06:25

so if I put 550 say here and I run that

play06:30

one it will have different stylization

play06:33

and it's much nicer if you ask me the

play06:36

next video will cover training until

play06:39

that time just go ahead and play with

play06:42

this repo try and figure out how the

play06:44

things work and I'll be a really nice

play06:47

here learning experience if you like the

play06:48

content go ahead and subscribe like and

play06:52

share the videos if you think they can

play06:55

bring value to somebody else see you

play06:57

next time

play06:58

[Music]

Rate This

5.0 / 5 (0 votes)

Related Tags
Neuronales StiltransferJohnsons PapierVorgefertigtes ModellCMM-AnsatzGatos-VerfahrenDatensatz MS-COCOStilübertragungMaschinelles LernenKünstliche IntelligenzProgrammierung
Do you need a summary in English?