话不多说,直接上代码,看不懂的朋友,欢迎留言。
import numpy as np import tensorflow as tf import matplotlib.pyplot as plt ACTIVATION = tf.nn.relu #激励函数 N_LAYERS = 7 #层数 N_HIDDEN_UNITS = 30 #隐藏层的神经元个数 def fix_seed(seed=1): # reproducible np.random.seed(seed) tf.set_random_seed(seed) def plot_his(inputs, inputs_norm): # plot histogram for the inputs of every layer for j, all_inputs in enumerate([inputs, inputs_norm]): for i, input in enumerate(all_inputs): plt.subplot(2, len(all_inputs), j*len(all_inputs)+(i+1)) plt.cla() if i == 0: the_range = (-7, 10) else: the_range = (-1, 1) plt.hist(input.ravel(), bins=15, range=the_range, color='#FF5733') plt.yticks(()) if j == 1: plt.xticks(the_range) else: plt.xticks(()) ax = plt.gca() ax.spines['right'].set_color('none') ax.spines[