Spaces:
Runtime error
Runtime error
Commit
•
43396c2
1
Parent(s):
da7901a
Upload 4 files
Browse files- requirement.txt +3 -0
- saved_model/mdl_wts.hdf5 +3 -0
- saved_model/saved_model.h5 +3 -0
- streamlit_host.py +39 -0
requirement.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
streamlit==0.80.0
|
2 |
+
tensorflow==2.5.0rc1
|
3 |
+
opencv-python==4.5.1.48
|
saved_model/mdl_wts.hdf5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:dd65e0741f782e2d379ecb76740aa665ad480d5742f09f1febdd681c2ef4df67
|
3 |
+
size 25203432
|
saved_model/saved_model.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:09f1568e1d7a9251f9b73130626c1590f6dcdc9eda85fef8d5ff91bd31ce82e2
|
3 |
+
size 8186264
|
streamlit_host.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import cv2
|
2 |
+
import numpy as np
|
3 |
+
import streamlit as st
|
4 |
+
import tensorflow as tf
|
5 |
+
from tensorflow.keras.preprocessing import image
|
6 |
+
from tensorflow.keras.applications.mobilenet_v2 import MobileNetV2,preprocess_input as mobilenet_v2_preprocess_input
|
7 |
+
|
8 |
+
model = tf.keras.models.load_model("saved_model/mdl_wts.hdf5")
|
9 |
+
### load file
|
10 |
+
uploaded_file = st.file_uploader("Choose a image file", type="jpg")
|
11 |
+
|
12 |
+
map_dict = {0: 'dog',
|
13 |
+
1: 'horse',
|
14 |
+
2: 'elephant',
|
15 |
+
3: 'butterfly',
|
16 |
+
4: 'chicken',
|
17 |
+
5: 'cat',
|
18 |
+
6: 'cow',
|
19 |
+
7: 'sheep',
|
20 |
+
8: 'spider',
|
21 |
+
9: 'squirrel'}
|
22 |
+
|
23 |
+
|
24 |
+
if uploaded_file is not None:
|
25 |
+
# Convert the file to an opencv image.
|
26 |
+
file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
|
27 |
+
opencv_image = cv2.imdecode(file_bytes, 1)
|
28 |
+
opencv_image = cv2.cvtColor(opencv_image, cv2.COLOR_BGR2RGB)
|
29 |
+
resized = cv2.resize(opencv_image,(224,224))
|
30 |
+
# Now do something with the image! For example, let's display it:
|
31 |
+
st.image(opencv_image, channels="RGB")
|
32 |
+
|
33 |
+
resized = mobilenet_v2_preprocess_input(resized)
|
34 |
+
img_reshape = resized[np.newaxis,...]
|
35 |
+
|
36 |
+
Genrate_pred = st.button("Generate Prediction")
|
37 |
+
if Genrate_pred:
|
38 |
+
prediction = model.predict(img_reshape).argmax()
|
39 |
+
st.title("Predicted Label for the image is {}".format(map_dict [prediction]))
|