···5656 print("ERROR: Data may not be completely saved")
575758585959-def __main__():
5959+if __name__ == "__main__":
6060 # Paths to the Waldo images
6161 waldo_path = 'waldo_data/64/waldo'
6262 n_waldo_path = 'waldo_data/64/notwaldo'
63636464 gen_data(waldo_path, n_waldo_path)
6565-6666-__main__()
+50
mini_proj/_image_classifier.py
···11+class ImageClassifier:
22+ """Class to create an ImageClassifier from a regular classifier with 5
33+ methods that are common amongst classifiers.
44+ """
55+66+ def __init__(self, clf, *args, **kwargs):
77+ self.clf = clf(*args, **kwargs)
88+99+ def fit(self, X, *args, **kwargs):
1010+ X = X.reshape((len(X), -1))
1111+ return self.clf.fit(X, *args, **kwargs)
1212+1313+ def predict(self, X, *args, **kwargs):
1414+ X = X.reshape((len(X), -1))
1515+ return self.clf.predict(X, *args, **kwargs)
1616+1717+ def score(self, X, *args, **kwargs):
1818+ X = X.reshape((len(X), -1))
1919+ return self.clf.score(X, *args, **kwargs)
2020+2121+ def get_params(self, *args, **kwargs):
2222+ return self.clf.get_params(*args, **kwargs)
2323+2424+ def set_params(self, **params):
2525+ return self.set_params(**params)
2626+2727+if __name__ == '__main__':
2828+2929+ # Import datasets, classifiers and performance metrics
3030+ from sklearn import datasets, svm, metrics
3131+3232+ # The digits dataset
3333+ digits = datasets.load_digits()
3434+3535+ n_samples = len(digits.images)
3636+ data = digits.images
3737+3838+ # Create a classifier: a support vector classifier
3939+ classifier = ImageClassifier(svm.SVC, gamma=0.001)
4040+4141+ # We learn the digits on the first half of the digits
4242+ classifier.fit(data[:n_samples // 2], digits.target[:n_samples // 2])
4343+4444+ # Now predict the value of the digit on the second half:
4545+ expected = digits.target[n_samples // 2:]
4646+ predicted = classifier.predict(data[n_samples // 2:])
4747+4848+ print("Classification report for classifier %s:\n%s\n"
4949+ % (classifier, metrics.classification_report(expected, predicted)))
5050+ print("Confusion matrix:\n%s" % metrics.confusion_matrix(expected, predicted))
+8-3
mini_proj/waldo_model.py
···88from keras.layers import Dense, Dropout, Activation, Flatten, Input
99from keras.layers import Conv2D, MaxPooling2D, ZeroPadding2D
1010from keras.models import Model
1111-from keras.layers.normalization import BatchNormalization
1212-from keras.utils import np_utils
1111+1212+from sklearn import svm, tree, naive_bayes, ensemble
1313+from _image_classifier import ImageClassifier
1414+1315from keras.optimizers import Adadelta
1416from keras.callbacks import ModelCheckpoint
1515-1617from keras import backend as K
1718K.set_image_dim_ordering('th')
1819np.random.seed(7)
···58595960## Define model
6061model = FCN()
6262+svm_iclf = ImageClassifier(svm.SVC)
6363+tree_iclf = ImageClassifier(tree.DecisionTreeClassifier)
6464+naive_bayes_iclf = ImageClassifier(naive_bayes.GaussianNBd)
6565+ensemble_iclf = ImageClassifier(ensemble.RandomForestClassifier)
61666267## Define training parameters
6368epochs = 20 # an epoch is one forward pass and back propogation of all training data
+3-5
wk11/week11.tex
···4747\text{otherwise }f(\_,\_,\_) & = & 0
4848\end{eqnarray*}
49495050-\begin{figure}[H]
5151- \includegraphics[scale=0.55]{plots}
5050+\begin{figure}[ht]
5151+ \includegraphics[scale=0.6]{plots}
5252 \centering
5353- \captionsetup{width=0.80\textwidth}
5453 \caption{Plots of the execution of the cellular automata with the different
5554 updating methods. From top-left to top-right: Synchronous, Random
5655 Independent, Random Order. From bottom-left to bottom-right: Clocked,
···131130the graphs showing the energy released from the system over time to
132131gauge how where the runaway reaction occurs.
133132134134-\begin{figure}[H]
133133+\begin{figure}[ht]
135134 \includegraphics[scale=0.70]{plots2}
136135 \centering
137137- \captionsetup{width=0.80\textwidth}
138136 \caption{Plots of energy released over time. Each plot corresponds a
139137 different density: 0\%, 5\%, 8\%, 10\%, 11\%, 12\%, 13\%, 15\%, 17\% and 20\%}
140138 \label{fig:plot2}