Use Pre-Trained CNN for State Farm Kaggle Competition

username: shahin0099
cooked: <p><strong>Use pre-trained CNN for the State Farm Kaggle competition</strong><br>
A workbook with fast.ai lessons 3-4<br>
if you want to read about <a href="https://vidmateapkdownloadinstall.com/vidmate-downloader-hd-live-tv/" rel="nofollow noopener">free video downloader like vidmate apk click here</a><br>
With a small train data size and sufficient training time, you can always adjust the train data to 100% accuracy.</p>
<p>Apply the VGG16 model with finetune default of fast.ai on distracted pilot detection competition data from Kaggle State Farm, we use the following parameters:</p>
<p>batch_size = 60<br>
epochs = 200<br>
train data size = 100 images belonging to 10 classes<br>
size of validation data = 50 images belonging to 10 classes<br>
Weight decrease = 0.0<br>
Learning rate = 0.001<br>
Optimizer = Adam<br>
Decrease in learning rate = 0.0<br>
Abandonment = 0.5 on two fully connected layers (4096 neurons, activation = ReLu)<br>
No batch standardization<br>
Around the 180 epochs, you can see the line accuracy = 1 go through a red dot, which means reaching an exact accuracy of 100% for training data.</p>
<p>However, it is clear that we have an overcapacity, the validation accuracy is only 0.5.</p>
<p>To estimate the cost in time with training in a complete data set and a VGG16 model (except that the last layer is replaced and that only the dense layers are trainable), I apply the following parameters:</p>
<p>batch_size = 60<br>
train data size = 17943 images belonging to 10 classes (take 20% of the original train data as validation)<br>
size of validation data = 4481 images belonging to 10 classes<br>
Weight decrease = 0.0<br>
Learning rate = 0.001<br>
Optimizer = Adam<br>
Decrease in learning rate = 0.0<br>
Abandonment = 0.5 on two fully connected layers (4096 neurons, activation = ReLu)<br>
No batch standardization<br>
It takes about 10 minutes to train the neural network at a time!</p>
<p>So if I have to check 10 learning rates, 10 weight decreases, 3 dropout rates, 3 momentum (or decreasing learning rate), 3 lot sizes, 2 optimizers, it will take about (assuming that 'no grid search here) (10 + 10 + 3 + 3 + 3 + 2) * 10 = 310 minutes ~ 5 hours for a single period.</p>
<p>As a general rule, we would like to run each parameter longer, for example 10 epochs, which means 50 hours of training! And 10 eras are probably not long enough!</p>
<p>It’s too long for me to find the optimal settings. I need to use less data in less time to find a meaningful approximation of the parameters.</p>
<p>In addition, there are 79,726 images under test, it takes about 30 minutes to generate predictions for them.</p>
<p>Anyway, here is the graph of the accuracy compared to the times for this race. We can say that the validation precision is better than the train precision, this could indicate an under-adjustment because we applied the stall.</p>
<p>By submitting this model to Kaggle, I got a score of 1.55869, ranking around 675 in Kaggle’s private ranking.</p>
<p>While there are a few ideas we can try to improve the validation error (for example, reduce regularization), it’s best to follow a systematic process to tackle the problem.</p>
<p>Since we are only forming dense layers here, we should probably remove the convolutional layers to speed up the formation.</p>
<p>To save time in training and fine-tuning the hyper-parameters, I tried to use the pre-formed VGG16 model here.</p>
<p>First, load the original VGG16 model<br>
Then delete all the layers after the last flattened part of the convolutional layer, i.e. after this layer<br>
_________________________________________________________________flatten_2 (Flatten) (None, 25088) 0 ================================================= == ==========================<br>
I then made predictions on train data, validation data and test data with the scale model. The resulting characteristics (shape: 25088x1 for each entry) are the entries of my new model (see below) on the photos of State Farm.<br>
I then created a minimal network fully connected with 1 hidden dense layer (which has only one neuron) and with softmax as the output layer.<br>
from keras.models import Sequentialfrom keras.layers.core import Flatten, Dense, Dropout, Lambdafrom keras.layers import BatchNormalizationfrom keras.optimizers import SGD, RMSprop, Adamlr = 0.001statefarm_model = Sequential () statefarm_model.add ‘relu’, input_shape = (25088,))) statefarm_model.add (Dense (10, activation = ‘softmax’)) statefarm_model.compile (optimizer = Adam (lr = lr), loss = ‘categorical_crossentropy’, metrics = [’ precision ']) statefarm_model.summary () _________________________________________________________________ Layer (type) Param</p>

username: ptrblck
cooked: <p>I’m not sure, if you posted some lecture notes or if there is a particular question you would like to discuss.<br>
Could you explain what you try to achieve and where you are stuck? <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=9" title=":slight_smile:" class="emoji" alt=":slight_smile:"></p>