Functions | Variables
train_cnn_augmented_data Namespace Reference

Functions

def save_model (model, name)
 
def generate_data_generator (generator, X, Y1, Y2, b)
 

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)
 
 datagen
 training ############################### More...
 
 h
 
 score
 

Function Documentation

def train_cnn_augmented_data.generate_data_generator (   generator,
  X,
  Y1,
  Y2,
  b 
)

Definition at line 196 of file train_cnn_augmented_data.py.

196 def generate_data_generator(generator, X, Y1, Y2, b):
197  genY1 = generator.flow(X, Y1, batch_size=b, seed=7)
198  genY2 = generator.flow(X, Y2, batch_size=b, seed=7)
199  while True:
200  g1 = genY1.next()
201  g2 = genY2.next()
202  yield {'main_input': g1[0]}, {'em_trk_none_netout': g1[1], 'michel_netout': g2[1]}
203 
def generate_data_generator(generator, X, Y1, Y2, b)
def train_cnn_augmented_data.save_model (   model,
  name 
)

Definition at line 36 of file train_cnn_augmented_data.py.

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

Variable Documentation

string train_cnn_augmented_data.actfn1 = 'relu'

Definition at line 77 of file train_cnn_augmented_data.py.

string train_cnn_augmented_data.actfn2 = 'relu'

Definition at line 79 of file train_cnn_augmented_data.py.

train_cnn_augmented_data.args = parser.parse_args()

Definition at line 6 of file train_cnn_augmented_data.py.

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

Definition at line 54 of file train_cnn_augmented_data.py.

string train_cnn_augmented_data.cfg_name = 'sgd_lorate'

Definition at line 60 of file train_cnn_augmented_data.py.

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

Definition at line 49 of file train_cnn_augmented_data.py.

train_cnn_augmented_data.config = read_config(args.config)

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

Definition at line 47 of file train_cnn_augmented_data.py.

string train_cnn_augmented_data.convactfn1 = 'relu'

Definition at line 65 of file train_cnn_augmented_data.py.

string train_cnn_augmented_data.convactfn2 = 'relu'

Definition at line 71 of file train_cnn_augmented_data.py.

train_cnn_augmented_data.datagen
Initial value:
1 = ImageDataGenerator(
2  featurewise_center=False, samplewise_center=False,
3  featurewise_std_normalization=False,
4  samplewise_std_normalization=False,
5  zca_whitening=False,
6  rotation_range=0, width_shift_range=0, height_shift_range=0,
7  horizontal_flip=True, # randomly flip images
8  vertical_flip=False)

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

Definition at line 186 of file train_cnn_augmented_data.py.

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

Definition at line 143 of file train_cnn_augmented_data.py.

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

Definition at line 146 of file train_cnn_augmented_data.py.

train_cnn_augmented_data.default

Definition at line 3 of file train_cnn_augmented_data.py.

int train_cnn_augmented_data.densesize1 = 128

Definition at line 76 of file train_cnn_augmented_data.py.

int train_cnn_augmented_data.densesize2 = 32

Definition at line 78 of file train_cnn_augmented_data.py.

float train_cnn_augmented_data.drop1 = 0.2

Definition at line 73 of file train_cnn_augmented_data.py.

float train_cnn_augmented_data.drop2 = 0.2

Definition at line 80 of file train_cnn_augmented_data.py.

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

Definition at line 118 of file train_cnn_augmented_data.py.

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

Definition at line 156 of file train_cnn_augmented_data.py.

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

Definition at line 130 of file train_cnn_augmented_data.py.

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

Definition at line 139 of file train_cnn_augmented_data.py.

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

Definition at line 142 of file train_cnn_augmented_data.py.

train_cnn_augmented_data.h
Initial value:
1 = model.fit_generator(
2  generate_data_generator(datagen, X_train, EmTrkNone_train, Michel_train, b=batch_size),
3  validation_data=(
4  {'main_input': X_test},
5  {'em_trk_none_netout': EmTrkNone_test, 'michel_netout': Michel_test}),
6  steps_per_epoch=X_train.shape[0]/batch_size, epochs=nb_epoch,
7  verbose=1)
def generate_data_generator(generator, X, Y1, Y2, b)

Definition at line 205 of file train_cnn_augmented_data.py.

train_cnn_augmented_data.help

Definition at line 3 of file train_cnn_augmented_data.py.

train_cnn_augmented_data.img_cols

Definition at line 52 of file train_cnn_augmented_data.py.

train_cnn_augmented_data.img_rows

Definition at line 52 of file train_cnn_augmented_data.py.

train_cnn_augmented_data.loss

Definition at line 124 of file train_cnn_augmented_data.py.

train_cnn_augmented_data.loss_weights

Definition at line 125 of file train_cnn_augmented_data.py.

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

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

Definition at line 85 of file train_cnn_augmented_data.py.

bool train_cnn_augmented_data.maxpool = False

Definition at line 67 of file train_cnn_augmented_data.py.

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

Definition at line 119 of file train_cnn_augmented_data.py.

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

Definition at line 157 of file train_cnn_augmented_data.py.

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

Definition at line 131 of file train_cnn_augmented_data.py.

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

Definition at line 122 of file train_cnn_augmented_data.py.

train_cnn_augmented_data.n = dataY.shape[0]

Definition at line 147 of file train_cnn_augmented_data.py.

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

Definition at line 154 of file train_cnn_augmented_data.py.

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

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

Definition at line 128 of file train_cnn_augmented_data.py.

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

Definition at line 55 of file train_cnn_augmented_data.py.

int train_cnn_augmented_data.nb_conv1 = 5

Definition at line 64 of file train_cnn_augmented_data.py.

int train_cnn_augmented_data.nb_conv2 = 7

Definition at line 70 of file train_cnn_augmented_data.py.

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

Definition at line 56 of file train_cnn_augmented_data.py.

int train_cnn_augmented_data.nb_filters1 = 48

Definition at line 63 of file train_cnn_augmented_data.py.

int train_cnn_augmented_data.nb_filters2 = 0

Definition at line 69 of file train_cnn_augmented_data.py.

int train_cnn_augmented_data.nb_pool = 2

Definition at line 58 of file train_cnn_augmented_data.py.

int train_cnn_augmented_data.ntot = 0

Definition at line 134 of file train_cnn_augmented_data.py.

train_cnn_augmented_data.optimizer

Definition at line 123 of file train_cnn_augmented_data.py.

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

Definition at line 2 of file train_cnn_augmented_data.py.

train_cnn_augmented_data.PATCH_SIZE_D

Definition at line 51 of file train_cnn_augmented_data.py.

train_cnn_augmented_data.PATCH_SIZE_W

Definition at line 51 of file train_cnn_augmented_data.py.

train_cnn_augmented_data.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 217 of file train_cnn_augmented_data.py.

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

Definition at line 121 of file train_cnn_augmented_data.py.

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

Definition at line 135 of file train_cnn_augmented_data.py.

train_cnn_augmented_data.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 88 of file train_cnn_augmented_data.py.

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

Definition at line 155 of file train_cnn_augmented_data.py.

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

Definition at line 129 of file train_cnn_augmented_data.py.