Spaces:
Sleeping
Sleeping
Upload model.py
Browse files
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"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
|