penscola commited on
Commit
81168c1
·
1 Parent(s): d1375ef

Create pp.py

Browse files
Files changed (1) hide show
  1. pp.py +43 -0
pp.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #Library imports
2
+ import numpy as np
3
+ import streamlit as st
4
+ import cv2
5
+ from keras.models import load_model
6
+
7
+
8
+ #Loading the Model
9
+ model = load_model('soils.h5')
10
+
11
+ #Name of Classes
12
+ CLASS_NAMES = ['Acrisols', 'Fluvisols', 'Ferrasols']
13
+
14
+ #Setting Title of App
15
+ st.title("Soils classification")
16
+ st.markdown("Upload an image of the soil")
17
+
18
+ #Uploading the soil image
19
+ soil_image = st.file_uploader("Choose an image...", type="jpg")
20
+ submit = st.button('Predict')
21
+ #On predict button click
22
+ if submit:
23
+
24
+
25
+ if soil_image is not None:
26
+
27
+ # Convert the file to an opencv image.
28
+ file_bytes = np.asarray(bytearray(soil_image.read()), dtype=np.uint8)
29
+ opencv_image = cv2.imdecode(file_bytes, 1)
30
+
31
+
32
+
33
+ # Displaying the image
34
+ st.image(opencv_image, channels="BGR")
35
+ st.write(opencv_image.shape)
36
+ #Resizing the image
37
+ opencv_image = cv2.resize(opencv_image, (256,256))
38
+ #Convert image to 4 Dimension
39
+ opencv_image.shape = (1,256,256,3)
40
+ #Make Prediction
41
+ Y_pred = model.predict(opencv_image)
42
+ result = CLASS_NAMES[np.argmax(Y_pred)]
43
+ st.title(str("This is {}".format(result)))