I donโt think there is a way to pass the parameter "per turn" to GridSearchCV . Perhaps the easiest approach would be to subclass KerasRegressor to do what you want.
class KerasRegressorTB(KerasRegressor): def __init__(self, *args, **kwargs): super(KerasRegressorTB, self).__init__(*args, **kwargs) def fit(self, x, y, log_dir=None, **kwargs): cbs = None if log_dir is not None: params = self.get_params() conf = ",".join("{}={}".format(k, params[k]) for k in sorted(params)) conf_dir = os.path.join(log_dir, conf) cbs = [TensorBoard(log_dir=conf_dir, histogram_freq=0, write_graph=True, write_images=False)] super(KerasRegressorTB, self).fit(x, y, callbacks=cbs, **kwargs)
You would use it like:
# ... estimator = KerasRegressorTB(build_fn=create_3_layers_model, input_dim=input_dim, output_dim=output_dim)
Update:
Since GridSearchCV runs the same model (i.e., the same parameter configuration) more than once due to cross-validation, the previous code ultimately puts several traces in each run. Looking at the source ( here and here ), there seems to be no way to get the โcurrent split identifierโ. At the same time, you should not just check for the existence of existing folders and add hooks as needed, because the tasks are being performed (perhaps at least, although I'm not sure if this is the case with Keras / TF) in parallel. You can try something like this:
import itertools import os class KerasRegressorTB(KerasRegressor): def __init__(self, *args, **kwargs): super(KerasRegressorTB, self).__init__(*args, **kwargs) def fit(self, x, y, log_dir=None, **kwargs): cbs = None if log_dir is not None:
I use os calls for compatibility with Python 2, but if you use Python 3, you can consider the more convenient pathlib module to handle the path and directory.
Note. I forgot to mention this before, but just in case, note that passing write_graph=True will register a graph for a run, which, depending on your model, can mean a lot (relatively speaking) of this space. The same goes for write_images , although I do not know how much space is required for this function.