Gluon Sagemaker BYOM - cannot deploy model

I have trained a Gluon CV model locally and now I am trying to deploy it to Sagemaker.
This situation is documented in several places (here and here).

Everywhere, the preliminary step seems to package the model in a format being readable by sagemaker.mxnet.model.MXNetModel, i.e. basically running the following code:

import os
import json

os.mkdir('model')

model.save_checkpoint('model/model', 0000)
with open ( 'model/model-shapes.json', "w") as shapes:
    json.dump([{"shape": model.data_shapes[0][1], "name": "data"}], shapes)

import tarfile

def flatten(tarinfo):
    tarinfo.name = os.path.basename(tarinfo.name)
    return tarinfo
    
tar = tarfile.open("model.tar.gz", "w:gz")
tar.add("model", filter=flatten)
tar.close()

My problem is that the above code does not apply to Gluon.
My model comes from the vision zoo model_zoo.vision.resnet34_v2(pretrained=True), hence it does not possess the required attributes.
Running the above code results in:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-7-b573201434c1> in <module>()
      4 os.mkdir('model')
      5 
----> 6 model.save_checkpoint('model/model', 0000)
      7 with open ( 'model/model-shapes.json', "w") as shapes:
      8     json.dump([{"shape": model.data_shapes[0][1], "name": "data"}], shapes)

AttributeError: 'ResNetV2' object has no attribute 'save_checkpoint'

Any suggestions on how to create a SageMaker model data .tar.gz file from a pretrained model?
Thanks a lot in advance!

@thomelane you are my only hope man :grin:

Hi, does this help?

I could follow all the steps of the tutorial (gluon–> symbol) successfully.

1 Like

Thanks a lot for the reply! I thought about everything but clearly not about the easiest route :wink:
Let me check this out!

1 Like