使用SageMaker时提前停止并回调Keras

使用SageMaker时提前停止并回调Keras,keras,amazon-sagemaker,Keras,Amazon Sagemaker,我正在使用sagemaker训练keras模型。在培训模型时,我需要实施早期回采方法 是否有方法传递回调,如EarlyStopping、History等 按照传统方式,我们将其作为参数传递给keras的拟合函数: results = model.fit(train_x_trim, train_y_trim, validation_data=(test_x, test_y), epochs=FLAGS.epoch,

我正在使用sagemaker训练keras模型。在培训模型时,我需要实施早期回采方法

是否有方法传递回调,如EarlyStopping、History等

按照传统方式,我们将其作为参数传递给keras的拟合函数:

results = model.fit(train_x_trim, train_y_trim, 
                    validation_data=(test_x, test_y), 
                    epochs=FLAGS.epoch,  
                    verbose=0, 
                    callbacks=[tboard, checkpointer, early_stopping, history])
但是,如果使用SageMaker,我们需要调用SageMaker的fit函数,它不支持回调

from sagemaker.tensorflow import TensorFlow 
iris_estimator = TensorFlow(entry_point='training_code.py', 
                            role=role, output_path=model_location, 
                            code_location=custom_code_upload_location, 
                            train_instance_count=1, 
                            train_instance_type='ml.c4.xlarge', 
                            training_steps=1000, 
                            evaluation_steps=100)

你知道如何在SageMaker中实现回调吗

我为迟来的回复道歉

看起来您上面指定的Keras代码本质上就是您的算法代码。这将在您的用户脚本中定义,即您提供的SageMaker Python SDK示例中的“training_code.py”

从TensorFlow 1.11开始,SageMaker预定义的TensorFlow容器支持“脚本模式”。您应该能够在用户脚本中指定Keras回调

有关更多信息: