Django 应用程序,Django 表单。

4

我正在创建一个图像分类器应用程序。我对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键解释为张量:张量Tensor(” Placeholder:0“,shape =(3,3,3,64),dtype = float32)”。

1
你好,欢迎来到Stack Overflow,请展示您的工作证明,包括代码崩溃的位置以及您尝试使用示例图像实现的目标。 - O_o
1
请提供您的代码。 - Ramtin
1个回答

2

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接