如何设置TensorFlow在AWS上加载模型?

问题描述

我在加载TensorFlow模型时遇到问题。这在本地(在运行gunicorn --bind ...时)和该服务器上有效。但是,当我转向AWS时,出现以下错误

{ “错误”:“有一个错误,无法打开文件文件读取失败:时间= 2020年8月12日星期三19:02:14 2020 \ n,文件名='/ home / ubuntu / ambdjango / leadmanager / assets / model11',文件描述符= 13,errno = 21,错误消息=“是目录”,buf = 0x7fff3b251850,总读取大小= 8,此子读取的字节= 8,实际读取的字节= 18446744073709551615,偏移量= 0)” }

据我所知,我的本地主机和AWS EC2实例都运行相同版本的TensorFlow(2.3.0),但是当我在EC2实例中键入“哪个TensorFlow”时,没有给出响应,这很奇怪

我的后端代码如下,如果有人有任何想法,将不胜感激。

from tensorflow.keras.models import load_model    
@api_view()
    def model (self):
        try:
            BASE_DIR = Path(__file__).ancestor(2)
            Mmodel_DIr  = os.path.join(BASE_DIR,'assets/model11')
            model = load_model(Mmodel_DIr)
            sp = int(self.GET.get('sp',''))
            ran = float(self.GET.get('ran',''))
            testinverted = 1/sp
            testran = [normran(ran)]
            testinverted = [norminverted(testinverted)]
            dataframetest= pd.DataFrame()
            dataframetest['ran']= testran
            dataframetest['invertedodds']= testinverted
            chance = (model.predict(dataframetest)[0])
            chanceep = 0.04 if chance < 0.04 and sp<10 else float(chance)
            return Response({'chanceep': chanceep})
        except Exception as e:
            return Response({'error': 'there was an error ' + str(e)})

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)