-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Works mostly now, one caveat is that the model now needs the number of training events and number of validation events specified by keyword args if using from_directory. Getting the size of the number of files does not work as of right now.
- Loading branch information
1 parent
b810701
commit 5c9f3b5
Showing
8 changed files
with
150 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
from factnn import GammaPreprocessor, ProtonPreprocessor, SeparationGenerator, SeparationModel | ||
import os.path | ||
from factnn.data import kfold | ||
|
||
base_dir = "../ihp-pc41.ethz.ch/public/phs/" | ||
obs_dir = [base_dir + "public/"] | ||
gamma_dir = [base_dir + "sim/gamma/"] | ||
proton_dir = [base_dir + "sim/proton/"] | ||
|
||
shape = [30,70] | ||
rebin_size = 3 | ||
|
||
# Get paths from the directories | ||
gamma_paths = [] | ||
for directory in gamma_dir: | ||
for root, dirs, files in os.walk(directory): | ||
for file in files: | ||
if file.endswith("phs.jsonl.gz"): | ||
gamma_paths.append(os.path.join(root, file)) | ||
|
||
|
||
# Get paths from the directories | ||
proton_paths = [] | ||
for directory in proton_dir: | ||
for root, dirs, files in os.walk(directory): | ||
for file in files: | ||
if file.endswith("phs.jsonl.gz"): | ||
proton_paths.append(os.path.join(root, file)) | ||
|
||
|
||
# Now do the Kfold Cross validation Part for both sets of paths | ||
gamma_indexes = kfold.split_data(gamma_paths, kfolds=5) | ||
proton_indexes = kfold.split_data(proton_paths, kfolds=5) | ||
|
||
|
||
gamma_configuration = { | ||
'rebin_size': rebin_size, | ||
'output_file': "../gamma.hdf5", | ||
'shape': shape, | ||
'paths': gamma_indexes[0][0] | ||
} | ||
|
||
proton_configuration = { | ||
'rebin_size': rebin_size, | ||
'output_file': "../proton.hdf5", | ||
'shape': shape, | ||
'paths': proton_indexes[0][0] | ||
} | ||
|
||
|
||
proton_train_preprocessor = ProtonPreprocessor(config=proton_configuration) | ||
gamma_train_preprocessor = GammaPreprocessor(config=gamma_configuration) | ||
|
||
gamma_configuration['paths'] = gamma_indexes[1][0] | ||
proton_configuration['paths'] = proton_indexes[1][0] | ||
|
||
proton_validate_preprocessor = ProtonPreprocessor(config=proton_configuration) | ||
gamma_validate_preprocessor = GammaPreprocessor(config=gamma_configuration) | ||
|
||
|
||
separation_generator_configuration = { | ||
'seed': 1337, | ||
'batch_size': 4, | ||
'start_slice': 0, | ||
'number_slices': 38, | ||
'mode': 'train', | ||
'chunked': False, | ||
'augment': True, | ||
'from_directory': True, | ||
'input_shape': [-1, gamma_train_preprocessor.shape[3]-2, gamma_train_preprocessor.shape[2], gamma_train_preprocessor.shape[1], 1], | ||
} | ||
|
||
separation_validate = SeparationGenerator(config=separation_generator_configuration) | ||
separation_train = SeparationGenerator(config=separation_generator_configuration) | ||
|
||
separation_validate.mode = "validate" | ||
separation_train.mode = "train" | ||
|
||
separation_train.proton_train_preprocessor = proton_train_preprocessor | ||
separation_train.proton_validate_preprocessor = proton_validate_preprocessor | ||
separation_train.train_preprocessor = gamma_train_preprocessor | ||
separation_train.validate_preprocessor = gamma_validate_preprocessor | ||
|
||
separation_model_configuration = { | ||
'conv_dropout': 0.1, | ||
'lstm_dropout': 0.2, | ||
'fc_dropout': 0.4, | ||
'num_conv3d': 3, | ||
'kernel_conv3d': 2, | ||
'strides_conv3d': 1, | ||
'num_lstm': 0, | ||
'kernel_lstm': 2, | ||
'strides_lstm': 1, | ||
'num_fc': 2, | ||
'pooling': True, | ||
'neurons': [16, 16, 16, 8, 32], | ||
'shape': [gamma_train_preprocessor.shape[3]-2, gamma_train_preprocessor.shape[2], gamma_train_preprocessor.shape[1], 1], | ||
'start_slice': 0, | ||
'number_slices': 25, | ||
'activation': 'relu', | ||
} | ||
|
||
separation_model = SeparationModel(config=separation_model_configuration) | ||
|
||
print(separation_model) | ||
""" | ||
Now run the models with the generators! | ||
""" | ||
|
||
separation_model.train_generator = separation_train | ||
separation_model.validate_generator = separation_validate | ||
|
||
separation_model.train(train_generator=separation_train, validate_generator=separation_validate) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters