upload 6 file
Browse files- app.py +76 -0
- class_indices.json +33 -0
- dog_breed_classifier.h5 +3 -0
- icon.ico +0 -0
- readme.md +131 -0
- setup.py +0 -0
app.py
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import tkinter as tk
|
2 |
+
from tkinter import filedialog, messagebox
|
3 |
+
from PIL import Image, ImageTk
|
4 |
+
import numpy as np
|
5 |
+
import tensorflow as tf
|
6 |
+
import json
|
7 |
+
import os
|
8 |
+
import sys
|
9 |
+
|
10 |
+
def resource_path(relative_path):
|
11 |
+
"""Get absolute path to resource, works for dev and for PyInstaller."""
|
12 |
+
try:
|
13 |
+
base_path = sys._MEIPASS
|
14 |
+
except Exception:
|
15 |
+
base_path = os.path.abspath(".")
|
16 |
+
return os.path.join(base_path, relative_path)
|
17 |
+
|
18 |
+
try:
|
19 |
+
model = tf.keras.models.load_model(resource_path("dog_breed_classifier.h5"), compile=False)
|
20 |
+
except Exception as e:
|
21 |
+
messagebox.showerror("Model Load Error", f"Could not load model:\n{e}")
|
22 |
+
sys.exit(1)
|
23 |
+
|
24 |
+
try:
|
25 |
+
with open(resource_path("class_indices.json"), "r") as f:
|
26 |
+
class_indices = json.load(f)
|
27 |
+
class_names = {int(v): k for k, v in class_indices.items()}
|
28 |
+
except Exception as e:
|
29 |
+
messagebox.showerror("Class Index Load Error", f"Could not load labels:\n{e}")
|
30 |
+
sys.exit(1)
|
31 |
+
|
32 |
+
def predict_image(image_path):
|
33 |
+
try:
|
34 |
+
img = Image.open(image_path).resize((224, 224)).convert("RGB")
|
35 |
+
img_array = np.array(img) / 255.0
|
36 |
+
img_array = np.expand_dims(img_array, axis=0)
|
37 |
+
predictions = model.predict(img_array)[0]
|
38 |
+
top_idx = np.argmax(predictions)
|
39 |
+
breed = class_names[top_idx]
|
40 |
+
confidence = predictions[top_idx] * 100
|
41 |
+
return breed, confidence
|
42 |
+
except Exception as e:
|
43 |
+
messagebox.showerror("Prediction Error", str(e))
|
44 |
+
return "Error", 0
|
45 |
+
|
46 |
+
def upload_image():
|
47 |
+
file_path = filedialog.askopenfilename(filetypes=[("Image Files", "*.jpg *.png *.jpeg")])
|
48 |
+
if not file_path:
|
49 |
+
return
|
50 |
+
image = Image.open(file_path)
|
51 |
+
image = image.resize((250, 250))
|
52 |
+
img_tk = ImageTk.PhotoImage(image)
|
53 |
+
img_label.configure(image=img_tk)
|
54 |
+
img_label.image = img_tk
|
55 |
+
|
56 |
+
breed, confidence = predict_image(file_path)
|
57 |
+
result_label.config(text=f"Breed: {breed}\nConfidence: {confidence:.2f}%")
|
58 |
+
|
59 |
+
root = tk.Tk()
|
60 |
+
root.title("Dog Breed Detector")
|
61 |
+
root.geometry("400x500")
|
62 |
+
root.configure(bg="white")
|
63 |
+
|
64 |
+
title = tk.Label(root, text="Dog Breed Classification", font=("Arial", 18), bg="white")
|
65 |
+
title.pack(pady=10)
|
66 |
+
|
67 |
+
btn = tk.Button(root, text="Upload Image", command=upload_image, font=("Arial", 12), bg="#4CAF50", fg="white")
|
68 |
+
btn.pack(pady=10)
|
69 |
+
|
70 |
+
img_label = tk.Label(root, bg="white")
|
71 |
+
img_label.pack()
|
72 |
+
|
73 |
+
result_label = tk.Label(root, text="", font=("Arial", 14), bg="white", fg="#333")
|
74 |
+
result_label.pack(pady=20)
|
75 |
+
|
76 |
+
root.mainloop()
|
class_indices.json
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"Akita Inu": 0,
|
3 |
+
"Alaskan Malamute": 1,
|
4 |
+
"Australian Shepherd": 2,
|
5 |
+
"Basset Hound": 3,
|
6 |
+
"Beagle": 4,
|
7 |
+
"Bernese Mountain Dog": 5,
|
8 |
+
"Border Collie": 6,
|
9 |
+
"Boston Terrier": 7,
|
10 |
+
"Boxer": 8,
|
11 |
+
"Bulldog": 9,
|
12 |
+
"Chihuahua": 10,
|
13 |
+
"Cocker Spaniel": 11,
|
14 |
+
"Dachshund": 12,
|
15 |
+
"Doberman Pinscher": 13,
|
16 |
+
"French Bulldog": 14,
|
17 |
+
"German Shepherd": 15,
|
18 |
+
"Golden Retriever": 16,
|
19 |
+
"Great Dane": 17,
|
20 |
+
"Indian pariah": 18,
|
21 |
+
"Labrador Retriever": 19,
|
22 |
+
"Maltese": 20,
|
23 |
+
"Pomeranian": 21,
|
24 |
+
"Poodle": 22,
|
25 |
+
"Pug": 23,
|
26 |
+
"Rottweiler": 24,
|
27 |
+
"Saint Bernard": 25,
|
28 |
+
"Shar pei": 26,
|
29 |
+
"Shih Tzu": 27,
|
30 |
+
"Siberian Husky": 28,
|
31 |
+
"Whippet": 29,
|
32 |
+
"Yorkshire Terrier": 30
|
33 |
+
}
|
dog_breed_classifier.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:de81d8b588600e786a8f23bb76aacc30ffbabc3b92e7b1cd84309c3fa8f8cacf
|
3 |
+
size 11420032
|
icon.ico
ADDED
|
readme.md
ADDED
@@ -0,0 +1,131 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# πΆ Dog Breed Classification Desktop App
|
2 |
+
|
3 |
+
This is a standalone desktop application built using **Tkinter** and **TensorFlow**, capable of identifying dog breeds from images. The app uses a trained `.h5` deep learning model and supports creating `.exe` and `.msi` installers via **cx_Freeze** or **PyInstaller**.
|
4 |
+
|
5 |
+
---
|
6 |
+
|
7 |
+
## π Features
|
8 |
+
|
9 |
+
- β
Offline desktop app (no Python installation required)
|
10 |
+
- πΌοΈ Upload any dog image (JPG, PNG, JPEG)
|
11 |
+
- π Predicts dog breed with confidence score
|
12 |
+
- π Simple folder structure and user-friendly GUI
|
13 |
+
- π οΈ Create `.exe` or `.msi` installers with `cx_Freeze`
|
14 |
+
- β οΈ Error handling for missing models or files
|
15 |
+
|
16 |
+
---
|
17 |
+
|
18 |
+
## π§ Model Info
|
19 |
+
|
20 |
+
- Trained on **31 dog breeds** including:
|
21 |
+
```
|
22 |
+
|
23 |
+
Akita Inu, German Shepherd, Labrador Retriever, Poodle, Pug, Golden Retriever,
|
24 |
+
Siberian Husky, Bulldog, Saint Bernard, Rottweiler, and more.
|
25 |
+
|
26 |
+
```
|
27 |
+
- Input Image Size: **224 x 224**
|
28 |
+
- Format: `dog_breed_classifier.h5` (Keras model)
|
29 |
+
|
30 |
+
---
|
31 |
+
|
32 |
+
## π Folder Structure
|
33 |
+
|
34 |
+
```
|
35 |
+
|
36 |
+
DogBreedApp/
|
37 |
+
β
|
38 |
+
βββ app.py # Main GUI application file
|
39 |
+
βββ dog\_breed\_classifier.h5 # Trained TensorFlow model
|
40 |
+
βββ class\_indices.json # Label-to-classname mapping
|
41 |
+
βββ setup.py # cx\_Freeze build script
|
42 |
+
βββ dog.ico # (optional) Icon file
|
43 |
+
|
44 |
+
````
|
45 |
+
|
46 |
+
---
|
47 |
+
|
48 |
+
## π Requirements
|
49 |
+
|
50 |
+
Install these Python packages:
|
51 |
+
|
52 |
+
```bash
|
53 |
+
pip install -r requirements.txt
|
54 |
+
````
|
55 |
+
|
56 |
+
**requirements.txt**
|
57 |
+
|
58 |
+
```txt
|
59 |
+
tensorflow
|
60 |
+
numpy
|
61 |
+
pillow
|
62 |
+
cx-Freeze
|
63 |
+
```
|
64 |
+
|
65 |
+
---
|
66 |
+
|
67 |
+
## π₯οΈ Running the App
|
68 |
+
|
69 |
+
```bash
|
70 |
+
python app.py
|
71 |
+
```
|
72 |
+
|
73 |
+
---
|
74 |
+
|
75 |
+
## π¦ Creating Executable (.exe or .msi)
|
76 |
+
|
77 |
+
### β
Using cx\_Freeze
|
78 |
+
|
79 |
+
1. Create `setup.py`
|
80 |
+
2. Build:
|
81 |
+
|
82 |
+
```bash
|
83 |
+
python setup.py build
|
84 |
+
```
|
85 |
+
|
86 |
+
3. For MSI Installer:
|
87 |
+
|
88 |
+
```bash
|
89 |
+
python setup.py bdist_msi
|
90 |
+
```
|
91 |
+
|
92 |
+
This generates:
|
93 |
+
|
94 |
+
* `.exe` in `build/`
|
95 |
+
* `.msi` installer in `dist/`
|
96 |
+
|
97 |
+
---
|
98 |
+
|
99 |
+
## π§ Packaging Notes
|
100 |
+
|
101 |
+
* Use `resource_path()` for model/JSON so PyInstaller or cx\_Freeze can bundle files.
|
102 |
+
* Include `.h5` and `.json` in `include_files` in `setup.py`.
|
103 |
+
* Works without requiring Python installation.
|
104 |
+
|
105 |
+
---
|
106 |
+
|
107 |
+
## πΈ Screenshots
|
108 |
+
|
109 |
+

|
110 |
+

|
111 |
+
|
112 |
+
---
|
113 |
+
|
114 |
+
## π License
|
115 |
+
|
116 |
+
This project is open-source and available for educational and personal use.
|
117 |
+
|
118 |
+
---
|
119 |
+
|
120 |
+
## π¨βπ» Author
|
121 |
+
|
122 |
+
Developed by **Jayasimma D**
|
123 |
+
|
124 |
+
```
|
125 |
+
|
126 |
+
---
|
127 |
+
|
128 |
+
### β
Bonus Tips:
|
129 |
+
- Save it as `README.md` in your root folder.
|
130 |
+
- Add screenshots to a `/screenshots` folder if you plan to upload this to GitHub or Share.
|
131 |
+
- Replace `[Your Name]` with your actual name or GitHub username.
|
setup.py
ADDED
File without changes
|