我正在创建一个图像分类器应用程序 . 我是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:Tensor Tensor(“Placeholder:0”,shape =(3,3,3,64),dtype = float32)'
1 回答
我找到了解决问题的链接 . https://github.com/RasaHQ/rasa_core/issues/80
在预测结果后,将tensorflow会话清除为