# HG changeset patch
# User bgruening
# Date 1696240827 0
# Node ID 818f9b69d8a0f478c25e9cdbc92a40a44ea5be75
# Parent 0af678661e20d6ef45e1d3e6a1dd662a35b6cfa0
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 80417bf0158a9b596e485dd66408f738f405145a
diff -r 0af678661e20 -r 818f9b69d8a0 keras_train_and_eval.py
--- a/keras_train_and_eval.py Fri Sep 22 17:04:27 2023 +0000
+++ b/keras_train_and_eval.py Mon Oct 02 10:00:27 2023 +0000
@@ -188,6 +188,7 @@
infile1,
infile2,
outfile_result,
+ outfile_history=None,
outfile_object=None,
outfile_y_true=None,
outfile_y_preds=None,
@@ -215,6 +216,9 @@
outfile_result : str
File path to save the results, either cv_results or test result.
+ outfile_history : str, optional
+ File path to save the training history.
+
outfile_object : str, optional
File path to save searchCV object.
@@ -253,9 +257,7 @@
swapping = params["experiment_schemes"]["hyperparams_swapping"]
swap_params = _eval_swap_params(swapping)
estimator.set_params(**swap_params)
-
estimator_params = estimator.get_params()
-
# store read dataframe object
loaded_df = {}
@@ -448,12 +450,20 @@
# train and eval
if hasattr(estimator, "config") and hasattr(estimator, "model_type"):
if exp_scheme == "train_val_test":
- estimator.fit(X_train, y_train, validation_data=(X_val, y_val))
+ history = estimator.fit(X_train, y_train, validation_data=(X_val, y_val))
else:
- estimator.fit(X_train, y_train, validation_data=(X_test, y_test))
+ history = estimator.fit(X_train, y_train, validation_data=(X_test, y_test))
else:
- estimator.fit(X_train, y_train)
-
+ history = estimator.fit(X_train, y_train)
+ if "callbacks" in estimator_params:
+ for cb in estimator_params["callbacks"]:
+ if cb["callback_selection"]["callback_type"] == "CSVLogger":
+ hist_df = pd.DataFrame(history.history)
+ hist_df["epoch"] = np.arange(1, estimator_params["epochs"] + 1)
+ epo_col = hist_df.pop('epoch')
+ hist_df.insert(0, 'epoch', epo_col)
+ hist_df.to_csv(path_or_buf=outfile_history, sep="\t", header=True, index=False)
+ break
if isinstance(estimator, KerasGBatchClassifier):
scores = {}
steps = estimator.prediction_steps
@@ -526,6 +536,7 @@
aparser.add_argument("-X", "--infile1", dest="infile1")
aparser.add_argument("-y", "--infile2", dest="infile2")
aparser.add_argument("-O", "--outfile_result", dest="outfile_result")
+ aparser.add_argument("-hi", "--outfile_history", dest="outfile_history")
aparser.add_argument("-o", "--outfile_object", dest="outfile_object")
aparser.add_argument("-l", "--outfile_y_true", dest="outfile_y_true")
aparser.add_argument("-p", "--outfile_y_preds", dest="outfile_y_preds")
@@ -542,6 +553,7 @@
args.infile1,
args.infile2,
args.outfile_result,
+ outfile_history=args.outfile_history,
outfile_object=args.outfile_object,
outfile_y_true=args.outfile_y_true,
outfile_y_preds=args.outfile_y_preds,
diff -r 0af678661e20 -r 818f9b69d8a0 keras_train_and_eval.xml
--- a/keras_train_and_eval.xml Fri Sep 22 17:04:27 2023 +0000
+++ b/keras_train_and_eval.xml Mon Oct 02 10:00:27 2023 +0000
@@ -8,7 +8,7 @@
echo "@VERSION@"
- '${target_file.element_identifier}.gz' &&
@@ -29,6 +29,9 @@
#end if
--infile2 '$input_options.infile2'
--outfile_result '$outfile_result'
+ #if $save and 'save_csvlogger' in str($save)
+ --outfile_history '$outfile_history'
+ #end if
#if $save and 'save_estimator' in str($save)
--outfile_object '$outfile_object'
#end if
@@ -39,7 +42,6 @@
#if $experiment_schemes.test_split.split_algos.shuffle == 'group'
--groups '$experiment_schemes.test_split.split_algos.groups_selector.infile_g'
#end if
-
]]>
@@ -81,10 +83,14 @@
+
+
+ str(save) and 'save_csvlogger' in str(save)
+
str(save) and 'save_estimator' in str(save)