django - 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)'
解决方案
我找到了解决问题的链接。 https://github.com/RasaHQ/rasa_core/issues/80
from keras import backend as K
在您预测结果之后,将 tensorflow 会话清除为
K.clear_session()
推荐阅读
- javascript - 通过方法更改数组的元素?
- java - 部署到 Nexus 存储库时出现 Gradle 错误
- python - (x*w+x1*w1+...xn*wn+b) 如何检查得到的值是否是(x)和(y)的差
- wpf - 无法在位图中捕获 WPF 实时图表
- numpy - 由于形状错误,乘法在 numpy 中失败
- python - Python 记录链接工具包 - Qgrams 错误
- angular - 使用 Karma 为 angular 指令创建单元测试
- pandas - Pandas 使用字典替换值和值列表
- entity-framework - 将分页功能添加到索引 Razor 页面 ASP.NET Core
- google-chrome - Chrome 开发者控制台在控制台中打印换行符“\n”