Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Template code below: ###add lines to import modules as needed ## def build _ model 1 ( ) : model = None # Add code

Template code below:
###add lines to import modules as needed
##
def build_model1():
model = None # Add code to define model 1.
return model
def build_model2():
model = None#add code to define model 1
return model
def build_model3():
model = None #add code to define model 1
##this one should use the functional API so you can create the residual connections
return model
def build_model150k():
model = None # add code to define model 1
return model
#nio training or dataset construction should happen over this line
if ___name =='__main__':
##########
##add code here to load the CIFAR10 data set
######
## build and train model 1
model1= build_model1()
#compaile and train model 1
##build, compile and train model 2(DS convolutions)
model2= build_model2()
### repeate for model 3 and your best sub-50l params model
We're going to examine a convolutional neural network (CNN) used for classifying images in
the CIFAR-10 dataset.
A. Each input image is 3232 pixels with red/green/blue channels for a total size of
32323.
B. The layers are as follows:
Conv 2D: 32 filters, 33 kernel, stride=2(in both x,y dimensions), "same" padding
BatchNorm
Conv 2D: 64 filters, 33 kernel, stride=2(in both x,y dimensions), "same" padding
BatchNorm
Conv 2D: 128 filters, 33 kernel, stride=2(in both x,y dimensions), "same" padding
BatchNorm
Four more pairs of Conv2D+Batchnorm, just like the last, except with no striding
option (so stride defaults to 1).
Conv 2D: 128 filters, 33 kernel, (in both x,y dimensions), "same" padding
BatchNorm
MaxPooling, 44 pooling size, 44 stride
Flatten
Dense (aka Fully Connected),128 units.
BatchNorm
Dense (aka Fully Connected),10 units
Use a spreadsheet or a script to calculate for each layer the number of parameters, the
number of multiply-accumulate operations, and the output size. Turn in a pdf showing a
table of parameter and mac counts per layer, as well as the spreadsheet or script you used
to calculate it.
The next steps will be turned in on GitHub. Copy the file hw2_template.py to
hw2_complete.py for your work.
The automatic grading scripts will assume you used the filename hw2_complete.py, so
please follow this instruction precisely.
Create a function named build_model1()(above the "if ") line, which implements
the above model in Keras. Use your function to build the model and, name it 'model1'. Use
the summary() method to check your parameter count and output size calculations. (Make
sure to 'compile' it).
Load the CIFAR-10 set and split the training set into a training and validation subset.
Your training, test, and validation sets should be in variables named, respectively:
(train_images, train_labels),(test_images, test_labels),(val_images, val_labels)
Train for 50 epochs. What is the training, validation, and test accuracy at the end of
training?
INCLUDE Did you observe any overfitting? Should the model train for longer, shorter, or
about that number of epochs.
Take or find a picture of something that is one of the output classes
('airplane,"automobile,"bird,"cat,'deer,"dog,'frog,"horse,"ship,"truck'). Save it as a png or jpg,
crop and/or rescale it to 3232 pixels, and run your classifier on it. Name the
cropped/scaled image "test_image_classname.ext" where classname is one of the output
classes listed and 'ext' is the appropriate filename extension (jpg or png).
INCLUDE Does it correctly label the picture?
Repeat steps 2,3,4,5 with a model where all convolutional layers except for the first one are
replaced with depthwise-separable convolutions. Name this model 'model2', and build it
with a function called "build_model2()"
For example, a layer
Conv 2D: 64 filters, 33 kernel, stride=2(in both x,y dimensions), "same" padding
Would become either
SeparableConv 2D: 64 filters, 33 kernel, stride=2(in both x,y dimensions),
"same" padding
. OR
Depthwise Conv 2D: 33 kernel, stride=2(in both x,y dimensions), "same"
padding, use_bias=False
Disable the bias here, because applying a bias to both sub-layers is redundant
Conv2D: 64 filters (edit),11 kernel, stride=1
Note: Striding by 2 twice would effectively stride by 4
Note: padding does not matter for a 11 kernel.
Only the 11 convolutionn would include the activation (eg "relu")
INCLUDE For this model, did you observe any overfitting? Should the model train for longer,
shorter, or about that number of epochs.
Create a function that builds a 3rd model, with the same structure as the first model
(standard convolutions rather than separable convolution) but add dropout layers after the
convolutions and residual connections (aka skip connections) around every two
convolutional blocks (a "block" here refers to a convolution layer, batchnorm, and dropout).
Start the skip connections after the first convolution layer, because there is no benefit to
delivering gradients all the way back to the inputs. The building function should be called
build_model3() and the model should be named model3. Also note that here you will need
to use the functional API B, rather than the Sequential
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 1 Lnai 9284

Authors: Annalisa Appice ,Pedro Pereira Rodrigues ,Vitor Santos Costa ,Carlos Soares ,Joao Gama ,Alipio Jorge

1st Edition

3319235273, 978-3319235271

More Books

Students also viewed these Databases questions