Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

app.py 902 B

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
  1. import streamlit as st
  2. from PIL import Image
  3. import tensorflow as tf
  4. import numpy as np
  5. """
  6. # Deep Classification project.
  7. A Simple classification application that classifies a given image is a Dog or a Cat.
  8. """
  9. model = tf.keras.models.load_model("model.h5")
  10. uploaded_file = st.file_uploader("Choose a file")
  11. if uploaded_file is not None:
  12. # To read file as bytes:
  13. image = Image.open(uploaded_file)
  14. img = image.resize((224,224)) ## Resizing the image becoz it take this size only.
  15. img_array = np.array(img) ## image to numpy array
  16. img_array = np.expand_dims(img_array, axis=0) # [batch_size, row, col, channel]
  17. result = model.predict(img_array) # [[0.99, 0.01], [0.99, 0.01]]
  18. argmax_index = np.argmax(result, axis=1) # [0, 0]
  19. if argmax_index[0] == 0:
  20. st.image(image, caption="predicted: Cat")
  21. else:
  22. st.image(image, caption='predicted: Dog')
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...