Commit 062c55c8 authored by Patrick Scheibe's avatar Patrick Scheibe
Browse files

Fix run_fnntraining.py in tests

parent 4e5aba07
......@@ -4,61 +4,36 @@ import logging
import dfpl.options as opt
import dfpl.fingerprint as fp
import dfpl.autoencoder as ac
import dfpl.feedforwardNN as fNN
import dfpl.single_label_model as fNN
import dfpl.utils as utils
project_directory = pathlib.Path(__file__).parent.absolute()
test_train_args = opt.Options(
inputFile=f"{project_directory}/data/S_dataset.csv",
outputDir=f"{project_directory}/modeltraining/",
inputFile=utils.makePathAbsolute(f"{project_directory}/data/S_dataset.csv"),
ecModelDir=utils.makePathAbsolute(f"{project_directory}/output_data/fnnTrainingCompressed/modeltraining"),
outputDir=utils.makePathAbsolute(f"{project_directory}/output_data/fnnTraining"),
ecWeightsFile="",
type='smiles',
fpType='topological',
epochs=11,
epochs=10,
fpSize=2048,
encFPSize=256,
enableMultiLabel=False,
testingFraction=0.2,
kFolds=2,
testSize=0.2,
kFolds=1,
verbose=2,
trainAC=True,
trainFNN=True
)
def run_fnn_training(opts: opt.Options) -> None:
logging.basicConfig(format="DFPL-%(levelname)s: %(message)s", level=logging.INFO)
logging.info("Adding fingerprint to dataset")
df = fp.importDataFile(opts.inputFile, import_function=fp.importSmilesCSV, fp_size=opts.fpSize)
# t = opts.ecWeightsFile
# opts.ecWeightsFile = opts.outputDir + t
if opts.trainAC:
logging.info("Training autoencoder")
encoder = ac.train_full_ac(df, opts)
# encoder.save_weights(opts.acFile)
else:
logging.info("Using trained autoencoder")
(_, encoder) = ac.define_ac_model(input_size=opts.fpSize, encoding_dim=opts.encFPSize)
df = ac.compress_fingerprints(df, encoder)
# train FNNs with compressed features
logging.info("Training the FNN using compressed input data.")
fNN.train_nn_models(df=df, opts=opts)
# train FNNs with uncompressed features
logging.info("Training the FNN using un-compressed input data.")
fNN.train_nn_models(df=df, opts=opts)
logging.info("Done")
def run_fnn_training_multi(opts: opt.Options) -> None:
def run_single_label_training(opts: opt.Options) -> None:
logging.basicConfig(format="DFPL-%(levelname)s: %(message)s", level=logging.INFO)
logging.info("Adding fingerprint to dataset")
opts.outputDir = utils.makePathAbsolute(f"{project_directory}/output_data/fnnTrainingCompressed")
utils.createDirectory(opts.outputDir)
df = fp.importDataFile(opts.inputFile, import_function=fp.importSmilesCSV, fp_size=opts.fpSize)
t = opts.ecWeightsFile
......@@ -70,17 +45,25 @@ def run_fnn_training_multi(opts: opt.Options) -> None:
# encoder.save_weights(opts.acFile)
else:
logging.info("Using trained autoencoder")
(_, encoder) = ac.define_ac_model(input_size=opts.fpSize,
encoding_dim=opts.encFPSize)
(_, encoder) = ac.define_ac_model(opts)
df = ac.compress_fingerprints(df, encoder)
# train FNNs with compressed features
logging.info("Training the FNN using compressed input data.")
fNN.train_nn_models_multi(df=df, opts=opts, use_compressed=True)
opts.compressFeatures = True
fNN.train_single_label_models(df=df, opts=opts)
# train FNNs with uncompressed features
opts.outputDir = utils.makePathAbsolute(f"{project_directory}/output_data/fnnTrainingUncompressed")
utils.createDirectory(opts.outputDir)
logging.info("Training the FNN using un-compressed input data.")
fNN.train_nn_models_multi(df=df, opts=opts, use_compressed=False)
opts.compressFeatures = False
fNN.train_single_label_models(df=df, opts=opts)
logging.info("Done")
if __name__ == '__main__':
run_single_label_training(test_train_args)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment