experiencor / keras-yolo2

Easy training on custom dataset. Various backends (MobileNet and SqueezeNet) supported. A YOLO demo to detect raccoon run entirely in brower is accessible at https://git.io/vF7vI (not on Windows).
MIT License
1.73k stars 785 forks source link

Why randomize weights of the last layer in Yolo Step-by-Step.ipynb? #336

Open jorgeMariano opened 6 years ago

jorgeMariano commented 6 years ago

Hi, First of all, thank you for sharing this amazing work. Could you explain, why you do this operation?

layer   = model.layers[-4] # the last convolutional layer
weights = layer.get_weights()

new_kernel = np.random.normal(size=weights[0].shape)/(GRID_H*GRID_W)
new_bias   = np.random.normal(size=weights[1].shape)/(GRID_H*GRID_W)

layer.set_weights([new_kernel, new_bias])

Thanks in advance.

ngrayluna commented 4 years ago

Recall that we are using a pretrained model which was trained on a large data set. We are using this model via transfer learning.  To do this, we need to customize the pretrained model. Since we have a small data set (e.g. the raccoon data set), we are going with feature-extraction approach.

The fine-extraction approach involves adding a new classifier on top of the pretrained model. And recall that when we train a model from scratch we initialize our weights to random values.

You can learn more about both types of transfer learning on the TensorFlow Tutorial's page: https://www.tensorflow.org/tutorials/images/transfer_learning