在Django内部导入Keras导致崩溃 [英] Importing Keras inside of Django causes it to crash

查看:77
本文介绍了在Django内部导入Keras导致崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为自己制作的计算机视觉应用创建了RESTful API.

I've created a RESTful API for a computer vision app I've made.

使用现有的SVM和以前的NOLearn神经网络可以很好地工作.

It works fine using the existing SVM and previously NOLearn Neural Network.

但是,我已经使用Keras(Theano后端)训练了一个新的CNN,并且每当我在一个py模块中导入Keras时,它就会崩溃.

However, I've trained a new CNN using Keras (Theano backend) and whenever I import Keras inside one of my py modules, it crashes.

import keras

我还尝试将其导入views.py文件中,并且它也崩溃了.

I also tried importing it into the views.py file and it also crashes.

这很奇怪,似乎与Django有直接关系.在计算机上运行python并执行import keras根本没有发现问题.

This is weird and it seems directly related to something with Django. Running python on the machine and doing import keras reveals no issue at all.

这是怎么回事?

推荐答案

当我从Django Web后端调用model_load函数时,出现了此错误. 在websever后端中使用tensorflow时,我们必须创建一个Session! 我通过添加来解决此问题:

I came into this error when I call model_load function from django web backend. we must create a Session when we use tensorflow in the websever backend! I fix this by add:

将tensorflow导入为tf

import tensorflow as tf

与tf.Session():

with tf.Session():

 //my code to call the Keras unit

这可能会对您有所帮助. https://www.tensorflow.org/versions/r0. 11/api_docs/python/client/session_management

this may help you. https://www.tensorflow.org/versions/r0.11/api_docs/python/client/session_management

这篇关于在Django内部导入Keras导致崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