I am attempting to load a frozen graph created through TensorFlow Keras (.pb) onto a memory limited microcontroller. Via Hyperopt(...) I am optimizing my training hyperparameters, however I would like to include the size of the resulting model as part of the search space. At the moment, I'm including using the weighted loss as an input to hyperopt, something like the following:
def optimizer(args):
...
training_history = nn.train_v00(....)
file_bytes = int(os.path.getsize(frozen_graph_filepath)) # returns size in bytes
final_loss = training_history.history['loss'][-1]
weighted_loss = final_loss*(file_bytes/(100*1024)) # Want model smaller than 100KB
if OPTIMIZATION_TARGET == 'loss':
return_struct = {
'status': STATUS_OK,
'loss': weighted_loss,
'epochs': epochs,
'metrics': {
'accuracy': final_acc
}
}
return return_struct
space = {
'learning_rate': hp.loguniform('learning_rate', np.log(0.00001), np.log(0.05)),
'dropout': hp.uniform('dropout', 0, 0.5),
'batch_size': hp.quniform('batch_size', 32, 128, 2),
'input_seq_len': hp.quniform('seq_len', 32, N_ADC_SAMPLES, 2),
'cnn_n_filters': hp.quniform('cnn_n_filters', 1, 10, 1),
'cnn_kernel_size': hp.quniform('cnn_kernel_size', 1, 10, 1),
'cnn_pool_size': hp.quniform('cnn_pool_size', 1, 10, 1)
}
t = Trials()
best = fmin(optimizer, space, algo=tpe.suggest, max_evals=MAX_EVALS, trials=t)
From what I have found thus far, there isn't a way to directly backpropagate the size of the model back through the training, but is there a better way of doing this?
Thanks for the consideration!