def densenettrain(): print("densenet begin") model = fc.get_model(50176) root = '/Users/lizhenhao/Desktop/helloworld/im/densenet' weights_savedir = "/Users/lizhenhao/PycharmProjects/laserFilm/weights/freeze/densenet" acc_savepath = "/Users/lizhenhao/PycharmProjects/laserFilm/weights/freeze/densenet/acc.png" loss_savepath = "/Users/lizhenhao/PycharmProjects/laserFilm/weights/freeze/densenet/loss.png" train_f, train_y = getdata_fromtxt(root + '/train.txt') vali_f, vali_y = getdata_fromtxt(root + '/vali.txt') test_f, test_y = getdata_fromtxt(root + '/test.txt') mycall = mycallback(test_f, test_y, weights_savedir) model.compile(loss=tf.keras.losses.binary_crossentropy, optimizer=tf.keras.optimizers.Adam(learning_rate=0.001), metrics=[tf.keras.metrics.binary_accuracy]) model.fit(train_f, train_y, epochs=20, shuffle=True, validation_data=(vali_f, vali_y), callbacks=[mycall]) draw.draw_acc(mycall.train_acc, mycall.vali_acc, mycall.test_acc, mycall.epoch, acc_savepath) draw.draw_loss(mycall.train_loss, mycall.vali_loss, mycall.test_loss, mycall.epoch, loss_savepath) print('densenet done') return model
loss = loss + (y_new[i] - y_p) * (y_new[i] - y_p) / 2 all_da = all_da + da(y_new[i], y_p, x_new[i]) all_db = all_db + db(y_new[i], y_p) #loss_ = calc_loss(a = a,b=b,x=np.array(x),y=np.array(y)) all_d = np.array([all_da / len(x_new), all_db / len(x_new)]) #all_d = np.array([all_da, all_db]) loss = loss / len(x_new) # 在图1的曲面上绘制 loss 点 draw.draw_curved_surface_loss(a, b, loss, curved_surface) # 在图2的等高线上绘制 loss 点 draw.draw_equal_altitude_loss(a, b, last_a, last_b) # 绘制图3中的回归直线 draw.draw_regression_line(a, b, x, y) # 绘制图4的loss更新曲线 draw.draw_loss(loss, step, all_loss, all_step) # 更新参数 last_a = a last_b = b E_g = gamma * E_g + (1 - gamma) * (all_db**2) rms_g = np.sqrt(E_g + epsilon) E_theta = gamma * E_theta + (1 - gamma) * (theta**2) rms_theta = np.sqrt(E_theta + epsilon) theta = -(rms_theta / rms_g) * all_d [a, b] = [a, b] + theta if step % 1 == 0: