Spaces:
Runtime error
Runtime error
NORLIE JHON MALAGDAO
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -82,48 +82,54 @@ val_ds = tf.keras.preprocessing.image_dataset_from_directory(
|
|
82 |
class_names = train_ds.class_names
|
83 |
print(class_names)
|
84 |
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
plt.axis("off")
|
92 |
-
|
93 |
-
# Define data augmentation
|
94 |
-
data_augmentation = keras.Sequential([
|
95 |
-
layers.RandomFlip("horizontal", input_shape=(img_height, img_width, 3)),
|
96 |
layers.RandomRotation(0.1),
|
97 |
layers.RandomZoom(0.1),
|
98 |
-
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
|
100 |
-
num_classes = 12
|
101 |
|
|
|
102 |
model = Sequential([
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
])
|
116 |
|
117 |
-
|
118 |
model.compile(optimizer='adam',
|
119 |
loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
|
120 |
metrics=['accuracy'])
|
121 |
|
|
|
|
|
|
|
122 |
epochs = 15
|
123 |
history = model.fit(
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
)
|
128 |
|
129 |
def predict_image(img):
|
|
|
82 |
class_names = train_ds.class_names
|
83 |
print(class_names)
|
84 |
|
85 |
+
data_augmentation = keras.Sequential(
|
86 |
+
[
|
87 |
+
layers.RandomFlip("horizontal",
|
88 |
+
input_shape=(img_height,
|
89 |
+
img_width,
|
90 |
+
3)),
|
|
|
|
|
|
|
|
|
|
|
91 |
layers.RandomRotation(0.1),
|
92 |
layers.RandomZoom(0.1),
|
93 |
+
]
|
94 |
+
)
|
95 |
+
|
96 |
+
plt.figure(figsize=(10, 10))
|
97 |
+
for images, _ in train_ds.take(1):
|
98 |
+
for i in range(9):
|
99 |
+
augmented_images = data_augmentation(images)
|
100 |
+
ax = plt.subplot(3, 3, i + 1)
|
101 |
+
plt.imshow(augmented_images[0].numpy().astype("uint8"))
|
102 |
+
plt.axis("off")
|
103 |
|
|
|
104 |
|
105 |
+
num_classes = len(class_names)
|
106 |
model = Sequential([
|
107 |
+
data_augmentation,
|
108 |
+
layers.Rescaling(1./255),
|
109 |
+
layers.Conv2D(16, 3, padding='same', activation='relu'),
|
110 |
+
layers.MaxPooling2D(),
|
111 |
+
layers.Conv2D(32, 3, padding='same', activation='relu'),
|
112 |
+
layers.MaxPooling2D(),
|
113 |
+
layers.Conv2D(64, 3, padding='same', activation='relu'),
|
114 |
+
layers.MaxPooling2D(),
|
115 |
+
layers.Dropout(0.2),
|
116 |
+
layers.Flatten(),
|
117 |
+
layers.Dense(128, activation='relu'),
|
118 |
+
layers.Dense(num_classes, name="outputs")
|
119 |
])
|
120 |
|
|
|
121 |
model.compile(optimizer='adam',
|
122 |
loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
|
123 |
metrics=['accuracy'])
|
124 |
|
125 |
+
model.summary()
|
126 |
+
|
127 |
+
|
128 |
epochs = 15
|
129 |
history = model.fit(
|
130 |
+
train_ds,
|
131 |
+
validation_data=val_ds,
|
132 |
+
epochs=epochs
|
133 |
)
|
134 |
|
135 |
def predict_image(img):
|