start_session.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/usr/bin/python3
  2. # File designed to be launched by user
  3. print("Start script")
  4. # Import python libraries
  5. from scipy.special import expit
  6. import argparse
  7. # Import local code to call
  8. from lab import generator, trainer, benchmark
  9. # Parse script arguments
  10. parser = argparse.ArgumentParser(description = "Start a training session for a neuronal network and display results.")
  11. parser.add_argument('-a, --alpha', help = "set the learning rate", dest="learnRate", type = float, default = 0.05)
  12. parser.add_argument('-e, --epochs', help = "set the number of iterations", dest="epochs", type = int, default = 2)
  13. args = parser.parse_args()
  14. # Parameters
  15. print("Parameters")
  16. print("Learning rate : ", args.learnRate)
  17. print("Number of epochs : ", args.epochs)
  18. activation = expit
  19. activationDerivative = lambda x : expit(x) * (1 - expit(x))
  20. # Session
  21. print("Start session")
  22. print("... generating neural network ...")
  23. network = generator.generate(activation, activationDerivative, generator.gaussAdaptedDev)
  24. print("... compute precision before training ... ")
  25. precisionBefore = benchmark.computePrecision(network)
  26. print("... train the network (can take a while) ... ")
  27. network = trainer.train(network, args.learnRate, args.epochs)
  28. print("... compute precision after training ... ")
  29. precisionAfter = benchmark.computePrecision(network)
  30. print("End of session")
  31. # Display results
  32. print("Precision before training : ", precisionBefore)
  33. print("Precision after training : ", precisionAfter)