1、C/C+ Program DesignCS205Week 14CNN for image classificationPre-tained model https:/ Convolutional layers (Conv+BN+ReLU)2 MaxPol1 Ful conected layerconv Multiple filters (kernels) can create multiple output channelshttps:/ A convolutional kernel create a channel in the output data.https:/ normalizati
2、on The BN layers have been merged into conv layersx = 0ReLU: Rectified Linear Unit i(x 0);max pooling For each channel If the input is C x H x W, the output will be C x H/2 x W/2Flatten The data blob is flatted into a 2048-length vector from 32x8x8FC: Fully-Connected Layer If the input is L and the
3、output is N (2 in the model, 4 in left figure), the size of weights is NxL (2x2048 in the model)output2x1= weight2x2048 *input2048x1+bias2x1Softmax To output the confidence vector (n=2 in the model)forCNN Explainer https:/poloclub.github.io/cnn-explainer/ExceptionsThe slides are based on the bok Rud
4、imentary Options An example: harmonic mean of two numbers Calling abort(): program example error1.cpp Send a message such as “abnormal program termination” to the standard error stream and terminate the program Return an implementation-dependent value that indicates failure to the operating system R
5、eturning an error code: program error2.cpp Return values to indicate a problem We have used it in the previous examplesThrow-Catch Mechanism An exceptional circumstance arises while a program is running Exception mechanism provide a way to transfer control from one part of a program to another Throw
6、ing an exceptionthrow keyword indicates the throwing of an exceptionA throw statement, in essence, is a jump (other jump operators?) Catching an exception with a handlercatch keyword indicates the catching of an exceptionFollowed by a typedeclaration that indicates the type of exception Using a try
7、blockA try block identifies a block of code for which particular exceptions will be activatedFollowed by one or more catch blocks See program example error3.cppThrow-Catch Mechanism Can we use more complex types? YES! Using objects as exceptions Advantage: use different exception types to distinguis
8、h among different functions and situations that produce exceptions An object can carry information with it, and you can use this information to help identify the conditions that caused the exception to be thrown A catch block could use that information to decide which course of action to pursue See
9、program example error4.cpp Geometric and harmonic meansMore Exception Features of Throw-Catch Mechanism Differences to the normal function One differenceA return statement: transfer execution to the calling functionA throw: transfer execution to the first function having a try-catch Second differenc
10、eThe compiler always creates a copy when throwing an exception The exception class Define an exception class that C+ uses as a base class One virtualmember function is named what(), and it returns a stringMore Exception Features The stdexcept exception classes The stdexcept header file defines sever
11、al more exception classes logic_error and runtime_error classeslogic_error family: domain_error, invalid_argument, length_error, out_of_boundsruntime_error family: range_error, overflow_error, underflow_errorMore Exception Features The bad_alloc exception and new Have new throw a bad_alloc exception new returned a null pointer when it couldnt allocate the memory See program example newexcp.cpp