【发布时间】:2021-03-15 09:44:30
【问题描述】:
让我解释一下,这是我的问题: 为了不被数据库打扰,我在 Django 项目的一个文件夹中的 .pickle 中保存了两个机器学习模型。 然后在对应的views.py中我要打开并使用这个模型。 事实是,当我在本地运行服务器时,所有这一切都运行良好,但一旦部署在 heroku 上,就无法访问这些模型并且该站点无法运行。
您有什么想法,是否可以在部署后使用此方法,还是我必须将它们保存在数据库中
项目文件组织:
main_folder >
models_folder >
saved_models_folder >
my_model.pickle (here the model that I want to open)
app_folder >
views.py ( here is the file in which I try to open the .pickle model)
其实我有这段代码,但是我打开它时因为不在models文件夹中,所以无法运行。
def open_model(file_name):
base_dir = 'models_folder\\saved_models_folder'
file_path = os.path.join(base_dir, file_name)
if os.path.exists(file_path):
print("Loading Trained Model")
model = pickle.load(open(file_path, "rb"))
else:
print('No model with this name, check this and retry')
model = None
return model
如果有人有一点想法,我会非常感兴趣。 谢谢。
【问题讨论】: