def test_tf(sagemaker_session): with timeout(minutes=15): script_path = os.path.join(DATA_DIR, 'iris', 'iris-dnn-classifier.py') estimator = TensorFlow(entry_point=script_path, role='SageMakerRole', training_steps=1, evaluation_steps=1, hyperparameters={'input_tensor_name': 'inputs'}, train_instance_count=1, train_instance_type='ml.c4.xlarge', sagemaker_session=sagemaker_session, base_job_name='test-tf') inputs = estimator.sagemaker_session.upload_data( path=DATA_PATH, key_prefix='integ-test-data/tf_iris') estimator.fit(inputs) print('job succeeded: {}'.format(estimator.latest_training_job.name)) with timeout_and_delete_endpoint(estimator=estimator, minutes=20): json_predictor = estimator.deploy(initial_instance_count=1, instance_type='ml.c4.xlarge') result = json_predictor.predict([6.4, 3.2, 4.5, 1.5]) print('predict result: {}'.format(result))
def test_cifar(sagemaker_session): with timeout(minutes=15): script_path = os.path.join(DATA_DIR, 'cifar_10', 'source') dataset_path = os.path.join(DATA_DIR, 'cifar_10', 'data') estimator = TensorFlow(entry_point='resnet_cifar_10.py', source_dir=script_path, role='SageMakerRole', training_steps=20, evaluation_steps=5, train_instance_count=2, train_instance_type='ml.p2.xlarge', sagemaker_session=sagemaker_session, base_job_name='test-cifar') inputs = estimator.sagemaker_session.upload_data( path=dataset_path, key_prefix='data/cifar10') estimator.fit(inputs) print('job succeeded: {}'.format(estimator.latest_training_job.name)) with timeout_and_delete_endpoint(estimator=estimator, minutes=20): predictor = estimator.deploy(initial_instance_count=1, instance_type='ml.p2.xlarge') predictor.serializer = PickleSerializer() predictor.content_type = PICKLE_CONTENT_TYPE data = np.random.randn(32, 32, 3) predict_response = predictor.predict(data) assert len( predict_response['outputs']['probabilities']['floatVal']) == 10
def test_tf_async(sagemaker_session, tf_full_version): training_job_name = "" with timeout(minutes=5): script_path = os.path.join(DATA_DIR, 'iris', 'iris-dnn-classifier.py') estimator = TensorFlow(entry_point=script_path, role='SageMakerRole', framework_version=tf_full_version, training_steps=1, evaluation_steps=1, hyperparameters={'input_tensor_name': 'inputs'}, train_instance_count=1, train_instance_type='ml.c4.xlarge', sagemaker_session=sagemaker_session, base_job_name='test-tf') inputs = estimator.sagemaker_session.upload_data( path=DATA_PATH, key_prefix='integ-test-data/tf_iris') estimator.fit(inputs, wait=False) training_job_name = estimator.latest_training_job.name time.sleep(20) with timeout_and_delete_endpoint(estimator=estimator, minutes=35): estimator = TensorFlow.attach(training_job_name=training_job_name, sagemaker_session=sagemaker_session) json_predictor = estimator.deploy(initial_instance_count=1, instance_type='ml.c4.xlarge') result = json_predictor.predict([6.4, 3.2, 4.5, 1.5]) print('predict result: {}'.format(result))