Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Landmark Detection from images #906

Closed
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
372 changes: 372 additions & 0 deletions Landmark Detection/Model/landmark-detection-tfhub.ipynb

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Landmark Detection/Web app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Landmark-Detection
Landmark Detection detects popular natural and human-made structures within an image.
43 changes: 43 additions & 0 deletions Landmark Detection/Web app/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import streamlit as st
from PIL import Image

import numpy as np
import pandas as pd
import tensorflow as tf
import tensorflow_hub as hub # type: ignore

# Load the model
TF_MODEL_URL = 'https://tfhub.dev/google/on_device_vision/classifier/landmarks_classifier_asia_V1/1'
IMAGE_SHAPE = (321, 321)

classifier = tf.keras.Sequential([
tf.keras.layers.InputLayer(shape=IMAGE_SHAPE+(3,)),
tf.keras.layers.Lambda(lambda x: hub.KerasLayer(TF_MODEL_URL, output_key='predictions:logits')(x))
])

# Load the label map
LABEL_MAP_URL = 'https://www.gstatic.com/aihub/tfhub/labelmaps/landmarks_classifier_asia_V1_label_map.csv'
df = pd.read_csv(LABEL_MAP_URL)
label_map = dict(zip(df.id, df.name))

# Define the prediction function
def classify_image(image):
img = np.array(image)/255.0
img = img[np.newaxis, ...]
prediction = classifier.predict(img)
return label_map[np.argmax(prediction)]

# Streamlit app
st.title("Landmark Detection Web App")

uploaded_file = st.file_uploader("Choose an image...", type="jpeg")

if uploaded_file is not None:
st.success("Image uploaded successfully!")
image = Image.open(uploaded_file).resize(IMAGE_SHAPE)
st.image(image, caption='Uploaded Image.', use_column_width=True)

if st.button("Classify Image"):
with st.spinner('Classifying...'):
label = classify_image(image)
st.success(f"Prediction: {label}")
Binary file added Landmark Detection/images/image1.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Landmark Detection/images/image2.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Landmark Detection/images/image3.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Landmark Detection/images/image4.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Landmark Detection/images/image5.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions Landmark Detection/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
streamlit
Pillow
numpy
pandas
tensorflow
tensorflow-hub