示例#1
0
def Profile_Activation_Functions():
    # First, initialize two networks. One will use Rational activation functions
    # and the other will use Tanh.
    Rational_NN = Network.Neural_Network(Num_Hidden_Layers=5,
                                         Neurons_Per_Layer=100,
                                         Input_Dim=3,
                                         Output_Dim=1,
                                         Activation_Function="Rational")
    Tanh_NN = Network.Neural_Network(Num_Hidden_Layers=5,
                                     Neurons_Per_Layer=100,
                                     Input_Dim=3,
                                     Output_Dim=1,
                                     Activation_Function="Tanh")

    # Now generate some random data.
    Data = torch.rand((20000, 3), dtype=torch.float32, requires_grad=True)

    # Pass the data through both networks, time it.
    Rational_Timer = Timing.Timer()
    Tanh_Timer = Timing.Timer()

    Rational_Timer.Start()
    Rational_NN(Data)
    Rational_Time = Rational_Timer.Stop()

    Tanh_Timer.Start()
    Tanh_NN(Data)
    Tanh_Time = Tanh_Timer.Stop()

    # Print results.
    print("Rational: %fs" % Rational_Time)
    print("Tanh:     %fs" % Tanh_Time)