|
|
|
import streamlit as st |
|
from streamlit_option_menu import option_menu |
|
from fastai.vision.all import * |
|
from fastai.learner import load_learner |
|
import pickle |
|
from bird_species import model_info |
|
from bird_species import capture_photo |
|
from bird_species import upload_photo |
|
|
|
|
|
def app(): |
|
|
|
|
|
|
|
st.set_page_config( |
|
page_title="Bird Species Detector (525 Species)", |
|
page_icon="๐๏ธ", |
|
initial_sidebar_state="collapsed" |
|
) |
|
|
|
|
|
|
|
st.markdown("<h1 style='text-align: center;'>๐๏ธBirds Species Detector (525 Species)๐๏ธ</h1>", |
|
unsafe_allow_html=True) |
|
|
|
|
|
|
|
|
|
selected = option_menu(None, ["Upload", "Capture", "Model"], |
|
icons=["cloud upload", "camera", "gear"], |
|
menu_icon="cast", default_index=0, orientation="horizontal") |
|
|
|
|
|
|
|
|
|
model = load_learner(fname="models/birds_learner.pkl") |
|
|
|
with open("models/birds_vocab.pkl", "rb") as f: |
|
vocab = pickle.load(f) |
|
|
|
vocab = sorted(vocab) |
|
|
|
with open("models/freezed_model_summary.pkl", "rb") as f: |
|
freezed_arch_summary = pickle.load(f) |
|
|
|
with open("models/unfreezed_model_summary.pkl", "rb") as f: |
|
unfreezed_arch_summary = pickle.load(f) |
|
|
|
with open("models/birds_model_preprocessing.pkl","rb") as f: |
|
preprocessing_steps = pickle.load(f) |
|
|
|
|
|
|
|
if selected == "Upload": |
|
st.caption("""Our project utilizes FastAI Vision with the ResNet50 architecture to classify |
|
525 bird species. Our dataset comprises 84,635 training images, 2,625 test images and 2,625 validation |
|
images, all standardized to 224x224x3 pixels. Initial training yields 96.6% accuracy, improved to 98% post |
|
fine-tuning. Despite gender imbalances, it's a valuable resource for accurate bird species classification.""") |
|
|
|
upload_photo(model=model, vocab=vocab, key="upload photo") |
|
|
|
|
|
|
|
st.markdown("### `Other Projects`") |
|
|
|
st.link_button(label="**Cat and Dog's Breed Detector**", url="https://subrata-mondal-cat-and-dog-breed-detector.streamlit.app/") |
|
st.divider() |
|
|
|
|
|
|
|
if selected == "Capture": |
|
capture_photo(model=model, vocab=None, key="capture photo") |
|
|
|
if selected == "Model": |
|
model_info() |
|
st.subheader("Preprocessing Steps") |
|
st.code(preprocessing_steps) |
|
st.subheader("FastAi Model Summary (Freezed)") |
|
st.code(freezed_arch_summary) |
|
st.subheader("FastAi Model Summary (Unfreezed)") |
|
st.code(unfreezed_arch_summary) |
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
app() |
|
|