aws-samples / amazon-sagemaker-tensorflow-object-detection-api

Train and deploy models using TensorFlow 2 with the Object Detection API on Amazon SageMaker
MIT No Attribution
42 stars 34 forks source link

Error while trying to deploy model #10

Closed nfbalbontin closed 3 years ago

nfbalbontin commented 3 years ago

Hi! I've been struggling for a while to deploy the model so then I can make predictions. When running:

predictor = model.deploy(initial_instance_count=1, instance_type='ml.m5.xlarge')

I obtain the following error:
update_endpoint is a no-op in sagemaker>=2. See: https://sagemaker.readthedocs.io/en/stable/v2.html for details.
It still runs the statement. But afterwards, when executing:

def image_file_to_tensor(path):
    cv_img = cv2.imread(path,1).astype('uint8')
    cv_img = cv2.cvtColor(cv_img, cv2.COLOR_BGR2RGB)
    return cv_img

img = image_file_to_tensor('test_images/22673445.jpg')

input = {
  'instances': [img.tolist()]
}

detections = predictor.predict(input)['predictions'][0]

img_with_detections = img.copy()
category_index = {1:{'id': 1, 'name': 'bee'}}
detection_boxes = np.array(detections['detection_boxes'])
detection_classes = [int(x) for x in detections['detection_classes']]
detection_scores = detections['detection_scores']

It shows the following error: ConnectionClosedError: Connection was closed before we received a valid response from endpoint URL: "https://runtime.sagemaker.us-east-1.amazonaws.com/endpoints/tf2-object-detection-2021-03-08-15-34-35-827/invocations".

Are there any ways to fix this problem? I tried fixing the udpate_endpoint but with no luck. Thanks!

sofianhamiti commented 3 years ago

Hi @nfbalbontin,

In the first notebook 1_prepare_data/prepare_data.ipynb we set the SageMaker Python SDK version. Make sure you have ran this command. !pip install -q sagemaker==2.16.2

Can you confirm this solves the issue?

nfbalbontin commented 3 years ago

Hi! Thank you for the quick reply. I added a cell at the beginning of deploy_endpoint.ipynb with the command you mentioned:

!pip install -q sagemaker==2.16.2

Still, it throughs the same error:


update_endpoint is a no-op in sagemaker>=2.
See: https://sagemaker.readthedocs.io/en/stable/v2.html for details.

And after, when I run all the following cells, I get the same error specified before.
After searching for the problem, I found the class sagemaker.predictor.Predictor that can be used for real-time predictions against SageMaker endpoints, but you need to have a deploy made -If I'm correct-. Could it be possible to make the deploy after running creating the model in train_model.ipynb? I tried with no success, but maybe I'm not getting the procedure right.

sofianhamiti commented 3 years ago

Did you restart the notebook kernel after updating the sdk? This should remove the warning.

nfbalbontin commented 3 years ago

Yes, I did. I even try with different kernels for the execution. Thanks again for the quick answer.

nfbalbontin commented 3 years ago

At the end it wasn't a problem related to the version. Thanks anyways!