首页 > 解决方案 > Django 应用程序,Django 表单

问题描述

我正在创建一个图像分类器应用程序。我是 Django 新手,我想做的是通过 Django 表单从用户那里获取输入图像并运行后端代码进行分类。成功提交表单后,我重定向到同一个表单的页面。同样,如果我输入另一个/相同的图像,tensorflow 会抛出错误。只有当我第一次输入图像时,才不会发生错误。请帮忙!

def get_name(request):
    # if this is a POST request we need to process the form data
    if request.method == 'POST':
        # create a form instance and populate it with data from the request:
        form = UploadFileForm(request.POST,request.FILES)
        # check whether it's valid:
        if form.is_valid():
            # process the data in form.cleaned_data as required
            # ...
            # redirect to a new URL:
            handle_uploaded_file(request.FILES['file'])

    # if a GET (or any other method) we'll create a blank form
    else:
        form = UploadFileForm()
    return render(request, 'name.html', {'form': form})



def handle_uploaded_file(f):
    #image_bytes = f.read()
    #image = Image.open(io.BytesIO(image_bytes))
    #image1 = image.resize((224,224))
    #dosom(image1)
    print(f.name)
    dosom(f)

dosom 函数获取输入图像并对其进行分类。抛出的错误是-'无法将 feed_dict 键解释为张量:张量张量(“占位符:0”,形状=(3、3、3、64),dtype=float32)'

标签: djangopython-3.xtensorflow

解决方案


我找到了解决问题的链接。 https://github.com/RasaHQ/rasa_core/issues/80

from keras import backend as K

在您预测结果之后,将 tensorflow 会话清除为

K.clear_session()

推荐阅读