Spaces:
Sleeping
Sleeping
ibrahim yıldız commited on
Upload 9 files
Browse files- .gitattributes +1 -0
- 1.jpg +3 -0
- 2.jpg +0 -0
- 3.jpg +0 -0
- 4.jpg +0 -0
- 5.jpg +0 -0
- 6.jpg +0 -0
- app.py +86 -0
- dog_model.h5 +3 -0
- requirements.txt +4 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
1.jpg filter=lfs diff=lfs merge=lfs -text
|
1.jpg
ADDED
|
Git LFS Details
|
2.jpg
ADDED
|
3.jpg
ADDED
|
4.jpg
ADDED
|
5.jpg
ADDED
|
6.jpg
ADDED
|
app.py
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import numpy as np
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import cv2
|
| 5 |
+
from tensorflow.keras.models import load_model
|
| 6 |
+
|
| 7 |
+
# Load the trained model
|
| 8 |
+
model = load_model('dog_model.h5')
|
| 9 |
+
|
| 10 |
+
# List of breeds
|
| 11 |
+
breeds = [
|
| 12 |
+
'affenpinscher', 'afghan_hound', 'african_hunting_dog', 'airedale',
|
| 13 |
+
'american_staffordshire_terrier', 'appenzeller', 'australian_terrier',
|
| 14 |
+
'basenji', 'basset', 'beagle', 'bedlington_terrier', 'bernese_mountain_dog',
|
| 15 |
+
'black-and-tan_coonhound', 'blenheim_spaniel', 'bloodhound', 'bluetick',
|
| 16 |
+
'border_collie', 'border_terrier', 'borzoi', 'boston_bull', 'bouvier_des_flandres',
|
| 17 |
+
'boxer', 'brabancon_griffon', 'briard', 'brittany_spaniel', 'bull_mastiff',
|
| 18 |
+
'cairn', 'cardigan', 'chesapeake_bay_retriever', 'chihuahua', 'chow',
|
| 19 |
+
'clumber', 'cocker_spaniel', 'collie', 'curly-coated_retriever', 'dandie_dinmont',
|
| 20 |
+
'dhole', 'dingo', 'doberman', 'english_foxhound', 'english_setter',
|
| 21 |
+
'english_springer', 'entlebucher', 'eskimo_dog', 'flat-coated_retriever',
|
| 22 |
+
'french_bulldog', 'german_shepherd', 'german_short-haired_pointer',
|
| 23 |
+
'giant_schnauzer', 'golden_retriever', 'gordon_setter', 'great_dane',
|
| 24 |
+
'great_pyrenees', 'greater_swiss_mountain_dog', 'groenendael', 'ibizan_hound',
|
| 25 |
+
'irish_setter', 'irish_terrier', 'irish_water_spaniel', 'irish_wolfhound',
|
| 26 |
+
'italian_greyhound', 'japanese_spaniel', 'keeshond', 'kelpie',
|
| 27 |
+
'kerry_blue_terrier', 'komondor', 'kuvasz', 'labrador_retriever',
|
| 28 |
+
'lakeland_terrier', 'leonberg', 'lhasa', 'malamute', 'malinois', 'maltese_dog',
|
| 29 |
+
'mexican_hairless', 'miniature_pinscher', 'miniature_poodle',
|
| 30 |
+
'miniature_schnauzer', 'newfoundland', 'norfolk_terrier', 'norwegian_elkhound',
|
| 31 |
+
'norwich_terrier', 'old_english_sheepdog', 'otterhound', 'papillon', 'pekinese',
|
| 32 |
+
'pembroke', 'pomeranian', 'pug', 'redbone', 'rhodesian_ridgeback', 'rottweiler',
|
| 33 |
+
'saint_bernard', 'saluki', 'samoyed', 'schipperke', 'scotch_terrier',
|
| 34 |
+
'scottish_deerhound', 'sealyham_terrier', 'shetland_sheepdog', 'shih-tzu',
|
| 35 |
+
'siberian_husky', 'silky_terrier', 'soft-coated_wheaten_terrier',
|
| 36 |
+
'staffordshire_bullterrier', 'standard_poodle', 'standard_schnauzer',
|
| 37 |
+
'sussex_spaniel', 'tibetan_mastiff', 'tibetan_terrier', 'toy_poodle', 'toy_terrier',
|
| 38 |
+
'vizsla', 'walker_hound', 'weimaraner', 'welsh_springer_spaniel',
|
| 39 |
+
'west_highland_white_terrier', 'whippet', 'wire-haired_fox_terrier', 'yorkshire_terrier'
|
| 40 |
+
]
|
| 41 |
+
|
| 42 |
+
# Streamlit app
|
| 43 |
+
st.title("Dog Breed Classifier 🐶")
|
| 44 |
+
images = ["1.jpg", "2.jpg", "3.jpg", "4.jpg", "5.jpg", "6.jpg"]
|
| 45 |
+
current_row = 0
|
| 46 |
+
for _ in range(2):
|
| 47 |
+
cols = st.columns(3)
|
| 48 |
+
for col, image in zip(cols, images[current_row:current_row+3]):
|
| 49 |
+
col.image(image)
|
| 50 |
+
current_row += 3
|
| 51 |
+
|
| 52 |
+
st.write("This model is traned on 120 different breeds of dogs using VGG16. Upload an image of a dog to classify its breed. You can use these sample images.")
|
| 53 |
+
|
| 54 |
+
# File uploader
|
| 55 |
+
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
| 56 |
+
|
| 57 |
+
def preprocess_image(image, image_size=(224, 224)):
|
| 58 |
+
image = cv2.resize(image, image_size)
|
| 59 |
+
image = image / 255.0
|
| 60 |
+
return image
|
| 61 |
+
|
| 62 |
+
if uploaded_file is not None:
|
| 63 |
+
# Read the uploaded image
|
| 64 |
+
file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
|
| 65 |
+
img = cv2.imdecode(file_bytes, 1)
|
| 66 |
+
|
| 67 |
+
# Convert BGR image to RGB
|
| 68 |
+
img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
| 69 |
+
|
| 70 |
+
# Display the uploaded image
|
| 71 |
+
st.image(img_rgb, caption='Uploaded Image.', use_column_width=True)
|
| 72 |
+
|
| 73 |
+
# Preprocess the image
|
| 74 |
+
img_processed = preprocess_image(img)
|
| 75 |
+
img_processed = np.expand_dims(img_processed, axis=0)
|
| 76 |
+
|
| 77 |
+
# Predict the breed
|
| 78 |
+
prediction = model.predict(img_processed)
|
| 79 |
+
predicted_breed = breeds[np.argmax(prediction)]
|
| 80 |
+
|
| 81 |
+
# Display probabilities for top 3 breeds
|
| 82 |
+
top_3_indices = prediction[0].argsort()[-3:][::-1]
|
| 83 |
+
top_3_breeds = [(breeds[i], prediction[0][i]) for i in top_3_indices]
|
| 84 |
+
st.write("Top 3 predicted breeds:")
|
| 85 |
+
for breed, prob in top_3_breeds:
|
| 86 |
+
st.header(f"{breed}: {prob:.4f}%")
|
dog_model.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5ec494ed3f0e82c7ad1628a4cf29cc7c53315ca741e20e925b531964b7630cbc
|
| 3 |
+
size 213836432
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
tensorflow
|
| 2 |
+
numpy
|
| 3 |
+
pandas
|
| 4 |
+
opencv-python
|