ValueError:Tensor不是此图的元素,当在Sagemaker中使用Gunicorn和Flask和Keras托管模型时


不想吃东西
2024-12-23 03:45:28 (3月前)
  1. 在当地环境中完美地工作,但是当我尝试时


主办
</跨度>


模型
</跨度>
在sagemaker中,它会产生此错误。

ValueError:Tensor Tensor(“dense_1 / BiasAdd:0”,shape =(?,1),dtype = float32)不是此图的元素。

那么我该如何解决这个问题呢?
我用Keras和Dockerized创建了一个时间序列预测器

模型
</跨度>
与AWS文档一起使用Flash和Gunicorn。我正在加载序列化的

模型
</跨度>
用这个代码。

@classmethod
def get_model(cls

2 条回复
  1. 0# 谦逊的毛巾 | 2019-08-31 10-32



    通过在模型加载阶段调用_make_predict_function()方法解决了该问题。




    1. @classmethod
      def get_model(cls):
      if cls.model == None:
      cls.model = load_model(‘/opt/ml/bitcoin_model.h5’)
      cls.model._make_predict_function()
      return cls.model

    2. </code>


    Bug参考:

    https://github.com/keras-team/keras/issues/6462


登录 后才能参与评论