예제 #1
0
                                   pred2)  # dl_dx5 = 14 x 14 x 3
            dl_dw_conv, dl_db_conv = conv_backward(dl_dx5, x, w_conv, b_conv,
                                                   pred1)

            dL_dw_conv += dl_dw_conv
            dL_db_conv += dl_db_conv
            dL_dw_fc += dl_dw_fc
            dL_db_fc += dl_db_fc

        k += 1
        if k == num_of_batches:
            k = 0
        w_conv = w_conv - (learning_rate / batch_size * dL_dw_conv)
        b_conv = b_conv - (learning_rate / batch_size * dL_db_conv)
        w_fc = w_fc - (learning_rate / batch_size * dL_dw_fc.transpose())
        b_fc = b_fc - (learning_rate / batch_size * dL_db_fc.transpose())

        print("    CNN    == Loading : {:.2f}%".format(iIter / nIters * 100),
              end='\r')
    print("    CNN    == Loading : 100.00%", end='\n')
    return w_conv, b_conv, w_fc, b_fc


if __name__ == '__main__':
    c1, a1 = main.main_slp_linear()
    c2, a2 = main.main_slp()
    c3, a3 = main.main_mlp()
    c4, a4 = main.main_cnn()

    main.visualize_confusion_matrix_all(c1, a1, c2, a2, c3, a3, c4, a4)
예제 #2
0
            mini_batch_dl_db_fc += dl_db_fc

        print('Iteration # {}/{} loss = {} \r'.format(iter_i + 1,
                                                      NUM_ITERATIONS,
                                                      mini_batch_loss),
              end='')
        loss_values.append(mini_batch_loss)
        # Update
        # print(np.mean(np.abs(mini_batch_dl_dw_conv)), np.mean(np.abs(mini_batch_dl_db_conv)), np.mean(np.abs(mini_batch_dl_dw_fc)), np.mean(np.abs(mini_batch_dl_db_fc)))
        w_conv = w_conv - mini_batch_dl_dw_conv * LEARNING_RATE
        # b_conv = b_conv - mini_batch_dl_db_conv * LEARNING_RATE
        w_fc = w_fc - mini_batch_dl_dw_fc.reshape(w_fc.shape) * LEARNING_RATE
        b_fc = b_fc - mini_batch_dl_db_fc.reshape(b_fc.shape) * LEARNING_RATE

    print()
    axes = plt.gca()
    plt.xlabel('iterations', fontsize=18)
    plt.ylabel('training loss', fontsize=16)
    plt.plot(loss_values)
    plt.show()

    return w_conv, b_conv, w_fc, b_fc


if __name__ == '__main__':
    np.random.seed(42)
    main.main_slp_linear()
    main.main_slp()
    main.main_mlp()
    main.main_cnn()
예제 #3
0
        w_fc -= lr * v_w_fc / np.sqrt(
            s_w_fc +
            1e-7)  # combine momentum and RMSProp to perform update with Adam

        v_b_fc = beta1 * v_b_fc + (1 - beta1) * db_fc / batch_size
        s_b_fc = beta2 * s_b_fc + (1 - beta2) * (db_fc / batch_size)**2
        b_fc -= lr * v_b_fc / np.sqrt(s_b_fc + 1e-7)

        #print(L/batch_size)
        #L_log.append(L/batch_size)
    print("Train Over for SLP")
    '''
    plt.figure(1)
    plt.plot(np.array(L_log))
    plt.draw()
    plt.pause(5)
    plt.clf
    '''
    return w_conv, b_conv, w_fc, b_fc


if __name__ == '__main__':
    retrain_tag = False
    for arg in sys.argv[1:]:
        if arg == "-r":
            retrain_tag = True
    main.main_slp_linear(retrain_tag)
    main.main_slp(retrain_tag)
    main.main_mlp(retrain_tag)
    main.main_cnn(retrain_tag)