Diff of /src/networkTraining.py [000000] .. [e9ece0]

Switch to unified view

a b/src/networkTraining.py
1
""" 
2
Copyright (c) 2016, Jose Dolz .All rights reserved.
3
Redistribution and use in source and binary forms, with or without modification,
4
are permitted provided that the following conditions are met:
5
    1. Redistributions of source code must retain the above copyright notice,
6
       this list of conditions and the following disclaimer.
7
    2. Redistributions in binary form must reproduce the above copyright notice,
8
       this list of conditions and the following disclaimer in the documentation
9
       and/or other materials provided with the distribution.
10
    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
11
    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
12
    OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
13
    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
14
    HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
15
    WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
16
    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
17
    OTHER DEALINGS IN THE SOFTWARE.
18
Jose Dolz. Dec, 2016.
19
email: jose.dolz.upv@gmail.com
20
LIVIA Department, ETS, Montreal.
21
"""
22
23
import sys
24
import pdb
25
import numpy
26
27
from LiviaNet.generateNetwork import generateNetwork
28
from LiviaNet.startTraining import startTraining
29
30
""" To print function usage """
31
def printUsage(error_type):
32
    if error_type == 1:
33
        print(" ** ERROR!!: Few parameters used.")
34
    else:
35
        print(" ** ERROR!!: Asked to start with an already created network but its name is not specified.")
36
        
37
    print(" ******** USAGE ******** ")
38
    print(" --- argv 1: Name of the configIni file.")
39
    print(" --- argv 2: Type of training:")
40
    print(" ------------- 0: Create a new model and start training")
41
    print(" ------------- 1: Use an existing model to keep on training (Requires an additional input with model name)")
42
    print(" --- argv 3: (Optional, but required if arg 2 is equal to 1) Network model name")
43
44
45
def networkTraining(argv):
46
    # Number of input arguments
47
    #    1: ConfigIniName
48
    #    2: TrainingType
49
    #             0: Create a new model and start training
50
    #             1: Use an existing model to keep on training (Requires an additional input with model name)
51
    #    3: (Optional, but required if arg 2 is equal to 1) Network model name
52
   
53
    # Do some sanity checks
54
    
55
    if len(argv) < 2:
56
        printUsage(1)
57
        sys.exit()
58
    
59
    configIniName = argv[0]
60
    trainingType  = argv[1]
61
    
62
    if trainingType == '1' and len(argv) == 2:
63
        printUsage(2)
64
        sys.exit()
65
        
66
    if len(argv)>2:
67
        networkModelName = argv[2]
68
   
69
    # Creating a new model 
70
    if trainingType == '0':
71
        print " ******************************************  CREATING NETWORK ******************************************"
72
        networkModelName = generateNetwork(configIniName)
73
        print " ******************************************  NETWORK CREATED ******************************************"
74
75
    # Training the network in model name
76
    print " ******************************************  STARTING NETWORK TRAINING ******************************************"
77
    startTraining(networkModelName,configIniName)
78
    print " ******************************************  DONE  ******************************************"
79
  
80
   
81
if __name__ == '__main__':
82
   networkTraining(sys.argv[1:])