在Django中运行Keras LSTM模型返回'thread._local'对象没有属性'value'

问题描述 投票:0回答:1

我正在尝试将我的Keras神经网络集成到我的Django应用程序中,否则将无法正常运行。当我运行python manage.py runserver时,我得到'thread._local' object has no attribute 'value'

Views.py:

def index(request):

    form = forms.InputForm()

    args = {'form': form}

    if request.method == "POST":

        print("checking")

        form = forms.InputForm(request.POST)

        if form.is_valid():

            print(classify(str(form.cleaned_data['textInput'])))

    return render(request, 'main_app/UI.html', args)

forms.py:

from django import forms


class InputForm(forms.Form):
    textInput = forms.CharField(widget=forms.TextInput, label='Enter text for analysis ')

    def clean(self):
        all_clean_data = super(InputForm, self).clean()
        textInput = all_clean_data['textInput']

HTML表单代码:

<div class="container">
    <div class="jumbotron">
        <form method="POST">
            {{ form.as_p }}
            {% csrf_token %}
            <input type="submit" class="btn btn-info" value="Click To Analyse">
        </form>
    </div>
</div>

我如何前进?

python django tensorflow keras lstm
1个回答
0
投票

更新-我找到了解决方案。

我解决问题的方法是将keras替换为tf.keras。然后Django接受了函数调用。

© www.soinside.com 2019 - 2024. All rights reserved.