I am not able to save model artifacts in S3 bucket using below code. I am successfully able to save the result in output data path and training job is getting completed successfully. I am using the following piece of code.
Can anyone please confirm how do we save the model_artifacts in model-dir using below code.
# train.py code
#!/usr/bin/env python
from __future__ import print_function
import os
import sys
import pandas as pd
prefix = '/opt/ml/'
input_dir = prefix + 'input/data'
output_data_dir = os.path.join(prefix, 'output/data')
model_dir = os.path.join(prefix, 'model')
channel_name='training'
training_path = os.path.join(input_dir, channel_name)
# The function to execute the training.
def train():
print('Starting the training.')
# Take the set of files and read them all into a single pandas dataframe
input_files = [ os.path.join(training_path, file) for file in os.listdir(training_path) ]
raw_data = [ pd.read_csv(file, header=None) for file in input_files ]
input_data = pd.concat(raw_data)
print(pd.DataFrame(input_data))
output_data = input_data.to_csv(os.path.join(output_data_dir, 'output.csv'), header=False, index=False)
if __name__ == '__main__':
train()
# Below are the S3 input and output paths :
output_path = "s3://{}/{}".format(bucket, prefix_output)
S3_input = "s3://{}/{}".format(bucket, prefix)
#Estimator Code
test_estimator = sagemaker.estimator.Estimator(ecr_image, # ECR image arn,
role=role, # execution role
instance_count=1, # no. of sagemaker instances
instance_type='ml.m4.xlarge', # instance type
output_path=output_path, # output path to store model outputs
base_job_name='sagemaker-job1', # job name prefix
sagemaker_session=session # session
)
# Launch instance and start training
test_estimator.fit({'training':S3_input})
What is missing in this code?