anindya-hf-2002
commited on
Commit
•
069e071
1
Parent(s):
32b6113
Upload 3 files
Browse files- DenseNet121v2_95.h5 +3 -0
- app.py +20 -0
- model.py +20 -0
DenseNet121v2_95.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:0a90907a1a27a8d477f847702ec685b468f02037d9fc15d9bd6d384696983610
|
3 |
+
size 29765928
|
app.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
import cv2
|
4 |
+
from model import classify_image
|
5 |
+
|
6 |
+
def main(img):
|
7 |
+
img = cv2.resize(img, (224,224))
|
8 |
+
img = img/255.0
|
9 |
+
img = np.expand_dims(img, axis=0)
|
10 |
+
label, accuracy = classify_image(img)
|
11 |
+
print(label)
|
12 |
+
out = {label: accuracy}
|
13 |
+
return out
|
14 |
+
|
15 |
+
demo = gr.Interface(fn=main,
|
16 |
+
inputs=gr.Image(),
|
17 |
+
outputs=gr.Label(num_top_classes=1), allow_flagging='never')
|
18 |
+
|
19 |
+
if __name__ == "__main__":
|
20 |
+
demo.launch(share=True)
|
model.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from keras.models import load_model
|
2 |
+
import numpy as np
|
3 |
+
|
4 |
+
labels = ['Chalky Soil', 'Mary Soil', 'Sand', 'Slit SOil', 'Alluvial Soil', 'Black Soil', 'Clay Soil', 'Red Soil']
|
5 |
+
MODEL_PATH = r"D:\Official\Reseach Projects\Official Project\soil-type-classification\models\DenseNet121v2_95.h5"
|
6 |
+
|
7 |
+
def load_CNN_model():
|
8 |
+
model = load_model(MODEL_PATH)
|
9 |
+
print("model loaded")
|
10 |
+
return model
|
11 |
+
|
12 |
+
def classify_image(img):
|
13 |
+
model = load_CNN_model()
|
14 |
+
prediction = model.predict(img)
|
15 |
+
predicted_class = np.argmax(prediction)
|
16 |
+
|
17 |
+
predicted_label = labels[predicted_class]
|
18 |
+
accuracy = prediction[0][predicted_class]
|
19 |
+
|
20 |
+
return predicted_label, accuracy
|