我一直在尝试将机器学习模型转换为Web应用程序。即使我的代码可以独立运行。当我调用Django文件中的函数时,它不起作用。
这是我的目录:
├───app │ │ admin.py │ │ apps.py │ │ classify_images.py │ │ forms.py │ │ model.ann │ │ modelnn.py │ │ models.py │ │ tests.py │ │ Untitled.ipynb │ │ urls.py │ │ views.py │ │ __init__.py │ │ │ ├───.ipynb_checkpoints │ │ Untitled-checkpoint.ipynb │ │ │ ├───image_vectors │ ├───img │ │ heat.PNG │ │ pp.jpg │ │ tosbik.jpg │ │ │ ├───migrations │ │ │ 0001_initial.py │ │ │ __init__.py │ │ │ │ │ └───__pycache__ │ │ 0001_initial.cpython-36.pyc │ │ __init__.cpython-36.pyc │ │ │ ├───static │ │ └───app │ │ │ main.css │ │ │ │ │ └───img │ │ logo.png │ │ logo2.png │ │ removed_noise.png │ │ xx_23242A72_xx.jpg.npz │ │ xx_23256H6_xx.jpg.npz │ │ xx_23476B26_xx.jpg.npz │ │ xx_23617A13_xx.jpg.npz │ │ xx_23666A46_xx.jpg.npz │ │ xx_24211O6_xx.jpg.npz │ │ │ ├───templates │ │ └───app │ │ complete.html │ │ index.html │ │ upload.html │ │ upload2.html │ │ │ ├───tmp │ │ └───imagenet │ │ classify_image_graph_def.pb │ │ cropped_panda.jpg │ │ imagenet_2012_challenge_label_map_proto.pbtxt │ │ imagenet_synset_to_human_label_map.txt │ │ inception-2015-12-05.tgz │ │ LICENSE │ │ │ └───__pycache__ │ admin.cpython-36.pyc │ apps.cpython-36.pyc │ classify_images.cpython-36.pyc │ forms.cpython-36.pyc │ modelnn.cpython-36.pyc │ models.cpython-36.pyc │ urls.cpython-36.pyc │ views.cpython-36.pyc │ __init__.cpython-36.pyc │ ├───project │ │ settings.py │ │ urls.py │ │ wsgi.py │ │ __init__.py │ │ │ └───__pycache__ │ settings.cpython-36.pyc │ urls.cpython-36.pyc │ wsgi.cpython-36.pyc │ __init__.cpython-36.pyc │ └───__pycache__ classify_images.cpython-36.pyc model.cpython-36.pyc
那是我的views.py文件:
from django.shortcuts import render
from django.http import HttpResponse
from django.views.generic import CreateView
from .models import Image
from django.urls import reverse_lazy
from .forms import PostForm
from .modelnn import Similarity_Model
from django.core.files.storage import FileSystemStorage
from .classify_images import vectorize
# Create your views here.
def home(request):
return render(request, 'app/index.html')
def upload(request):
if request.method == 'POST':
n_neigh=request.POST['number']
print(n_neigh)
model = Similarity_Model(n_neigh=int(n_neigh))
up_file = request.FILES['document']
fs = FileSystemStorage()
fs.save(up_file.name,up_file)
vectorize(str("img/"+up_file.name),"img/")
return render(request, 'app/upload2.html')
这里的问题是当我通过一些jupyter笔记本在自己的计算机上运行vectorize时 它完美地工作。但是,当我从views.py运行它时,它不会执行任何操作,但是不会输出任何错误。除此之外,它还可以正常工作,它将图像上传到img路径。唯一的问题是矢量化功能。