# Python定制 | CSE 252A Computer Vision Assignment4

Assignment4
November 29, 2017
1 CSE 252A Computer Vision I Fall 2017
1.1 Assignment 4
1.2 Problem 1: Install Tensorflow [2 pts]
Note: You will not need GPU support for this assignment so don’t worry if you don’t have one.
Furthermore, installing with GPU support is often more difficult to configure so it is suggested
that you install the CPU only version. However, if you have a GPU and would like to install GPU
support feel free to do so at your own risk 🙂
Note: On windows, Tensorflow is only supported in python3, so you will need to install
python3 for this assignment.
Run the following cell to verify your instalation.
In [ ]: import tensorflow as tf
hello = tf.constant(‘Hello, TensorFlow!’)
sess = tf.Session()
print(sess.run(hello))
python version: http://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz
Extract the data to ./data Once extracted run the following cell to view a few example images.
In : import numpy as np
# unpickles raw data files
def unpickle(file):
import pickle
import sys
with open(file, ‘rb’) as fo:
hidden -> hidden
hidden -> classes
The first two linear layers should be followed with a ReLU nonlinearity. The final layer should
not have a nonlinearity applied as we desire the raw logits output (see: the documentation for
tf.nn.sparse_softmax_cross_entropy_with_logits used in the training)
The final output of the computation graph should be stored in self.y as that will be used in the
training.
Hint: see the example linear classifier
Note: you should get around 50% accuracy
In [ ]: class MLPClassifer(TFClassifier):
def __init__(self, classes=10, hidden=100):
self.sess = tf.Session()
self.x = tf.placeholder(tf.float32, shape=[None,32,32,3]) # input batch of images
self.y_ = tf.placeholder(tf.int64, shape=[None]) # input labels
7
# test your MLP classifier (note you should get around 50% accuracy)
mlpClassifer = MLPClassifer()
mlpClassifer.train(trainData, trainLabels, epochs=20)
# display confusion matrix
M = confusion(testData, testLabels, mlpClassifer)
VisualizeConfussion(M)
1.9 Problem 7: Convolutional Neural Netork (CNN) [7 pts]
Here you will implement a CNN with the following architecture:
ReLU( Conv(kernel_size=4×4 stride=2, output_features=n) )
ReLU( Conv(kernel_size=4×4 stride=2, output_features=n*2) )
ReLU( Conv(kernel_size=4×4 stride=2, output_features=n*4) )
Linear(output_features=classes)
In [ ]: def conv2d(x, W, stride=2):
return tf.nn.conv2d(x, W, strides=[1, stride, stride, 1], padding=’SAME’)
class CNNClassifer(TFClassifier):
def __init__(self, classes=10, n=16):
self.sess = tf.Session()
self.x = tf.placeholder(tf.float32, shape=[None,32,32,3]) # input batch of images
self.y_ = tf.placeholder(tf.int64, shape=[None]) # input labels
# test your CNN classifier (note you should get around 65% accuracy)
cnnClassifer = CNNClassifer()
cnnClassifer.train(trainData, trainLabels, epochs=20)
# display confusion matrix
M = confusion(testData, testLabels, cnnClassifer)
VisualizeConfussion(M)
1.10 Further reference
To see how state of the art deep networks do on this dataset see:
https://github.com/tensorflow/models/tree/master/research/resnet
8 E-mail: vipdue@outlook.com  微信号:vipnxx 