···11+@misc{openData,
22+ title={Open Database License (ODbL) v1.0},
33+ url={https://opendatacommons.org/licenses/odbl/1.0/},
44+ journal={Open Data Commons},
55+ year={2018},
66+ month={Feb}
77+}
88+@techreport{knn,
99+ title={Discriminatory analysis-nonparametric discrimination: consistency properties},
1010+ author={Fix, Evelyn and Hodges Jr, Joseph L},
1111+ year={1951},
1212+ institution={California Univ Berkeley}
1313+}
1414+@article{svm,
1515+ title={Support-vector networks},
1616+ author={Cortes, Corinna and Vapnik, Vladimir},
1717+ journal={Machine learning},
1818+ volume={20},
1919+ number={3},
2020+ pages={273--297},
2121+ year={1995},
2222+ publisher={Springer}
2323+}
2424+@article{naivebayes,
2525+ title={Idiot's Bayes—not so stupid after all?},
2626+ author={Hand, David J and Yu, Keming},
2727+ journal={International statistical review},
2828+ volume={69},
2929+ number={3},
3030+ pages={385--398},
3131+ year={2001},
3232+ publisher={Wiley Online Library}
3333+}
3434+@article{randomforest,
3535+ title={Classification and regression by randomForest},
3636+ author={Liaw, Andy and Wiener, Matthew and others},
3737+ journal={R news},
3838+ volume={2},
3939+ number={3},
4040+ pages={18--22},
4141+ year={2002}
4242+}
143@article{Kotsiantis2007,
244abstract = {Supervised machine learning is the search for algorithms that reason from externally supplied instances to produce general hypotheses, which then make predictions about future instances. In other words, the goal of supervised learning is to build a concise model of the distribution of class labels in terms of predictor features. The resulting classifier is then used to assign class labels to the testing instances where the values of the predictor features are known, but the value of the class label is unknown. This paper describes various supervised machine learning classification techniques. Of course, a single article cannot be a complete review of all supervised machine learning classification algorithms (also known induction classification algorithms), yet we hope that the references cited will cover the major theoretical issues, guiding the researcher in interesting research directions and suggesting possible bias combinations that have yet to be explored.},
345author = {Kotsiantis, Sotiris B.},
···1456volume = {31},
1557year = {2007}
1658}
1717-
mini_proj/report/waldo.png
This is a binary file and will not be displayed.
+194-53
mini_proj/report/waldo.tex
···66 \usepackage[justification=centering]{caption} % Used for captions
77 \captionsetup[figure]{font=small} % Makes captions small
88 \newcommand\tab[1][0.5cm]{\hspace*{#1}} % Defines a new command to use 'tab' in text
99- % Math package
1010- \usepackage{amsmath}
99+ \usepackage[comma, numbers]{natbib} % Used for the bibliography
1010+ \usepackage{amsmath} % Math package
1111 % Enable that parameters of \cref{}, \ref{}, \cite{}, ... are linked so that a reader can click on the number an jump to the target in the document
1212 \usepackage{hyperref}
1313 %enable \cref{...} and \Cref{...} instead of \ref: Type of reference included in the link
···1919 \usepackage{bookmark}
2020 \usepackage{natbib}
21212222+ \usepackage{xcolor}
2323+ \newcommand{\todo}[1]{\marginpar{{\textsf{TODO}}}{\textbf{\color{red}[#1]}}}
2424+2225 \begin{document}
2323- \title{Waldo discovery using Neural Networks}
2626+ \title{What is Waldo?}
2427 \author{Kelvin Davis \and Jip J. Dekker\and Anthony Silvestere}
2528 \maketitle
2629···30333134 \section{Introduction}
32353333- \section{Background}
3636+ Almost every child around the world knows about ``Where's Waldo?'', also
3737+ known as ``Where's Wally?'' in some countries. This famous puzzle book has
3838+ spread its way across the world and is published in more than 25 different
3939+ languages. The idea behind the books is to find the character ``Waldo'',
4040+ shown in \Cref{fig:waldo}, in the different pictures in the book. This is,
4141+ however, not as easy as it sounds. Every picture in the book is full of tiny
4242+ details and Waldo is only one out of many. The puzzle is made even harder by
4343+ the fact that Waldo is not always fully depicted, sometimes it is just his
4444+ head or his torso popping out from behind something else. Lastly, the reason
4545+ that even adults will have trouble spotting Waldo is the fact that the
4646+ pictures are full of ``Red Herrings'': things that look like (or are colored
4747+ as) Waldo, but are not actually Waldo.
34483535- This paper is mad \cite{Kotsiantis2007}.
4949+ \begin{figure}[ht]
5050+ \includegraphics[scale=0.35]{waldo}
5151+ \centering
5252+ \caption{
5353+ A headshot of the character ``Waldo'', or ``Wally''. Pictures of Waldo
5454+ copyrighted by Martin Handford and are used under the fair-use policy.
5555+ }
5656+ \label{fig:waldo}
5757+ \end{figure}
36583737- \section{Methods}
5959+ The task of finding Waldo is something that relates to a lot of real life
6060+ image recognition tasks. Fields like mining, astronomy, surveillance,
6161+ radiology, and microbiology often have to analyse images (or scans) to find
6262+ the tiniest details, sometimes undetectable by the human eye. These tasks
6363+ are especially hard when the thing(s) you are looking for are similar to the
6464+ rest of the images. These tasks are thus generally performed using computers
6565+ to identify possible matches.
6666+6767+ ``Where's Waldo?'' offers us a great tool to study this kind of problem in a
6868+ setting that is humanly tangible. In this report we will try to identify
6969+ Waldo in the puzzle images using different classification methods. Every
7070+ image will be split into different segments and every segment will have to
7171+ be classified as either being ``Waldo'' or ``not Waldo''. We will compare
7272+ various different classification methods from more classical machine
7373+ learning, like naive Bayes classifiers, to the currently state of the art,
7474+ Neural Networks. In \Cref{sec:background} we will introduce the different
7575+ classification methods, \Cref{sec:method} will explain the way in which
7676+ these methods are trained and how they will be evaluated, in
7777+ \Cref{sec:results} will discuss the results, and \Cref{sec:conclusion} will
7878+ offer our final conclusions.
7979+8080+ \section{Background} \label{sec:background}
8181+8282+ The classification methods used can separated into two separate groups:
8383+ classical machine learning methods and neural network architectures. Many of
8484+ the classical machine learning algorithms have variations and improvements
8585+ for various purposes; however, for this report we will be using their only
8686+ their basic versions. In contrast, we will use different neural network
8787+ architectures, as this method is currently the most used for image
8888+ classification.
8989+9090+ \textbf{
9191+ \\A couple of papers that may be useful (if needed):
9292+ - LeNet: http://yann.lecun.com/exdb/publis/pdf/lecun-01a.pdf
9393+ - AlexNet: http://papers.nips.cc/paper/4824-imagenet-classification-with-deep-convolutional-neural-networks
9494+ - General comparison of LeNet and AlexNet:
9595+ "On the Performance of GoogLeNet and AlexNet Applied to Sketches", Pedro Ballester and Ricardo Matsumura Araujo
9696+ - Deep NN Architecture:
9797+ https://www-sciencedirect-com.ezproxy.lib.monash.edu.au/science/article/pii/S0925231216315533
9898+ }
9999+100100+ \subsection{Classical Machine Learning Methods}
101101+102102+ The following paragraphs will give only brief descriptions of the different
103103+ classical machine learning methods used in this reports. For further reading
104104+ we recommend reading ``Supervised machine learning: A review of
105105+ classification techniques'' \cite{Kotsiantis2007}.
106106+107107+ \paragraph{Naive Bayes Classifier}
108108+109109+ \cite{naivebayes}
110110+111111+ \paragraph{$k$-Nearest Neighbors}
112112+113113+ ($k$-NN) \cite{knn} is one of the simplest machine learning algorithms. It
114114+ classifies a new instance based on its ``distance'' to the known instances.
115115+ It will find the $k$ closest instances to the new instance and assign the
116116+ new instance the class that the majority of the $k$ closest instances has.
117117+ The method has to be configured in several ways: the number of $k$, the
118118+ distance measure, and (depending on $k$) a tie breaking measure all have to
119119+ be chosen.
120120+121121+ \paragraph{Support Vector Machine}
122122+123123+ \cite{svm}
124124+125125+ \paragraph{Random Forest}
126126+127127+ \cite{randomforest}
128128+129129+ \subsection{Neural Network Architectures}
130130+ \todo{Did we only do the three in the end? (Alexnet?)}
131131+ Yeah, we implemented the LeNet architecture, then improved on it for a fairly standar convolutional neural network (CNN) that was deeper, extracted more features, and condensed that image information more. Then we implemented a more fully convolutional network (FCN) which contained only one dense layer for the final binary classification step. The FCN added an extra convolutional layer, meaning the before classifying each image, the network abstracted the data more than the other two.
132132+ \begin{itemize}
133133+ \item LeNet
134134+ \item CNN
135135+ \item FCN
136136+ \end{itemize}
137137+138138+ \paragraph{Convolutional Neural Networks}
139139+140140+ \paragraph{LeNet}
141141+142142+ \paragraph{Fully Convolutional Neural Networks}
143143+144144+145145+ \section{Method} \label{sec:method}
146146+ \tab
147147+ In order to effectively utilize the aforementioned modelling and classification techniques, a key consideration is the data they are acting on.
148148+ A dataset containing Waldo and non-Waldo images was obtained from an Open Database\footnote{``The Open Database License (ODbL) is a license agreement intended to allow users to freely share, modify, and use [a] Database while maintaining [the] same freedom for others"\cite{openData}}hosted on the predictive modelling and analytics competition framework, Kaggle.
149149+ The distinction between images containing Waldo, and those that do not, was providied by the separation of the images in different sub-directories.
150150+ It was therefore necessary to preprocess these images before they could be utilised by the proposed machine learning algorithms.
151151+152152+ \subsection{Image Processing}
153153+ \tab
154154+ The Waldo image database consists of images of size 64$\times$64, 128$\times$128, and 256$\times$256 pixels obtained by dividing complete Where's Waldo? puzzles.
155155+ Within each set of images, those containing Waldo are located in a folder called `waldo', and those not containing Waldo, in a folder called `not\_waldo'.
156156+ Since Where's Waldo? puzzles are usually densely populated and contain fine details, the 64$\times$64 pixel set of images were selected to train and evaluate the machine learning models.
157157+ These images provide the added benefit of containing the most individual images of the three size groups.
158158+ \\
159159+ \par
160160+ Each of the 64$\times$64 pixel images were inserted into a Numpy
161161+ \footnote{Numpy is a popular Python programming library for scientific computing}
162162+ array of images, and a binary value was inserted into a seperate list at the same index.
163163+ These binary values form the labels for each image (waldo or not waldo).
164164+ Colour normalisation was performed on each so that artefacts in an image's colour profile correspond to meaningful features of the image (rather than photographic method).
165165+ \\
166166+ \par
167167+ Each original puzzle is broken down into many images, and only contains one Waldo. Although Waldo might span multiple 64$\times$64 pixel squares, this means that the non-Waldo data far outnumbers the Waldo data.
168168+ To combat the bias introduced by the skewed data, all Waldo images were artificially augmented by performing random rotations, reflections, and introducing random noise in the image to produce news images.
169169+ In this way, each original Waldo image was used to produce an additional 10 variations of the image, inserted into the image array.
170170+ This provided more variation in the true positives of the data set and assists in the development of more robust methods by exposing each technique to variations of the image during the training phase.
171171+ \\
172172+ \par
173173+ Despite the additional data, there were still over ten times as many non-Waldo images than Waldo images.
174174+ Therefore, it was necessary to cull the no-Waldo data, so that there was an even split of Waldo and non-Waldo images, improving the representation of true positives in the image data set.
175175+ \\
381763939- % Kelvin Start
4040- \subsection{Benchmarking}\label{benchmarking}
177177+ % Kelvin Start
178178+ \subsection{Benchmarking}\label{benchmarking}
411794242- In order to benchmark the Neural Networks, the performance of these
4343- algorithms are evaluated against other Machine Learning algorithms. We
4444- use Support Vector Machines, K-Nearest Neighbours (\(K=5\)), Gaussian
4545- Naive Bayes and Random Forest classifiers, as provided in Scikit-Learn.
180180+ In order to benchmark the Neural Networks, the performance of these
181181+ algorithms are evaluated against other Machine Learning algorithms. We
182182+ use Support Vector Machines, K-Nearest Neighbours (\(K=5\)), Gaussian
183183+ Naive Bayes and Random Forest classifiers, as provided in Scikit-Learn.
461844747- \subsection{Performance Metrics}\label{performance-metrics}
185185+ \subsection{Performance Metrics}\label{performance-metrics}
481864949- To evaluate the performance of the models, we record the time taken by
5050- each model to train, based on the training data and statistics about the
5151- predictions the models make on the test data. These prediction
5252- statistics include:
187187+ To evaluate the performance of the models, we record the time taken by
188188+ each model to train, based on the training data and statistics about the
189189+ predictions the models make on the test data. These prediction
190190+ statistics include:
531915454- \begin{itemize}
5555- \tightlist
5656- \item
5757- \textbf{Accuracy:}
5858- \[a = \dfrac{|correct\ predictions|}{|predictions|} = \dfrac{tp + tn}{tp + tn + fp + fn}\]
5959- \item
6060- \textbf{Precision:}
6161- \[p = \dfrac{|Waldo\ predicted\ as\ Waldo|}{|predicted\ as\ Waldo|} = \dfrac{tp}{tp + fp}\]
6262- \item
6363- \textbf{Recall:}
6464- \[r = \dfrac{|Waldo\ predicted\ as\ Waldo|}{|actually\ Waldo|} = \dfrac{tp}{tp + fn}\]
6565- \item
6666- \textbf{F1 Measure:} \[f1 = \dfrac{2pr}{p + r}\] where \(tp\) is the
6767- number of true positives, \(tn\) is the number of true negatives,
6868- \(fp\) is the number of false positives, and \(tp\) is the number of
6969- false negatives.
7070- \end{itemize}
192192+ \begin{itemize}
193193+ \item
194194+ \textbf{Accuracy:}
195195+ \[a = \dfrac{|correct\ predictions|}{|predictions|} = \dfrac{tp + tn}{tp + tn + fp + fn}\]
196196+ \item
197197+ \textbf{Precision:}
198198+ \[p = \dfrac{|Waldo\ predicted\ as\ Waldo|}{|predicted\ as\ Waldo|} = \dfrac{tp}{tp + fp}\]
199199+ \item
200200+ \textbf{Recall:}
201201+ \[r = \dfrac{|Waldo\ predicted\ as\ Waldo|}{|actually\ Waldo|} = \dfrac{tp}{tp + fn}\]
202202+ \item
203203+ \textbf{F1 Measure:} \[f1 = \dfrac{2pr}{p + r}\] where \(tp\) is the
204204+ number of true positives, \(tn\) is the number of true negatives,
205205+ \(fp\) is the number of false positives, and \(tp\) is the number of
206206+ false negatives.
207207+ \end{itemize}
712087272- Accuracy is a common performance metric used in Machine Learning,
7373- however in classification problems where the training data is heavily
7474- biased toward one category, sometimes a model will learn to optimize its
7575- accuracy by classifying all instances as one category. I.e. the
7676- classifier will classify all images that do not contain Waldo as not
7777- containing Waldo, but will also classify all images containing Waldo as
7878- not containing Waldo. Thus we use, other metrics to measure performance
7979- as well.
209209+ Accuracy is a common performance metric used in Machine Learning,
210210+ however in classification problems where the training data is heavily
211211+ biased toward one category, sometimes a model will learn to optimize its
212212+ accuracy by classifying all instances as one category. I.e. the
213213+ classifier will classify all images that do not contain Waldo as not
214214+ containing Waldo, but will also classify all images containing Waldo as
215215+ not containing Waldo. Thus we use, other metrics to measure performance
216216+ as well.
802178181- \emph{Precision} returns the percentage of classifications of Waldo that
8282- are actually Waldo. \emph{Recall} returns the percentage of Waldos that
8383- were actually predicted as Waldo. In the case of a classifier that
8484- classifies all things as Waldo, the recall would be 0. \emph{F1-Measure}
8585- returns a combination of precision and recall that heavily penalises
8686- classifiers that perform poorly in either precision or recall.
8787- % Kelvin End
218218+ \emph{Precision} returns the percentage of classifications of Waldo that
219219+ are actually Waldo. \emph{Recall} returns the percentage of Waldos that
220220+ were actually predicted as Waldo. In the case of a classifier that
221221+ classifies all things as Waldo, the recall would be 0. \emph{F1-Measure}
222222+ returns a combination of precision and recall that heavily penalises
223223+ classifiers that perform poorly in either precision or recall.
224224+ % Kelvin End
882258989- \section{Results}
226226+ \section{Results} \label{sec:results}
902279191- \section{Discussion and Conclusion}
228228+ \section{Conclusion} \label{sec:conclusion}
922299393- \bibliographystyle{humannat}
230230+ \clearpage % Ensures that the references are on a seperate page
231231+ \pagebreak
232232+ % References
233233+ \section{References}
234234+ \renewcommand{\refname}{}
235235+ \bibliographystyle{alpha}
94236 \bibliography{references}
9595-96237 \end{document}
+73-4
mini_proj/waldo_model.py
···2525'''
2626Model definition define the network structure
2727'''
2828-def FCN():
2828+def CNN():
2929 ## List of model layers
3030 inputs = Input((3, 64, 64))
3131···3333 m_pool1 = MaxPooling2D(pool_size=(2, 2))(conv1)
34343535 conv2 = Conv2D(32, (3, 3), activation='relu', padding='same')(m_pool1)
3636- #drop1 = Dropout(0.2)(conv2) # Drop some portion of features to prevent overfitting
3736 m_pool2 = MaxPooling2D(pool_size=(2, 2))(conv2)
38373938 conv3 = Conv2D(32, (3, 3), activation='relu', padding='same')(m_pool2)
···4746 drop3 = Dropout(0.2)(dense)
4847 classif = Dense(2, activation='sigmoid')(drop3) # Final layer to classify
49485050- ## Define the model structure
4949+ ## Define the model start and end
5050+ model = Model(inputs=inputs, outputs=classif)
5151+ # Optimizer recommended Adadelta values (lr=0.01)
5252+ model.compile(optimizer=Adam(), loss='binary_crossentropy', metrics=['accuracy', f1])
5353+5454+ return model
5555+5656+'''
5757+Model definition for a fully convolutional (no dense layers) network structure
5858+'''
5959+def FCN():
6060+ ## List of model layers
6161+ inputs = Input((3, 64, 64))
6262+6363+ conv1 = Conv2D(16, (3, 3), activation='relu', padding='same', input_shape=(64, 64, 3))(inputs)
6464+ m_pool1 = MaxPooling2D(pool_size=(2, 2))(conv1)
6565+6666+ conv2 = Conv2D(32, (3, 3), activation='relu', padding='same')(m_pool1)
6767+ m_pool2 = MaxPooling2D(pool_size=(2, 2))(conv2)
6868+6969+ conv3 = Conv2D(32, (3, 3), activation='relu', padding='same')(m_pool2)
7070+ drop2 = Dropout(0.2)(conv3) # Drop some portion of features to prevent overfitting
7171+ m_pool2 = MaxPooling2D(pool_size=(2, 2))(drop2)
7272+7373+ conv4 = Conv2D(64, (2, 2), activation='relu', padding='same')(m_pool2)
7474+7575+ flat = Flatten()(conv4) # Makes data 1D
7676+ drop3 = Dropout(0.2)(flat)
7777+ classif = Dense(2, activation='sigmoid')(drop3) # Final layer to classify
7878+7979+ ## Define the model start and end
5180 model = Model(inputs=inputs, outputs=classif)
5281 # Optimizer recommended Adadelta values (lr=0.01)
5382 model.compile(optimizer=Adam(), loss='binary_crossentropy', metrics=['accuracy', f1])
54835584 return model
56858686+8787+'''
8888+Model definition for the network structure of LeNet
8989+Note: LeNet was designed to classify into 10 classes, but we are only performing binary classification
9090+'''
9191+def LeNet():
9292+ ## List of model layers
9393+ inputs = Input((3, 64, 64))
9494+9595+ conv1 = Conv2D(6, (5, 5), activation='relu', padding='valid', input_shape=(64, 64, 3))(inputs)
9696+ m_pool1 = MaxPooling2D(pool_size=(2, 2))(conv1)
9797+9898+ conv2 = Conv2D(16, (5, 5), activation='relu', padding='valid')(m_pool1)
9999+ m_pool2 = MaxPooling2D(pool_size=(2, 2))(conv2)
100100+101101+ flat = Flatten()(m_pool2) # Makes data 1D
102102+103103+ dense1 = Dense(120, activation='relu')(flat) # Fully connected layer
104104+ dense2 = Dense(84, activation='relu')(dense1) # Fully connected layer
105105+ drop3 = Dropout(0.2)(dense2)
106106+ classif = Dense(2, activation='sigmoid')(drop3) # Final layer to classify
107107+108108+ ## Define the model start and end
109109+ model = Model(inputs=inputs, outputs=classif)
110110+ model.compile(optimizer=Adam(), loss='binary_crossentropy', metrics=['accuracy', f1])
111111+112112+ return model
113113+114114+'''
115115+AlexNet architecture
116116+'''
117117+def AlexNet():
118118+ inputs = Input(shape=(3, 64, 64))
119119+120120+121121+ return model
122122+123123+57124def f1(y_true, y_pred):
58125 def recall(y_true, y_pred):
59126 """Recall metric.
···110177lbl_test = to_categorical(lbl_test)
111178112179## Define model
180180+#model = CNN()
113181model = FCN()
182182+#model = LeNet()
114183# svm_iclf = ImageClassifier(svm.SVC)
115184# tree_iclf = ImageClassifier(tree.DecisionTreeClassifier)
116185# naive_bayes_iclf = ImageClassifier(naive_bayes.GaussianNBd)
117186# ensemble_iclf = ImageClassifier(ensemble.RandomForestClassifier)
118187119188## Define training parameters
120120-epochs = 10 # an epoch is one forward pass and back propogation of all training data
189189+epochs = 25 # an epoch is one forward pass and back propogation of all training data
121190batch_size = 150 # batch size - number of training example used in one forward/backward pass
122191# (higher batch size uses more memory, smaller batch size takes more time)
123192#lrate = 0.01 # Learning rate of the model - controls magnitude of weight changes in training the NN