title: How to save Tensorflow model in S3 (as /output/model.tar.gz) when using Tensorflow Estimator in AWS Sagemaker
body: <p>I have a Keras model getting trained using an entry_point script and I am using the following pieces of code to store the model artifacts (in the entry_point script).</p>
  <pre class="lang-py prettyprint-override"><code>parser.add_argument('--model_dir', type=str, default=os.environ['SM_MODEL_DIR'])
  args, _ = parser.parse_known_args()
  model_dir  = args.model_dir
  ---
  
  tf.keras.models.save_model(
        model,
        os.path.join(model_dir, 'model/1'),
        overwrite=True,
        include_optimizer=True
       )
  </code></pre>
  <p>Ideally, the model_dir should be <code>opt/ml/model</code> and Sagemaker should automatically move the contents of this folder to S3 as <code>s3://&lt;default_bucket&gt;/&lt;training_name&gt;/output/model.tar.gz</code></p>
  <p>When I run the <code>estimator.fit({'training': training_input_path})</code>, the training is successful, but the Cloudwatch logs show the following:</p>
  <pre><code>2020-09-16 02:49:12,458 sagemaker_tensorflow_container.training WARNING  No model artifact is saved under the path /opt/ml/model. Your training job will not save any model files to S3.
  </code></pre>
  <p>Even then, <strong>Sagemaker does store</strong> my model artifacts, with the only difference being that instead of storing them in <code>s3://&lt;default_bucket&gt;/&lt;training_name&gt;/output/model.tar.gz</code>, they are now stored unzipped as <code>s3://&lt;default_bucket&gt;/&lt;training_name&gt;/model/model/1/saved_model.pb</code> along with the <em>variables and assets folder</em>. Because of this, <code>estimator.deploy()</code> call fails as it is unable to find the artifacts in the <em>output/</em> directory.</p>
  <pre><code>Sagemaker Python SDK - 2.6.0
  </code></pre>
  <p>Estimator code:</p>
  <pre class="lang-py prettyprint-override"><code>from sagemaker.tensorflow import TensorFlow
  
  tf_estimator = TensorFlow(entry_point='autoencoder-model.py',
                         role=role,
                         instance_count=1,
                         instance_type='ml.m5.large',
                         framework_version=&quot;2.3.0&quot;,
                         py_version=&quot;py37&quot;,
                         debugger_hook_config=False,
                         hyperparameters={'epochs': 20},
                         source_dir='/home/ec2-user/SageMaker/model',
                         subnets=['subnet-1', 'subnet-2'],
                         security_group_ids=['sg-1', 'sg-1'])
  </code></pre>
  <p>What could I be doing wrong here?</p>