abcdef12356 commited on
Commit
6aa6eed
·
1 Parent(s): 623a994

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ st.markdown('<h1 style="color:black;">Vgg 19 Image classification model</h1>', unsafe_allow_html=True)
2
+ st.markdown('<h2 style="color:gray;">The image classification model classifies image into following categories:</h2>', unsafe_allow_html=True)
3
+ st.markdown('<h3 style="color:gray;"> street, buildings, forest, sea, mountain, glacier</h3>', unsafe_allow_html=True)
4
+
5
+ @st.cache(allow_output_mutation=True)
6
+ def get_base64_of_bin_file(bin_file):
7
+ with open(bin_file, 'rb') as f:
8
+ data = f.read()
9
+ return base64.b64encode(data).decode()
10
+
11
+
12
+ upload= st.file_uploader('Insert image for classification', type=['png','jpg'])
13
+ c1, c2= st.columns(2)
14
+ if upload is not None:
15
+ im= Image.open(upload)
16
+ img= np.asarray(im)
17
+ image= cv2.resize(img,(224, 224))
18
+ img= preprocess_input(image)
19
+ img= np.expand_dims(img, 0)
20
+ c1.header('Input Image')
21
+ c1.image(im)
22
+ c1.write(img.shape)
23
+ input_shape = (224, 224, 3)
24
+ optim_1 = Adam(learning_rate=0.0001)
25
+ n_classes=6
26
+ vgg_model = model(input_shape, n_classes, optim_1, fine_tune=2)
27
+ vgg_model.load_weights('/content/drive/MyDrive/vgg/tune_model19.weights.best.hdf5')
28
+
29
+ # prediction on model
30
+ vgg_preds = vgg_model.predict(img)
31
+ vgg_pred_classes = np.argmax(vgg_preds, axis=1)
32
+ c2.header('Output')
33
+ c2.subheader('Predicted class :')
34
+ c2.write(classes[vgg_pred_classes[0]] )