Skip to content

Instantly share code, notes, and snippets.

@pythonlessons
Created April 30, 2020 05:23
Show Gist options
  • Select an option

  • Save pythonlessons/6b8c16efac60f841fe615365aa6f22b6 to your computer and use it in GitHub Desktop.

Select an option

Save pythonlessons/6b8c16efac60f841fe615365aa6f22b6 to your computer and use it in GitHub Desktop.
Yolo_v3_weight_initialization
import numpy as np
import tensorflow as tf
import matplotlib.pyplot as plt
%matplotlib inline
plt.figure(figsize=(20,10))
x = np.random.randn(2000, 800) * 0.01 # Create input data
stds = [0.1, 0.05, 0.02, 0.01, 0.005, 0.001] # Try to use different standard deviations so that the initial weights are different
for i, std in enumerate(stds):
# First layer - fully connected layer
dense_1 = tf.keras.layers.Dense(750, kernel_initializer=tf.random_normal_initializer(std), activation='tanh')
output_1 = dense_1(x)
# Second layer - fully connected layer
dense_2 = tf.keras.layers.Dense(700, kernel_initializer=tf.random_normal_initializer(std), activation='tanh')
output_2 = dense_2(output_1)
# Third layer - fully connected layer
dense_3 = tf.keras.layers.Dense(650, kernel_initializer=tf.random_normal_initializer(std), activation='tanh')
output_3 = dense_3(output_2).numpy().flatten()
plt.subplot(1, len(stds), i+1)
plt.hist(output_3, bins=600, range=[-1, 1])
plt.xlabel('std = %.3f' %std)
plt.yticks([])
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment