我正在创建一个图像分类器应用程序。我对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)”。