Spaces:
Sleeping
Sleeping
initial commit
Browse files- cifar10_model.h5 +3 -0
- main.py +45 -0
- requirments.txt +6 -0
cifar10_model.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0b85226c770950248e809ff1f6ee1bbe4167ba35ec05886ff63d1d0230b180a2
|
| 3 |
+
size 2053808
|
main.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
import cv2
|
| 4 |
+
from PIL import Image, ImageOps
|
| 5 |
+
import numpy as np
|
| 6 |
+
|
| 7 |
+
# st.set_option("deprecation.showfileUploaderEncoding", False)
|
| 8 |
+
@st.cache(allow_output_mutation=True)
|
| 9 |
+
|
| 10 |
+
def load_model():
|
| 11 |
+
model = tf.keras.models.load_model("F:/igebra/internship/ai ready/machine learning/image_classification_cnn/cifar10_model.h5")
|
| 12 |
+
return model
|
| 13 |
+
|
| 14 |
+
model = load_model()
|
| 15 |
+
|
| 16 |
+
st.title("CIFAR-10 Image Classification")
|
| 17 |
+
uploaded_file = st.file_uploader("Upload an image", type=["png", "jpg", "jpeg"])
|
| 18 |
+
|
| 19 |
+
import cv2
|
| 20 |
+
import numpy as np
|
| 21 |
+
|
| 22 |
+
def import_and_predict(image_data, model):
|
| 23 |
+
size = (32, 32)
|
| 24 |
+
image = np.array(image_data)
|
| 25 |
+
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) if len(image.shape) > 2 else cv2.cvtColor(image, cv2.COLOR_GRAY2RGB)
|
| 26 |
+
image = cv2.resize(image, size, interpolation=cv2.INTER_AREA)
|
| 27 |
+
image = image / 255.0
|
| 28 |
+
img_reshape = np.expand_dims(image, axis=0)
|
| 29 |
+
prediction = model.predict(img_reshape)
|
| 30 |
+
return prediction
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
if uploaded_file is None:
|
| 34 |
+
st.text("Please upload an image file")
|
| 35 |
+
else:
|
| 36 |
+
image = Image.open(uploaded_file)
|
| 37 |
+
st.image(image, use_column_width=True)
|
| 38 |
+
predictions = import_and_predict(image, model)
|
| 39 |
+
print(predictions)
|
| 40 |
+
print(np.argmax(predictions))
|
| 41 |
+
classes = ["airplane", "automobile", "bird", "cat", "deer", "dog", "frog", "horse", "ship", "truck"]
|
| 42 |
+
print(classes[np.argmax(predictions)])
|
| 43 |
+
string = ("This image is most likely is :")
|
| 44 |
+
st.success(f"This image most likely contains: {classes[np.argmax(predictions)]}")
|
| 45 |
+
|
requirments.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
tensorflow
|
| 3 |
+
cv2
|
| 4 |
+
PIL
|
| 5 |
+
numpy
|
| 6 |
+
matplotlib
|