Sprawko v0
50
.gitignore
vendored
@ -120,8 +120,6 @@ cmake-build-release/
|
||||
|
||||
## Plugin-specific files:
|
||||
|
||||
# IntelliJ
|
||||
out/
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
@ -142,3 +140,51 @@ fabric.properties
|
||||
damaged_*
|
||||
ok_*
|
||||
/dataset/
|
||||
|
||||
# common
|
||||
*.csv
|
||||
*.obj
|
||||
*.exe
|
||||
*.lst
|
||||
*.tmp
|
||||
*.pdb
|
||||
|
||||
# tex
|
||||
*.aux
|
||||
*.lof
|
||||
*.log
|
||||
*.lot
|
||||
*.fls
|
||||
*.out
|
||||
*.toc
|
||||
*.fmt
|
||||
*.fot
|
||||
*.cb
|
||||
*.cb2
|
||||
.*.lb
|
||||
*.pdf
|
||||
|
||||
/cmake-*/
|
||||
|
||||
/sprawozdanie/*-figure*
|
||||
|
||||
## Build tool auxiliary files:
|
||||
*.fdb_latexmk
|
||||
*.synctex
|
||||
*.synctex(busy)
|
||||
*.synctex.gz
|
||||
*.synctex.gz(busy)
|
||||
*.pdfsync
|
||||
*.auxlock
|
||||
|
||||
# hyperref
|
||||
*.brf
|
||||
|
||||
# listings
|
||||
*.lol
|
||||
|
||||
# makeidx
|
||||
*.idx
|
||||
*.ilg
|
||||
*.ind
|
||||
*.ist
|
||||
|
42
generate-results.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
function array_mean($array) {
|
||||
return array_sum($array) / count($array);
|
||||
}
|
||||
|
||||
$dir = $argv[1];
|
||||
$results = [];
|
||||
|
||||
$iterator = new \RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS | FilesystemIterator::CURRENT_AS_FILEINFO);
|
||||
foreach ($iterator as $file) {
|
||||
if (!$file->isFile()) continue;
|
||||
|
||||
$path = $file->getPathname();
|
||||
$lines = preg_split("/\R/", file_get_contents($path));
|
||||
$headers = str_getcsv(array_shift($lines)); // headers
|
||||
|
||||
$lines = array_map(function($line) { return preg_replace("/tensor\((.*?)\)/si", '$1', $line); }, $lines);
|
||||
$lines = array_filter($lines);
|
||||
$csv = array_map('str_getcsv', $lines);
|
||||
$csv = array_map(function($line) use($headers) { return @array_combine($headers, $line); }, $csv);
|
||||
|
||||
$result[(int)str_replace('loss_epoch_', '', $file->getBasename('.csv'))] = [
|
||||
'generator' => array_mean(array_column($csv, 'g_loss')),
|
||||
'discriminator' => array_mean(array_column($csv, 'd_loss')),
|
||||
'data' => $csv
|
||||
];
|
||||
}
|
||||
|
||||
ksort($result);
|
||||
echo "epoch,g,d\n";
|
||||
// foreach($result as $epoch => $loss) {
|
||||
// echo sprintf("%d,%.4f,%.4f\n", $epoch, $loss['generator'], $loss['discriminator']);
|
||||
// }
|
||||
$iteration = 0;
|
||||
foreach($result as $epoch => $loss) {
|
||||
foreach($loss['data'] as $row) {
|
||||
if ($iteration++ % 5 != 0) continue;
|
||||
|
||||
echo sprintf("%.4f,%.4f,%.4f\n", $iteration/100., $row['g_loss'], $row['d_loss']);
|
||||
}
|
||||
}
|
BIN
sprawozdanie/oczekiwane.jpg
Normal file
After Width: | Height: | Size: 72 KiB |
BIN
sprawozdanie/out/13_1.jpg
Normal file
After Width: | Height: | Size: 5.6 KiB |
BIN
sprawozdanie/out/13_128.jpg
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
sprawozdanie/out/13_16.jpg
Normal file
After Width: | Height: | Size: 6.7 KiB |
BIN
sprawozdanie/out/13_2.jpg
Normal file
After Width: | Height: | Size: 5.6 KiB |
BIN
sprawozdanie/out/13_200.jpg
Normal file
After Width: | Height: | Size: 6.2 KiB |
BIN
sprawozdanie/out/13_32.jpg
Normal file
After Width: | Height: | Size: 7.0 KiB |
BIN
sprawozdanie/out/13_4.jpg
Normal file
After Width: | Height: | Size: 5.7 KiB |
BIN
sprawozdanie/out/13_64.jpg
Normal file
After Width: | Height: | Size: 6.5 KiB |
BIN
sprawozdanie/out/13_8.jpg
Normal file
After Width: | Height: | Size: 6.2 KiB |
BIN
sprawozdanie/out/13_damaged.jpg
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
sprawozdanie/out/13_ok.jpg
Normal file
After Width: | Height: | Size: 6.9 KiB |
BIN
sprawozdanie/out/18_1.jpg
Normal file
After Width: | Height: | Size: 5.3 KiB |
BIN
sprawozdanie/out/18_128.jpg
Normal file
After Width: | Height: | Size: 6.2 KiB |
BIN
sprawozdanie/out/18_16.jpg
Normal file
After Width: | Height: | Size: 5.8 KiB |
BIN
sprawozdanie/out/18_2.jpg
Normal file
After Width: | Height: | Size: 5.6 KiB |
BIN
sprawozdanie/out/18_200.jpg
Normal file
After Width: | Height: | Size: 7.0 KiB |
BIN
sprawozdanie/out/18_32.jpg
Normal file
After Width: | Height: | Size: 6.5 KiB |
BIN
sprawozdanie/out/18_4.jpg
Normal file
After Width: | Height: | Size: 5.6 KiB |
BIN
sprawozdanie/out/18_64.jpg
Normal file
After Width: | Height: | Size: 6.8 KiB |
BIN
sprawozdanie/out/18_8.jpg
Normal file
After Width: | Height: | Size: 5.6 KiB |
BIN
sprawozdanie/out/18_damaged.jpg
Normal file
After Width: | Height: | Size: 6.2 KiB |
BIN
sprawozdanie/out/18_ok.jpg
Normal file
After Width: | Height: | Size: 7.7 KiB |
BIN
sprawozdanie/out/34_1.jpg
Normal file
After Width: | Height: | Size: 5.2 KiB |
BIN
sprawozdanie/out/34_128.jpg
Normal file
After Width: | Height: | Size: 6.2 KiB |
BIN
sprawozdanie/out/34_16.jpg
Normal file
After Width: | Height: | Size: 6.3 KiB |
BIN
sprawozdanie/out/34_2.jpg
Normal file
After Width: | Height: | Size: 5.2 KiB |
BIN
sprawozdanie/out/34_200.jpg
Normal file
After Width: | Height: | Size: 6.3 KiB |
BIN
sprawozdanie/out/34_32.jpg
Normal file
After Width: | Height: | Size: 6.5 KiB |
BIN
sprawozdanie/out/34_4.jpg
Normal file
After Width: | Height: | Size: 5.5 KiB |
BIN
sprawozdanie/out/34_64.jpg
Normal file
After Width: | Height: | Size: 6.6 KiB |
BIN
sprawozdanie/out/34_8.jpg
Normal file
After Width: | Height: | Size: 5.8 KiB |
BIN
sprawozdanie/out/34_damaged.jpg
Normal file
After Width: | Height: | Size: 6.1 KiB |
BIN
sprawozdanie/out/34_ok.jpg
Normal file
After Width: | Height: | Size: 5.2 KiB |
BIN
sprawozdanie/out/4_1.jpg
Normal file
After Width: | Height: | Size: 5.2 KiB |
BIN
sprawozdanie/out/4_128.jpg
Normal file
After Width: | Height: | Size: 6.1 KiB |
BIN
sprawozdanie/out/4_16.jpg
Normal file
After Width: | Height: | Size: 6.1 KiB |
BIN
sprawozdanie/out/4_2.jpg
Normal file
After Width: | Height: | Size: 5.1 KiB |
BIN
sprawozdanie/out/4_200.jpg
Normal file
After Width: | Height: | Size: 5.9 KiB |
BIN
sprawozdanie/out/4_32.jpg
Normal file
After Width: | Height: | Size: 6.8 KiB |
BIN
sprawozdanie/out/4_4.jpg
Normal file
After Width: | Height: | Size: 5.2 KiB |
BIN
sprawozdanie/out/4_64.jpg
Normal file
After Width: | Height: | Size: 6.6 KiB |
BIN
sprawozdanie/out/4_8.jpg
Normal file
After Width: | Height: | Size: 6.0 KiB |
BIN
sprawozdanie/out/4_damaged.jpg
Normal file
After Width: | Height: | Size: 5.5 KiB |
BIN
sprawozdanie/out/4_ok.jpg
Normal file
After Width: | Height: | Size: 9.8 KiB |
BIN
sprawozdanie/out/pjm_1.jpg
Normal file
After Width: | Height: | Size: 5.0 KiB |
BIN
sprawozdanie/out/pjm_128.jpg
Normal file
After Width: | Height: | Size: 6.8 KiB |
BIN
sprawozdanie/out/pjm_16.jpg
Normal file
After Width: | Height: | Size: 6.0 KiB |
BIN
sprawozdanie/out/pjm_2.jpg
Normal file
After Width: | Height: | Size: 5.3 KiB |
BIN
sprawozdanie/out/pjm_200.jpg
Normal file
After Width: | Height: | Size: 7.0 KiB |
BIN
sprawozdanie/out/pjm_32.jpg
Normal file
After Width: | Height: | Size: 6.8 KiB |
BIN
sprawozdanie/out/pjm_4.jpg
Normal file
After Width: | Height: | Size: 5.1 KiB |
BIN
sprawozdanie/out/pjm_64.jpg
Normal file
After Width: | Height: | Size: 6.9 KiB |
BIN
sprawozdanie/out/pjm_8.jpg
Normal file
After Width: | Height: | Size: 5.3 KiB |
BIN
sprawozdanie/out/pjm_damaged.jpg
Normal file
After Width: | Height: | Size: 63 KiB |
BIN
sprawozdanie/out/pjm_ok.jpg
Normal file
After Width: | Height: | Size: 63 KiB |
BIN
sprawozdanie/out/t_1.jpg
Normal file
After Width: | Height: | Size: 5.0 KiB |
BIN
sprawozdanie/out/t_128.jpg
Normal file
After Width: | Height: | Size: 6.7 KiB |
BIN
sprawozdanie/out/t_16.jpg
Normal file
After Width: | Height: | Size: 5.4 KiB |
BIN
sprawozdanie/out/t_2.jpg
Normal file
After Width: | Height: | Size: 5.0 KiB |
BIN
sprawozdanie/out/t_200.jpg
Normal file
After Width: | Height: | Size: 6.7 KiB |
BIN
sprawozdanie/out/t_32.jpg
Normal file
After Width: | Height: | Size: 6.0 KiB |
BIN
sprawozdanie/out/t_4.jpg
Normal file
After Width: | Height: | Size: 5.2 KiB |
BIN
sprawozdanie/out/t_64.jpg
Normal file
After Width: | Height: | Size: 6.8 KiB |
BIN
sprawozdanie/out/t_8.jpg
Normal file
After Width: | Height: | Size: 4.9 KiB |
BIN
sprawozdanie/out/t_damaged.jpg
Normal file
After Width: | Height: | Size: 35 KiB |
BIN
sprawozdanie/out/t_ok.jpg
Normal file
After Width: | Height: | Size: 35 KiB |
169
sprawozdanie/sprawozdanie.tex
Normal file
@ -0,0 +1,169 @@
|
||||
\documentclass[]{article}
|
||||
\usepackage[T1]{fontenc}
|
||||
\usepackage{polski}
|
||||
\usepackage[utf8]{inputenc}
|
||||
\usepackage[margin=1.25in]{geometry}
|
||||
\usepackage{alltt}
|
||||
\usepackage{titling}
|
||||
\usepackage{pdfpages}
|
||||
\usepackage{float}
|
||||
\usepackage{amsmath}
|
||||
\usepackage{booktabs}
|
||||
\usepackage{tabularx}
|
||||
\usepackage{amstext}
|
||||
\usepackage{pgfplots}
|
||||
\usepackage{tikz}
|
||||
\usepackage{xspace}
|
||||
\usepackage{enumerate}
|
||||
\usepackage{lmodern}
|
||||
\usepackage{amsfonts}
|
||||
\usepackage{mathtools}
|
||||
\usepackage{graphicx}
|
||||
\usepackage{algorithm}
|
||||
\usepackage{algpseudocode}
|
||||
\usepackage{wrapfig}
|
||||
\usepackage[polish]{babel}
|
||||
\usepackage{etoolbox}
|
||||
\usepackage{subcaption}
|
||||
\usepackage{multirow} % kurwa
|
||||
|
||||
\pgfplotsset{compat=1.15}
|
||||
\usepgfplotslibrary{groupplots}
|
||||
|
||||
\DeclarePairedDelimiter\ceil{\lceil}{\rceil}
|
||||
\DeclarePairedDelimiter\floor{\lfloor}{\rfloor}
|
||||
|
||||
\usetikzlibrary{decorations.pathmorphing, arrows.meta, positioning}
|
||||
\usetikzlibrary{shapes.geometric, arrows, intersections}
|
||||
\usetikzlibrary{external}
|
||||
\tikzexternalize
|
||||
|
||||
\pgfdeclarelayer{background}
|
||||
\pgfdeclarelayer{foreground}
|
||||
\pgfsetlayers{background,main,foreground}%
|
||||
|
||||
% opening
|
||||
\title{Retusz starych zdjęć \\ \small{Projekt ze Sztzucznej Inteligencji, WETI, PG 2018}}
|
||||
\author{\protect\begin{tabular}{ll|l}
|
||||
Szymon Szczyrbak & \textit{165760} & Informatyka 2016/2017 \\
|
||||
Kacper Donat & \textit{165581} & Semest IV, gr. 1
|
||||
\protect\end{tabular}}
|
||||
\floatname{algorithm}{Program}
|
||||
|
||||
\makeatletter
|
||||
\newcommand{\imgresult}[1]{%
|
||||
\gdef\tablerow{
|
||||
\includegraphics[height=1.6cm]{out/#1_damaged.jpg} &%
|
||||
\foreach \v in {damaged,1,2,4,8,16,32,64,128,200} {%
|
||||
\includegraphics[height=1.6cm]{out/#1_\v.jpg} &%
|
||||
}%
|
||||
\includegraphics[height=1.6cm]{out/#1_ok.jpg} \\%
|
||||
}%
|
||||
}
|
||||
\makeatother
|
||||
|
||||
\begin{document}
|
||||
\maketitle
|
||||
\section{Cel projektu}
|
||||
Celem projektu było przygotowanie programu, który w sposób automatyczny umożliwiałby retuszowanie starych zdjęć z
|
||||
wykorzystaniem technik sztucznej inteligencji.
|
||||
|
||||
\begin{figure}[H]
|
||||
\centering
|
||||
\includegraphics{./oczekiwane.jpg}
|
||||
\caption{Oczekiwany rezultat działania aplikacji}
|
||||
\end{figure}
|
||||
|
||||
Do realizacji celu zdecydowano się wykorzystać technikę GAN\footnote{https://arxiv.org/abs/1406.2661} zakładającą
|
||||
stworzenie 2 sieci neuronowych, próbujących się wzajemnie oszukać. Jedna sieć - Generator - odpowiada za generowanie danych na
|
||||
podstawie wektora wejściowego (w tym wypadku uszkodzonego zdjęcia) starając się przekonać drugą sieć -
|
||||
Dyskryminatora - że jest to nieuszkodzone zdjęcie.
|
||||
|
||||
\subsection{Pozyskanie datasetu}
|
||||
Jednym z problemów, na które natknęliśmy się podczas opracowywania rozwiązania był brak dostępnego wystarczająco
|
||||
dużego datasetu, mogącego posłużyc do wyuczenia sieci. aby poradzić sobie z tym problemem została napisana aplikacja
|
||||
umożliwająca generyczne niszczenie zdjęć.
|
||||
|
||||
\begin{figure}[H]
|
||||
\centering
|
||||
\begin{tikzpicture}[node distance=1.5cm]
|
||||
\node (in) {\includegraphics[height=2cm]{steps/in.jpg}};
|
||||
\node[right=of in] (sepia) {\includegraphics[height=2cm]{steps/sepia.jpg}};
|
||||
\node[right=of sepia] (brightness) {\includegraphics[height=2cm]{steps/brightness.jpg}};
|
||||
\node[below=of in] (noise) {\includegraphics[height=2cm]{steps/noise.jpg}};
|
||||
\node[right=of noise] (decals) {\includegraphics[height=2cm]{steps/decals.jpg}};
|
||||
\node[right=of decals] (blur) {\includegraphics[height=2cm]{steps/blur.jpg}};
|
||||
|
||||
\draw [->] (in) -- node [above] {sepia} (sepia);
|
||||
\draw [->] (sepia) -- node [above] {jasność} (brightness);
|
||||
\draw [->] (brightness) -- node [sloped, above] {szum} (noise);
|
||||
\draw [->] (noise) -- node [above] {zniszczenia} (decals);
|
||||
\draw [->] (decals) -- node [above] {rozmycie} (blur);
|
||||
\end{tikzpicture}
|
||||
\caption{Proces niszczenia zdjęć}
|
||||
\end{figure}
|
||||
|
||||
Każdy z kroków jest parametryzowalny, oraz każde zdjęcie zawiera losową zmianę do parametru w celu zapobiegnięcia
|
||||
zbyt szybkiemu overfittingowi sieci.
|
||||
|
||||
\section{Rezultaty}
|
||||
\begin{center}\textit{\color{red} wstaw budowę sieci plox}\end{center}
|
||||
|
||||
\begin{figure}[H]
|
||||
\centering
|
||||
\begin{tikzpicture}
|
||||
\begin{axis}[grid=both, width=\linewidth, height=8cm, no marks, xmin=0, xmax=200, xlabel={Epoka}, ylabel={Strata}]
|
||||
\addplot[very thin, blue] table [x=epoch,y=g,col sep=comma] {iterations.csv};
|
||||
\addplot[very thick] table [x=epoch,y=g,col sep=comma] {loss.csv};
|
||||
\end{axis}
|
||||
\end{tikzpicture}
|
||||
\caption{Funkcja straty dla generatora}
|
||||
\label{fig:results}
|
||||
\end{figure}
|
||||
|
||||
\begin{figure}[H]
|
||||
\centering
|
||||
\begin{tikzpicture}
|
||||
\begin{axis}[grid=both, width=\linewidth, height=8cm, no marks, xmin=0, xmax=200, xlabel={Epoka}, ylabel={Strata}]
|
||||
\addplot[very thin, red] table [x=epoch,y=d,col sep=comma] {iterations.csv};
|
||||
\addplot[very thick] table [x=epoch,y=d,col sep=comma] {loss.csv};
|
||||
\end{axis}
|
||||
\end{tikzpicture}
|
||||
\caption{Funkcja straty dla dyskryminatora}
|
||||
\end{figure}
|
||||
|
||||
\begin{table}[H]
|
||||
\centering
|
||||
\def\arraystretch{.6}
|
||||
\setlength{\tabcolsep}{0pt} % for the horizontal padding
|
||||
\begin{tabular}{cccccccccccc}
|
||||
zniszczone & 1 & 2 & 4 & 8 & 16 & 32 & 64 & 128 & 200 & oczekiwane \tabularnewline \hline
|
||||
\input{table.tex}
|
||||
\end{tabular}
|
||||
\caption{Zestawienie wyników dla kolejnych epok, zdjęcia z 3 oraz 4 rzędu pochodzą z internetu, pozostałe zostały zniszczone generycznie}
|
||||
\end{table}
|
||||
|
||||
\subsection{Obserwacje}
|
||||
Powyższe dane zostały pozyskane z uczenia sieci na datasecie zawierajacym 100 różnych elementów. W zestawieniu
|
||||
\ref{fig:results} wyraźnie widać, że wraz z każdą generacją generator osiąga coraz lepsze wyniki jednak, od pewnego
|
||||
momentu szybkość uczenia się zdecydowanie maleje.
|
||||
|
||||
\subsection{Problemy}
|
||||
Głównym blokujący problemem podczas rozwijania projektu były niezwykle długie czasy uczenia się sieci na CPU, oraz
|
||||
dość wysoka podatność na zmiany w parametrach sieci czy wygenerowanego datasetu, nie pozwoliło to na zrobienie zbyt
|
||||
wielu iteracji programu, a tym samym na jego skuteczny rozwój.
|
||||
|
||||
Wyraźnie również widać przekolorowanie na obrazkach oraz zmianę jasności - prawdopodobnie oba te problemy wynikają z
|
||||
zastosowania normalizacji zarówno wektora wejściowego jak i na poszczególnych etapach Generatora oraz przy konwersji
|
||||
z tensorów, którymi posługuje się do obrazów.
|
||||
|
||||
Po sprawdzeniu kilku różnych zestawu danych do uczenia się, można zauważyć, że efekty na obrazach pochodzących z
|
||||
realnego śiata są do siebie bardzo podobne, co wskazywałoby na relatywną stabilność rozwiązania i problem ze
|
||||
sposobem generowania danych, który dostarcza zbyt mało różnorodne wejście. Problem ten można by rozwiązać
|
||||
wykorzystując dataset zbudowany na podstawie kilku różnych metod generowania zniszczeń, bądź najlepiej wykorzystując
|
||||
dane pochodzące z realnego świata.
|
||||
|
||||
Dodatkową trudnością jest fakt, że sieć nie tylko musi nauczyć się generować brakujące części obrazu ale też
|
||||
decydować, które części są uszkodzeniem, a które detalem do zachowania. Problem ten widać w 3 wierszu prezentowanych
|
||||
danych - wzór na koszuli został uznany za uszkodzenie i usunięty przez sieć.
|
||||
\end{document}
|
BIN
sprawozdanie/steps/blur.jpg
Normal file
After Width: | Height: | Size: 62 KiB |
BIN
sprawozdanie/steps/brightness.jpg
Normal file
After Width: | Height: | Size: 70 KiB |
BIN
sprawozdanie/steps/decals.jpg
Normal file
After Width: | Height: | Size: 167 KiB |
BIN
sprawozdanie/steps/in.jpg
Normal file
After Width: | Height: | Size: 252 KiB |
BIN
sprawozdanie/steps/noise.jpg
Normal file
After Width: | Height: | Size: 164 KiB |
BIN
sprawozdanie/steps/sepia.jpg
Normal file
After Width: | Height: | Size: 75 KiB |
4
sprawozdanie/table.php
Normal file
@ -0,0 +1,4 @@
|
||||
<?php
|
||||
echo implode(' & ', array_map(function($v) use ($argv) {
|
||||
return "\\includegraphics[height=1.7cm]{out/{$argv[1]}_{$v}.jpg}";
|
||||
}, ['damaged', 1, 2, 4, 8, 16, 32, 64, 128, 200, 'ok']))." \\\\ ";
|
6
sprawozdanie/table.tex
Normal file
@ -0,0 +1,6 @@
|
||||
\includegraphics[height=1.6cm]{out/13_damaged.jpg} & \includegraphics[height=1.6cm]{out/13_1.jpg} & \includegraphics[height=1.6cm]{out/13_2.jpg} & \includegraphics[height=1.6cm]{out/13_4.jpg} & \includegraphics[height=1.6cm]{out/13_8.jpg} & \includegraphics[height=1.6cm]{out/13_16.jpg} & \includegraphics[height=1.6cm]{out/13_32.jpg} & \includegraphics[height=1.6cm]{out/13_64.jpg} & \includegraphics[height=1.6cm]{out/13_128.jpg} & \includegraphics[height=1.6cm]{out/13_200.jpg} & \includegraphics[height=1.6cm]{out/13_ok.jpg} \\
|
||||
\includegraphics[height=1.6cm]{out/18_damaged.jpg} & \includegraphics[height=1.6cm]{out/18_1.jpg} & \includegraphics[height=1.6cm]{out/18_2.jpg} & \includegraphics[height=1.6cm]{out/18_4.jpg} & \includegraphics[height=1.6cm]{out/18_8.jpg} & \includegraphics[height=1.6cm]{out/18_16.jpg} & \includegraphics[height=1.6cm]{out/18_32.jpg} & \includegraphics[height=1.6cm]{out/18_64.jpg} & \includegraphics[height=1.6cm]{out/18_128.jpg} & \includegraphics[height=1.6cm]{out/18_200.jpg} & \includegraphics[height=1.6cm]{out/18_ok.jpg} \\
|
||||
\includegraphics[height=1.6cm]{out/pjm_damaged.jpg} & \includegraphics[height=1.6cm]{out/pjm_1.jpg} & \includegraphics[height=1.6cm]{out/pjm_2.jpg} & \includegraphics[height=1.6cm]{out/pjm_4.jpg} & \includegraphics[height=1.6cm]{out/pjm_8.jpg} & \includegraphics[height=1.6cm]{out/pjm_16.jpg} & \includegraphics[height=1.6cm]{out/pjm_32.jpg} & \includegraphics[height=1.6cm]{out/pjm_64.jpg} & \includegraphics[height=1.6cm]{out/pjm_128.jpg} & \includegraphics[height=1.6cm]{out/pjm_200.jpg} & \includegraphics[height=1.6cm]{out/pjm_ok.jpg} \\
|
||||
\includegraphics[height=1.6cm]{out/t_damaged.jpg} & \includegraphics[height=1.6cm]{out/t_1.jpg} & \includegraphics[height=1.6cm]{out/t_2.jpg} & \includegraphics[height=1.6cm]{out/t_4.jpg} & \includegraphics[height=1.6cm]{out/t_8.jpg} & \includegraphics[height=1.6cm]{out/t_16.jpg} & \includegraphics[height=1.6cm]{out/t_32.jpg} & \includegraphics[height=1.6cm]{out/t_64.jpg} & \includegraphics[height=1.6cm]{out/t_128.jpg} & \includegraphics[height=1.6cm]{out/t_200.jpg} & \includegraphics[height=1.6cm]{out/t_ok.jpg} \\
|
||||
\includegraphics[height=1.6cm]{out/34_damaged.jpg} & \includegraphics[height=1.6cm]{out/34_1.jpg} & \includegraphics[height=1.6cm]{out/34_2.jpg} & \includegraphics[height=1.6cm]{out/34_4.jpg} & \includegraphics[height=1.6cm]{out/34_8.jpg} & \includegraphics[height=1.6cm]{out/34_16.jpg} & \includegraphics[height=1.6cm]{out/34_32.jpg} & \includegraphics[height=1.6cm]{out/34_64.jpg} & \includegraphics[height=1.6cm]{out/34_128.jpg} & \includegraphics[height=1.6cm]{out/34_200.jpg} & \includegraphics[height=1.6cm]{out/34_ok.jpg} \\
|
||||
\includegraphics[height=1.6cm]{out/4_damaged.jpg} & \includegraphics[height=1.6cm]{out/4_1.jpg} & \includegraphics[height=1.6cm]{out/4_2.jpg} & \includegraphics[height=1.6cm]{out/4_4.jpg} & \includegraphics[height=1.6cm]{out/4_8.jpg} & \includegraphics[height=1.6cm]{out/4_16.jpg} & \includegraphics[height=1.6cm]{out/4_32.jpg} & \includegraphics[height=1.6cm]{out/4_64.jpg} & \includegraphics[height=1.6cm]{out/4_128.jpg} & \includegraphics[height=1.6cm]{out/4_200.jpg} & \includegraphics[height=1.6cm]{out/4_ok.jpg} \\
|
46
test_plot.py
@ -1,19 +1,41 @@
|
||||
import torch
|
||||
import numpy as np
|
||||
import torch.nn as nn
|
||||
import torch.optim as optim
|
||||
from torchvision import transforms
|
||||
import torchvision.transforms.functional as F
|
||||
import utils
|
||||
from dataset import get_dataloader
|
||||
from torch.autograd import Variable
|
||||
from generator import Generator
|
||||
from gan import Generator
|
||||
from PIL import Image
|
||||
import argparse
|
||||
|
||||
G = Generator()
|
||||
G.load_state_dict(torch.load('./gen_10epoch_32f_tanh'))
|
||||
trainloader = get_dataloader()
|
||||
it = trainloader.__iter__()
|
||||
NUM_FEATURES = 16
|
||||
|
||||
G = Generator(input_width=178, input_height=218, input_dim=3, num_features=NUM_FEATURES, output_dim=3, lr=0.0002)
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(description="Shows output")
|
||||
parser.add_argument('image', help='Image to transform', type=str)
|
||||
parser.add_argument('network', help='Network to use', type=str)
|
||||
parser.add_argument('ok', help='Comparison result', nargs='?', type=str)
|
||||
parser.add_argument('-o', help='Output file', nargs='?', type=str, dest='output')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
G.load_state_dict(torch.load(args.network))
|
||||
|
||||
transform = transforms.Compose([transforms.ToTensor(), transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])
|
||||
reverse_transform = transforms.Compose([transforms.ToTensor(), transforms.ToPILImage()])
|
||||
|
||||
test_damaged = transform(Image.open(args.image).convert("RGB")).unsqueeze_(0)
|
||||
if args.ok:
|
||||
test_ok = transform(Image.open(args.ok).convert("RGB")).unsqueeze_(0)
|
||||
else:
|
||||
test_ok = test_damaged
|
||||
|
||||
for i in range(10):
|
||||
test_ok, test_damaged = it.__next__()
|
||||
generated_image = G(Variable(test_damaged))
|
||||
generated_image = generated_image.data
|
||||
utils.plot_images(test_damaged, test_ok, generated_image)
|
||||
|
||||
if args.output:
|
||||
generated_image = utils.normalize_image(generated_image)
|
||||
im = F.to_pil_image(generated_image)
|
||||
im.convert('RGB').save(args.output)
|
||||
else:
|
||||
utils.plot_images(test_damaged, test_ok, generated_image)
|
||||
|
6
utils.py
@ -31,4 +31,8 @@ def plot_images(input_image, target_image, generated_image):
|
||||
ax.imshow(img, cmap=None, aspect='equal')
|
||||
plt.subplots_adjust(wspace=0, hspace=0)
|
||||
|
||||
plt.show()
|
||||
plt.show()
|
||||
|
||||
|
||||
def normalize_image(img):
|
||||
return (((img[0] - img[0].min()) * 255) / (img[0].max() - img[0].min())).numpy().transpose(1, 2, 0).astype(np.uint8)
|
||||
|