Skip to content

Commit 3099668

Browse files
Workable model done
1 parent e180dc5 commit 3099668

File tree

11 files changed

+107
-7
lines changed

11 files changed

+107
-7
lines changed
396 Bytes
Binary file not shown.
48 Bytes
Binary file not shown.
1.07 KB
Binary file not shown.

image/form.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from django import forms
2+
3+
class ImageUploadingForm(forms.Form):
4+
image = forms.ImageField()
5+

image/models.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

image/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33

44
urlpatterns = [
55
path('', views.home, name="home"),
6+
path('result', views.imageProcess, name="identify")
67
]

image/views.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,46 @@
11
from django.shortcuts import render
2+
from .form import ImageUploadingForm
23

4+
# Model Dependencies
5+
from tensorflow.keras.applications.resnet50 import ResNet50
6+
from tensorflow.keras.preprocessing import image
7+
from tensorflow.keras.applications.resnet50 import preprocess_input, decode_predictions
8+
import numpy as np
39

4-
# Create your views here.
10+
# binary image
11+
def handle_upload(file):
12+
with open('img.jpg','wb+') as save_image:
13+
for chuck in file.chunks():
14+
save_image.write(chuck)
515

616
# render image upload page
717
def home(request):
818
# return HttpResponse("Hello World")
9-
return render(request, 'image-process/input.html')
19+
return render(request, 'image-process/input.html')
20+
21+
def imageProcess(request):
22+
form = ImageUploadingForm(request.POST, request.FILES)
23+
if form.is_valid():
24+
handle_upload(request.FILES['image'])
25+
26+
# if image valid, create model
27+
model = ResNet50(weights='imagenet')
28+
29+
img_path = 'img.jpg'
30+
31+
# predicting image
32+
img = image.load_img(img_path, target_size=(224, 224))
33+
x = image.img_to_array(img)
34+
x = np.expand_dims(x, axis=0)
35+
x = preprocess_input(x)
36+
37+
preds = model.predict(x)
38+
# print('Predicted:', decode_predictions(preds, top=3)[0])
39+
40+
res = []
41+
for result in decode_predictions(preds, top=3)[0]:
42+
res.append((result[1], np.round(result[2]*100, 2)))
43+
44+
# print(res)
45+
46+
return render(request, 'image-process/output.html', {'res':res})

img.jpg

131 KB
Loading

requirements.txt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,41 @@
1+
absl-py==0.10.0
12
asgiref==3.2.10
3+
astunparse==1.6.3
4+
cachetools==4.1.1
5+
certifi==2020.6.20
6+
chardet==3.0.4
27
Django==3.1.2
8+
gast==0.3.3
9+
google-auth==1.22.1
10+
google-auth-oauthlib==0.4.1
11+
google-pasta==0.2.0
12+
grpcio==1.32.0
313
gunicorn==20.0.4
14+
h5py==2.10.0
15+
idna==2.10
16+
Keras==2.4.3
17+
Keras-Preprocessing==1.1.2
18+
Markdown==3.3.1
19+
numpy==1.19.2
20+
oauthlib==3.1.0
21+
opt-einsum==3.3.0
22+
Pillow==8.0.0
23+
protobuf==3.13.0
24+
pyasn1==0.4.8
25+
pyasn1-modules==0.2.8
426
pytz==2020.1
27+
PyYAML==5.3.1
28+
requests==2.24.0
29+
requests-oauthlib==1.3.0
30+
rsa==4.6
31+
scipy==1.5.2
32+
six==1.15.0
533
sqlparse==0.4.1
34+
tensorboard==2.3.0
35+
tensorboard-plugin-wit==1.7.0
36+
tensorflow==2.3.1
37+
tensorflow-estimator==2.3.0
38+
termcolor==1.1.0
39+
urllib3==1.25.10
40+
Werkzeug==1.0.1
41+
wrapt==1.12.1

templates/image-process/input.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
{% extends 'base.html' %}
22
{% block content %}
3-
<form style="margin: auto; width: 70rem; max-width: 95%; padding: 5%;" class="col s12 z-depth-4">
3+
<form action="{% url 'identify' %}" method="POST" enctype="multipart/form-data" style="margin: auto; width: 70rem; max-width: 95%; padding: 5%;" class="col s12 z-depth-4">
44
<h3>Upload an image</h3>
5+
{% csrf_token %}
56
<div class="row">
67
<div class="file-field input-field col s6">
78
<div class="btn">
89
<span>Select Image</span>
9-
<input type="file">
10+
<input type="file" id="image" name="image">
1011
</div>
1112
<div class="file-path-wrapper col s6">
1213
<input class="file-path validate" type="text">

0 commit comments

Comments
 (0)