Hot questions for Using Neural networks in amazon sagemaker

Question:

What is underlying algorithm for Sagemaker's Neural Topic Model? I have hard time googling for details, and the documentation doesn't mention any paper.

Googling for 'neural topic model' doesn't exactly answer my question, since a couple of methods seems to be called that.


Answer:

Seems like AWS SageMaker team answered the question, https://forums.aws.amazon.com/thread.jspa?threadID=270493&tstart=0

Question:

I trained my model in Amazon-SageMaker and downloaded it to my local computer. Unfortunately, I don't have any idea how to run the model locally.

The Model is in a directory with files like:

image-classification-0001.params
image-classification-0002.params
image-classification-0003.params
image-classification-0004.params
image-classification-0005.params
image-classification-symbol.json
model-shapes.json

Would anyone know how to run this locally with Python, or be able to point me to a resource that could help? I am trying to avoid calling the model using the Amazon API.

Edit: The model I used was created with code very similar to this example.

Any help is appreciated, I will award the bounty to whoever is most helpful, even if they don't completely solve the question.


Answer:

This is not a complete answer as I do not have SageMaker setup (And I do not know MXNet) and so I can not practically test this approach (yes, as already mentioned, I do not want to call this a complete answer rather a probable pointer/approach to solve this issue).

The Assumption -

You mentioned a that your model is very similar to the notebook link you provided. If you read the text in the notebook carefully, you will see at some point there is something like this -

"In this demo, we are using Caltech-256 dataset, which contains 30608 images of 256 objects. For the training and validation data, we follow the splitting scheme in this MXNet example."

See the mention of MXNet there? Let us assume that you did not change a lot and hence your model is built using MXNet as well.

The Approach -

Assuming what I just mentioned, if you go and search in the documentation of AWS SageMaker Python SDK you will see a section about serialization of the modules. Which again, by itself, starts with another assumption -

"If you train function returns a Module object, it will be serialized by the default Module serialization system, unless you've specified a custom save function."

Assuming that this is True for your case, further reading in the same document tells us that "model-shapes.json" is a JSON serialised representation of your models, "model-symbol.json" is the serialization of the module symbols created by calling the 'save' function on the 'symbol' property of module, and finally "module.params" is the serialized (I am not sure if it is text or binary format) form of the module parameters.

Equipped with this knowledge we go and look into the documentation of MXNet. And Voila! We see here how we can save and load models with MXNet. So as you already have those saved files, you just need to load them in a local installation of MXNet and then run them to predict the unknown.

I hope this will help you to find a direction to solve your problem.

Bonus -

I am not sure if this also can do the same job, (it is also mentioned by @Seth Rothschild in the comments) but it should, you can see that AWS SageMaker Python SDK has a way to load models from saved ones as well.

Question:

After I've trained and deployed the model with AWS SageMaker, I want to evaluate it on several csv files:

- category-1-eval.csv (~700000 records)
- category-2-eval.csv (~500000 records)
- category-3-eval.csv (~800000 records)
...

The right way to do this is with using Estimator.evaluate() method, as it is fast.

The problem is - I cannot find the way to restore SageMaker model into Tensorflow Estimator, is it possible?

I've tried to restore a model like this:

tf.estimator.DNNClassifier(
    feature_columns=...,
    hidden_units=[...],
    model_dir="s3://<bucket_name>/checkpoints",
)

In AWS SageMaker documentation a different approach is described - to test the actual endpoint from the Notebook - but it takes to much time and requires a lot of API calls to the endpoint.


Answer:

if you used the built-in Tensorflow container, your model has been saved in Tensorflow Serving format, e.g.:

$ tar tfz model.tar.gz
model/
model/1/
model/1/saved_model.pb
model/1/variables/
model/1/variables/variables.index
model/1/variables/variables.data-00000-of-00001

You can easily load it with Tensorflow Serving on your local machine, and send it samples to predict. More info at https://www.tensorflow.org/tfx/guide/serving