我在使用R的keras包时,尝试使用标志和tuning_run来调整我的全连接深度学习模型的超参数。我在哪里可以找到每次运行中使用的实际标志值?
我尝试在生成的结果数据框和runs/文件夹中查找使用的超参数值。虽然所有运行的准确率值、损失函数和其他元数据都在那里,但生成这些结果的超参数并未包含在内(我遵循了此处给出的示例:https://tensorflow.rstudio.com/tools/tfruns/articles/tuning.html)。我调用tuning_run的方式如下
runs <- tuning_run("test.R", flags = list(dropout1=c(0.5,0.4,0.3),dropout2=c(0.3,0.2),dense_units=c(128,256)),sample=0.3)
我的模型使用标志的方式如下
model <- keras_model_sequential()model %>% layer_dense(units = 256, activation = 'relu', input_shape = c(784)) %>% layer_dropout(rate = FLAGS$dropout_1) %>% layer_dense(units = FLAGS$dense_units, activation = 'relu') %>% layer_dropout(rate = FLAGS$dropout_2) %>% layer_dense(units = 10, activation = 'softmax')
当我运行它,并随后查找生成特定验证准确率的标志值时(在runs数据框中),这是我观察到的
Data frame: 2 x 25 run_dir eval_loss eval_acc metric_loss metric_acc1 runs/2019-03-29T00-14-10Z 0.1315 0.9794 0.0075 0.99772 runs/2019-03-29T00-10-37Z 0.1326 0.9816 0.0096 0.9973 metric_val_loss metric_val_acc1 0.1475 0.97942 0.1443 0.9794# ... with 18 more columns:# samples, validation_samples, batch_size, epochs, epochs_completed,# metrics, model, loss_function, optimizer, learning_rate, script, start,# end, completed, output, source_code, context, type
我想知道在每次迭代中使用的标志值在哪里找到。还是我做错了什么?任何帮助将不胜感激。谢谢!
回答:
我发现问题所在了。标志也需要在目标脚本中定义,keras才能报告它们。这就是为什么结果框架中没有显示标志的原因。
一旦我在test.R中添加了这些行,问题就解决了
FLAGS <- flags( flag_numeric('dropout_1', 0.04, 'First dropout'), flag_numeric('dropout_2', 0.3, 'Second dropout'), flag_integer('dense_units', 128, 'Units in dense layer'))
相同的问题和解决方案在此处讨论:https://github.com/rstudio/tfruns/issues/24