Functions | Variables
train_cnn Namespace Reference

Functions

def save_model (model, name)
 

Variables

 parser = argparse.ArgumentParser(description='Run CNN training on patches with a few different hyperparameter sets.')
 
 help
 
 default
 
 args = parser.parse_args()
 
 config = read_config(args.config)
 configuration ############################# More...
 
 CNN_INPUT_DIR = config['training_on_patches']['input_dir']
 
 PATCH_SIZE_W
 
 PATCH_SIZE_D
 
 img_rows
 
 img_cols
 
 batch_size = config['training_on_patches']['batch_size']
 
 nb_classes = config['training_on_patches']['nb_classes']
 
 nb_epoch = config['training_on_patches']['nb_epoch']
 
int nb_pool = 2
 
string cfg_name = 'sgd_lorate'
 
int nb_filters1 = 48
 
int nb_conv1 = 5
 
string convactfn1 = 'relu'
 
bool maxpool = False
 
int nb_filters2 = 0
 
int nb_conv2 = 7
 
string convactfn2 = 'relu'
 
float drop1 = 0.2
 
int densesize1 = 128
 
string actfn1 = 'relu'
 
int densesize2 = 32
 
string actfn2 = 'relu'
 
float drop2 = 0.2
 
 main_input = Input(shape=(img_rows, img_cols, 1), name='main_input')
 CNN definition ############################. More...
 
 x
 
 em_trk_none = Dense(3, activation='softmax', name='em_trk_none_netout')(x)
 
 michel = Dense(1, activation='sigmoid', name='michel_netout')(x)
 
 sgd = SGD(lr=0.01, decay=1e-5, momentum=0.9, nesterov=True)
 
 model = Model(inputs=[main_input], outputs=[em_trk_none, michel])
 
 optimizer
 
 loss
 
 loss_weights
 
 n_training = count_events(CNN_INPUT_DIR, 'training')
 read data sets ############################ More...
 
 X_train = np.zeros((n_training, PATCH_SIZE_W, PATCH_SIZE_D, 1), dtype=np.float32)
 
 EmTrkNone_train = np.zeros((n_training, 3), dtype=np.int32)
 
 Michel_train = np.zeros((n_training, 1), dtype=np.int32)
 
int ntot = 0
 
list subdirs = [f for f in os.listdir(CNN_INPUT_DIR) if 'training' in f]
 
list filesX = [f for f in os.listdir(CNN_INPUT_DIR + '/' + dirname) if '_x.npy' in f]
 
 fnameY = fnameX.replace('_x.npy', '_y.npy')
 
 dataX = np.load(CNN_INPUT_DIR + '/' + dirname + '/' + fnameX)
 
 dataY = np.load(CNN_INPUT_DIR + '/' + dirname + '/' + fnameY)
 
 n = dataY.shape[0]
 
 n_testing = count_events(CNN_INPUT_DIR, 'testing')
 
 X_test = np.zeros((n_testing, PATCH_SIZE_W, PATCH_SIZE_D, 1), dtype=np.float32)
 
 EmTrkNone_test = np.zeros((n_testing, 3), dtype=np.int32)
 
 Michel_test = np.zeros((n_testing, 1), dtype=np.int32)
 
 h
 training ############################### More...
 
 score
 

Function Documentation

def train_cnn.save_model (   model,
  name 
)

Definition at line 35 of file train_cnn.py.

35 def save_model(model, name):
36  try:
37  with open(name + '_architecture.json', 'w') as f:
38  f.write(model.to_json())
39  model.save_weights(name + '_weights.h5', overwrite=True)
40  return True # Save successful
41  except:
42  return False # Save failed
43 
int open(const char *, int)
Opens a file descriptor.
def save_model(model, name)
Definition: train_cnn.py:35

Variable Documentation

string train_cnn.actfn1 = 'relu'

Definition at line 76 of file train_cnn.py.

string train_cnn.actfn2 = 'relu'

Definition at line 78 of file train_cnn.py.

train_cnn.args = parser.parse_args()

Definition at line 6 of file train_cnn.py.

train_cnn.batch_size = config['training_on_patches']['batch_size']

Definition at line 53 of file train_cnn.py.

string train_cnn.cfg_name = 'sgd_lorate'

Definition at line 59 of file train_cnn.py.

train_cnn.CNN_INPUT_DIR = config['training_on_patches']['input_dir']

Definition at line 48 of file train_cnn.py.

train_cnn.config = read_config(args.config)

configuration #############################

Definition at line 46 of file train_cnn.py.

string train_cnn.convactfn1 = 'relu'

Definition at line 64 of file train_cnn.py.

string train_cnn.convactfn2 = 'relu'

Definition at line 70 of file train_cnn.py.

train_cnn.dataX = np.load(CNN_INPUT_DIR + '/' + dirname + '/' + fnameX)

Definition at line 142 of file train_cnn.py.

train_cnn.dataY = np.load(CNN_INPUT_DIR + '/' + dirname + '/' + fnameY)

Definition at line 145 of file train_cnn.py.

train_cnn.default

Definition at line 3 of file train_cnn.py.

int train_cnn.densesize1 = 128

Definition at line 75 of file train_cnn.py.

int train_cnn.densesize2 = 32

Definition at line 77 of file train_cnn.py.

float train_cnn.drop1 = 0.2

Definition at line 72 of file train_cnn.py.

