Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import tensorflow as tf
|
2 |
-
from tensorflow
|
3 |
import gradio as gr
|
4 |
import numpy as np
|
5 |
import cv2
|
@@ -7,50 +7,9 @@ import os
|
|
7 |
|
8 |
classes = ["Abyssinian", "Bengal", "Birman", "Bombay", "British Shorthair", "Egyptian Mau", "Maine Coon", "Persian", "Ragdoll", "Russian Blue", "Siamese", "Sphynx"]
|
9 |
example_images = ["examples/" + f for f in os.listdir("examples")]
|
10 |
-
|
11 |
img_size = 400
|
12 |
-
num_classes = 12
|
13 |
-
|
14 |
-
# Create CNN model architecture and apply weights from file
|
15 |
-
def create_model():
|
16 |
-
model = models.Sequential()
|
17 |
-
model.add(layers.RandomFlip("horizontal_and_vertical"))
|
18 |
-
model.add(layers.RandomRotation(0.2))
|
19 |
-
model.add(layers.RandomZoom((0, 0.2)))
|
20 |
-
model.add(layers.Rescaling(1./255))
|
21 |
-
|
22 |
-
model.add(layers.Conv2D(8, 3, activation="relu"))
|
23 |
-
model.add(layers.BatchNormalization())
|
24 |
-
model.add(layers.MaxPooling2D())
|
25 |
-
|
26 |
-
model.add(layers.Conv2D(16, 3, activation="relu"))
|
27 |
-
model.add(layers.BatchNormalization())
|
28 |
-
model.add(layers.MaxPooling2D())
|
29 |
-
|
30 |
-
model.add(layers.Conv2D(32, 3, activation="relu"))
|
31 |
-
model.add(layers.BatchNormalization())
|
32 |
-
model.add(layers.MaxPooling2D())
|
33 |
-
|
34 |
-
model.add(layers.Conv2D(64, 3, activation="relu"))
|
35 |
-
model.add(layers.BatchNormalization())
|
36 |
-
model.add(layers.MaxPooling2D())
|
37 |
-
|
38 |
-
model.add(layers.Conv2D(92, 3, activation="relu"))
|
39 |
-
model.add(layers.BatchNormalization())
|
40 |
-
model.add(layers.MaxPooling2D())
|
41 |
-
|
42 |
-
model.add(layers.BatchNormalization())
|
43 |
-
|
44 |
-
model.add(layers.Flatten())
|
45 |
-
|
46 |
-
model.add(layers.Dense(1024, activation="relu"))
|
47 |
-
model.add(layers.Dropout(0.5))
|
48 |
-
model.add(layers.Dense(512, activation="relu"))
|
49 |
-
model.add(layers.Dense(num_classes, activation="softmax"))
|
50 |
-
model.load_weights("CatClassifierWeights.h5")
|
51 |
-
return model
|
52 |
|
53 |
-
model =
|
54 |
|
55 |
def model_predict(image):
|
56 |
image = cv2.resize(image, (img_size, img_size))
|
|
|
1 |
import tensorflow as tf
|
2 |
+
from tensorflow import keras
|
3 |
import gradio as gr
|
4 |
import numpy as np
|
5 |
import cv2
|
|
|
7 |
|
8 |
classes = ["Abyssinian", "Bengal", "Birman", "Bombay", "British Shorthair", "Egyptian Mau", "Maine Coon", "Persian", "Ragdoll", "Russian Blue", "Siamese", "Sphynx"]
|
9 |
example_images = ["examples/" + f for f in os.listdir("examples")]
|
|
|
10 |
img_size = 400
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
+
model = tf.keras.models.load_model("CatClassifier")
|
13 |
|
14 |
def model_predict(image):
|
15 |
image = cv2.resize(image, (img_size, img_size))
|