Spaces:
Runtime error
Runtime error
NORLIE JHON MALAGDAO
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -6,7 +6,6 @@ import tensorflow as tf
|
|
6 |
from tensorflow import keras
|
7 |
from tensorflow.keras import layers
|
8 |
from tensorflow.keras.models import Sequential
|
9 |
-
from PIL import Image
|
10 |
import matplotlib.pyplot as plt
|
11 |
import gradio as gr
|
12 |
import numpy as np
|
@@ -105,37 +104,42 @@ for images, _ in train_ds.take(1):
|
|
105 |
plt.imshow(augmented_images[0].numpy().astype("uint8"))
|
106 |
plt.axis("off")
|
107 |
|
108 |
-
# Define a deeper CNN model with
|
109 |
num_classes = len(class_names)
|
110 |
-
model = Sequential(
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
model.
|
|
|
|
|
|
|
|
|
|
|
139 |
loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=False),
|
140 |
metrics=['accuracy'])
|
141 |
|
@@ -197,7 +201,6 @@ body {
|
|
197 |
}
|
198 |
"""
|
199 |
|
200 |
-
|
201 |
gr.Interface(
|
202 |
fn=predict_image,
|
203 |
inputs=image,
|
|
|
6 |
from tensorflow import keras
|
7 |
from tensorflow.keras import layers
|
8 |
from tensorflow.keras.models import Sequential
|
|
|
9 |
import matplotlib.pyplot as plt
|
10 |
import gradio as gr
|
11 |
import numpy as np
|
|
|
104 |
plt.imshow(augmented_images[0].numpy().astype("uint8"))
|
105 |
plt.axis("off")
|
106 |
|
107 |
+
# Define a deeper CNN model with more regularization techniques
|
108 |
num_classes = len(class_names)
|
109 |
+
model = Sequential()
|
110 |
+
|
111 |
+
model.add(data_augmentation)
|
112 |
+
model.add(layers.Rescaling(1./255))
|
113 |
+
|
114 |
+
model.add(layers.Conv2D(32, 3, padding='same', activation='relu', kernel_regularizer=keras.regularizers.l2(0.001)))
|
115 |
+
model.add(layers.BatchNormalization())
|
116 |
+
model.add(layers.MaxPooling2D())
|
117 |
+
|
118 |
+
model.add(layers.Conv2D(64, 3, padding='same', activation='relu', kernel_regularizer=keras.regularizers.l2(0.001)))
|
119 |
+
model.add(layers.BatchNormalization())
|
120 |
+
model.add(layers.MaxPooling2D())
|
121 |
+
|
122 |
+
model.add(layers.Conv2D(128, 3, padding='same', activation='relu', kernel_regularizer=keras.regularizers.l2(0.001)))
|
123 |
+
model.add(layers.BatchNormalization())
|
124 |
+
model.add(layers.MaxPooling2D())
|
125 |
+
|
126 |
+
model.add(layers.Conv2D(256, 3, padding='same', activation='relu', kernel_regularizer=keras.regularizers.l2(0.001)))
|
127 |
+
model.add(layers.BatchNormalization())
|
128 |
+
model.add(layers.MaxPooling2D())
|
129 |
+
|
130 |
+
model.add(layers.Conv2D(512, 3, padding='same', activation='relu', kernel_regularizer=keras.regularizers.l2(0.001)))
|
131 |
+
model.add(layers.BatchNormalization())
|
132 |
+
model.add(layers.MaxPooling2D())
|
133 |
+
|
134 |
+
model.add(layers.Dropout(0.5))
|
135 |
+
model.add(layers.Flatten())
|
136 |
+
|
137 |
+
model.add(layers.Dense(256, activation='relu', kernel_regularizer=keras.regularizers.l2(0.001)))
|
138 |
+
model.add(layers.Dropout(0.5))
|
139 |
+
|
140 |
+
model.add(layers.Dense(num_classes, activation='softmax', name="outputs"))
|
141 |
+
|
142 |
+
model.compile(optimizer=keras.optimizers.Adam(learning_rate=1e-4),
|
143 |
loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=False),
|
144 |
metrics=['accuracy'])
|
145 |
|
|
|
201 |
}
|
202 |
"""
|
203 |
|
|
|
204 |
gr.Interface(
|
205 |
fn=predict_image,
|
206 |
inputs=image,
|