float train_cnn.drop2 = 0.2

Definition at line 79 of file train_cnn.py.

train_cnn.em_trk_none = Dense(3, activation='softmax', name='em_trk_none_netout')(x)

Definition at line 117 of file train_cnn.py.

train_cnn.EmTrkNone_test = np.zeros((n_testing, 3), dtype=np.int32)

Definition at line 155 of file train_cnn.py.

train_cnn.EmTrkNone_train = np.zeros((n_training, 3), dtype=np.int32)

Definition at line 129 of file train_cnn.py.

list train_cnn.filesX = [f for f in os.listdir(CNN_INPUT_DIR + '/' + dirname) if '_x.npy' in f]

Definition at line 138 of file train_cnn.py.

train_cnn.fnameY = fnameX.replace('_x.npy', '_y.npy')

Definition at line 141 of file train_cnn.py.

train_cnn.h
Initial value:
1 = model.fit({'main_input': X_train},
2  {'em_trk_none_netout': EmTrkNone_train, 'michel_netout': Michel_train},
3  validation_data=(
4  {'main_input': X_test},
5  {'em_trk_none_netout': EmTrkNone_test, 'michel_netout': Michel_test}),
6  batch_size=batch_size, epochs=nb_epoch, shuffle=True,
7  verbose=1)

training ###############################

Definition at line 186 of file train_cnn.py.

train_cnn.help

Definition at line 3 of file train_cnn.py.

train_cnn.img_cols

Definition at line 51 of file train_cnn.py.

train_cnn.img_rows

Definition at line 51 of file train_cnn.py.

train_cnn.loss

Definition at line 123 of file train_cnn.py.

train_cnn.loss_weights

Definition at line 124 of file train_cnn.py.

train_cnn.main_input = Input(shape=(img_rows, img_cols, 1), name='main_input')

CNN definition ############################.

Definition at line 84 of file train_cnn.py.

bool train_cnn.maxpool = False

Definition at line 66 of file train_cnn.py.

train_cnn.michel = Dense(1, activation='sigmoid', name='michel_netout')(x)

Definition at line 118 of file train_cnn.py.

train_cnn.Michel_test = np.zeros((n_testing, 1), dtype=np.int32)

Definition at line 156 of file train_cnn.py.

train_cnn.Michel_train = np.zeros((n_training, 1), dtype=np.int32)

Definition at line 130 of file train_cnn.py.

train_cnn.model = Model(inputs=[main_input], outputs=[em_trk_none, michel])

Definition at line 121 of file train_cnn.py.

train_cnn.n = dataY.shape[0]

Definition at line 146 of file train_cnn.py.

train_cnn.n_testing = count_events(CNN_INPUT_DIR, 'testing')

Definition at line 153 of file train_cnn.py.

train_cnn.n_training = count_events(CNN_INPUT_DIR, 'training')

read data sets ############################

Definition at line 127 of file train_cnn.py.

train_cnn.nb_classes = config['training_on_patches']['nb_classes']

Definition at line 54 of file train_cnn.py.

int train_cnn.nb_conv1 = 5

Definition at line 63 of file train_cnn.py.

int train_cnn.nb_conv2 = 7

Definition at line 69 of file train_cnn.py.

train_cnn.nb_epoch = config['training_on_patches']['nb_epoch']

Definition at line 55 of file train_cnn.py.

int train_cnn.nb_filters1 = 48

Definition at line 62 of file train_cnn.py.

int train_cnn.nb_filters2 = 0

Definition at line 68 of file train_cnn.py.

int train_cnn.nb_pool = 2

Definition at line 57 of file train_cnn.py.

int train_cnn.ntot = 0

Definition at line 133 of file train_cnn.py.

train_cnn.optimizer

Definition at line 122 of file train_cnn.py.

train_cnn.parser = argparse.ArgumentParser(description='Run CNN training on patches with a few different hyperparameter sets.')

Definition at line 2 of file train_cnn.py.

train_cnn.PATCH_SIZE_D

Definition at line 50 of file train_cnn.py.

train_cnn.PATCH_SIZE_W

Definition at line 50 of file train_cnn.py.

train_cnn.score
Initial value:
1 = model.evaluate({'main_input': X_test},
2  {'em_trk_none_netout': EmTrkNone_test, 'michel_netout': Michel_test},
3  verbose=0)

Definition at line 198 of file train_cnn.py.

train_cnn.sgd = SGD(lr=0.01, decay=1e-5, momentum=0.9, nesterov=True)

Definition at line 120 of file train_cnn.py.

list train_cnn.subdirs = [f for f in os.listdir(CNN_INPUT_DIR) if 'training' in f]

Definition at line 134 of file train_cnn.py.

train_cnn.x
Initial value:
1 = Conv2D(nb_filters1, (nb_conv1, nb_conv1),
2  padding='valid', data_format='channels_last',
3  activation=LeakyReLU())(main_input)

Definition at line 87 of file train_cnn.py.

train_cnn.X_test = np.zeros((n_testing, PATCH_SIZE_W, PATCH_SIZE_D, 1), dtype=np.float32)

Definition at line 154 of file train_cnn.py.

train_cnn.X_train = np.zeros((n_training, PATCH_SIZE_W, PATCH_SIZE_D, 1), dtype=np.float32)

Definition at line 128 of file train_cnn.py.