| import streamlit as st |
| import tensorflow as tf |
| import os |
| import cv2 |
| import PIL |
| from PIL import Image, ImageOps |
| import numpy as np |
| import matplotlib.pyplot as plt |
| import numpy as np |
|
|
| from tensorflow import keras |
| from tensorflow.keras import layers |
| from tensorflow.keras.models import Sequential |
|
|
| from tensorflow.keras.utils import load_img |
| from tensorflow.keras.preprocessing.image import img_to_array |
|
|
| from tensorflow.keras.layers import Dense, Flatten, AveragePooling2D, Dropout |
| from tensorflow.keras.optimizers import Adam |
| from tensorflow.keras.applications.vgg16 import VGG16 |
| from tensorflow.keras.applications.densenet import DenseNet121 |
| from tensorflow.keras.models import Model |
|
|
|
|
| st.title("Corn Maize Classification") |
| st.header("Please input an image to be classified:") |
| |
| |
| uploaded_file = st.file_uploader("Upload an Image", type="jpg") |
|
|
| |
| model = keras.models.load_model("LeafDisease_Corn_Maize-DenseNet121.h5") |
| opt = Adam(learning_rate= 0.0001) |
| model.compile(optimizer=opt, loss= 'categorical_crossentropy', metrics=['accuracy']) |
|
|
|
|
| if uploaded_file is not None: |
| image = Image.open(uploaded_file) |
| st.image(image, caption='Uploaded file', use_column_width=True) |
| st.write("") |
| st.write("Classifying...") |
| |
| |
| data = np.ndarray(shape=(1, 224, 224, 3), dtype=np.float32) |
| size = (224, 224) |
| image = ImageOps.fit(image, size, Image.ANTIALIAS) |
|
|
| |
| image_array = np.asarray(image) |
| |
| normalized_image_array = (image_array.astype(np.float32) / 255) |
|
|
| |
| data[0] = normalized_image_array |
| |
| |
| |
| |
| |
| prediction_percentage = model.predict(data) |
| prediction=prediction_percentage.round() |
| st.write ("Predictions are:", prediction) |
| st.write ("Predictions percentage:", prediction_percentage) |
| |
|
|
|
|
|
|