Spaces:
Runtime error
Runtime error
NORLIE JHON MALAGDAO
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,14 +2,9 @@ import gradio as gr
|
|
| 2 |
import matplotlib.pyplot as plt
|
| 3 |
import numpy as np
|
| 4 |
import os
|
| 5 |
-
import PIL
|
| 6 |
import tensorflow as tf
|
| 7 |
-
|
| 8 |
-
from tensorflow import
|
| 9 |
-
from tensorflow.keras import layers
|
| 10 |
-
from tensorflow.keras.models import Sequential
|
| 11 |
-
|
| 12 |
-
from PIL import Image
|
| 13 |
import gdown
|
| 14 |
import zipfile
|
| 15 |
import pathlib
|
|
@@ -42,20 +37,7 @@ except zipfile.BadZipFile:
|
|
| 42 |
os.remove(local_zip_file)
|
| 43 |
|
| 44 |
# Convert the extracted directory path to a pathlib.Path object
|
| 45 |
-
data_dir = pathlib.Path(extracted_path)
|
| 46 |
-
|
| 47 |
-
# Print the directory structure to debug
|
| 48 |
-
for root, dirs, files in os.walk(extracted_path):
|
| 49 |
-
level = root.replace(extracted_path, '').count(os.sep)
|
| 50 |
-
indent = ' ' * 4 * (level)
|
| 51 |
-
print(f"{indent}{os.path.basename(root)}/")
|
| 52 |
-
subindent = ' ' * 4 * (level + 1)
|
| 53 |
-
for f in files:
|
| 54 |
-
print(f"{subindent}{f}")
|
| 55 |
-
|
| 56 |
-
# Path to the dataset directory
|
| 57 |
-
data_dir = pathlib.Path('extracted_files/Pest_Dataset')
|
| 58 |
-
data_dir = pathlib.Path(data_dir)
|
| 59 |
|
| 60 |
# Verify if the path exists
|
| 61 |
assert data_dir.exists(), f"Path {data_dir} does not exist."
|
|
@@ -95,7 +77,7 @@ for images, labels in train_ds.take(1):
|
|
| 95 |
plt.axis("off")
|
| 96 |
|
| 97 |
# Define data augmentation
|
| 98 |
-
data_augmentation =
|
| 99 |
[
|
| 100 |
layers.RandomFlip("horizontal", input_shape=(img_height, img_width, 3)),
|
| 101 |
layers.RandomRotation(0.1),
|
|
@@ -116,7 +98,7 @@ for images, _ in train_ds.take(1):
|
|
| 116 |
num_classes = len(class_names)
|
| 117 |
model = Sequential([
|
| 118 |
data_augmentation,
|
| 119 |
-
layers.Rescaling(1./255),
|
| 120 |
layers.Conv2D(16, 3, padding='same', activation='relu'),
|
| 121 |
layers.MaxPooling2D(),
|
| 122 |
layers.Conv2D(32, 3, padding='same', activation='relu'),
|
|
|
|
| 2 |
import matplotlib.pyplot as plt
|
| 3 |
import numpy as np
|
| 4 |
import os
|
|
|
|
| 5 |
import tensorflow as tf
|
| 6 |
+
from tensorflow.keras import layers, Sequential
|
| 7 |
+
from tensorflow.keras.models import load_model
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
import gdown
|
| 9 |
import zipfile
|
| 10 |
import pathlib
|
|
|
|
| 37 |
os.remove(local_zip_file)
|
| 38 |
|
| 39 |
# Convert the extracted directory path to a pathlib.Path object
|
| 40 |
+
data_dir = pathlib.Path(extracted_path) / 'Pest_Dataset'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
# Verify if the path exists
|
| 43 |
assert data_dir.exists(), f"Path {data_dir} does not exist."
|
|
|
|
| 77 |
plt.axis("off")
|
| 78 |
|
| 79 |
# Define data augmentation
|
| 80 |
+
data_augmentation = Sequential(
|
| 81 |
[
|
| 82 |
layers.RandomFlip("horizontal", input_shape=(img_height, img_width, 3)),
|
| 83 |
layers.RandomRotation(0.1),
|
|
|
|
| 98 |
num_classes = len(class_names)
|
| 99 |
model = Sequential([
|
| 100 |
data_augmentation,
|
| 101 |
+
layers.Rescaling(1./255, input_shape=(img_height, img_width, 3)),
|
| 102 |
layers.Conv2D(16, 3, padding='same', activation='relu'),
|
| 103 |
layers.MaxPooling2D(),
|
| 104 |
layers.Conv2D(32, 3, padding='same', activation='relu'),
|