Spaces:
Sleeping
Sleeping
cyberai-1 commited on
Commit ·
ba646e4
1
Parent(s): 4ba1c15
Match model preprocessing scale
Browse files
app.py
CHANGED
|
@@ -25,6 +25,7 @@ UPLOAD_DIR = BASE_DIR / "static" / "uploads"
|
|
| 25 |
DATABASE_PATH = BASE_DIR / "instance" / "traffic_signs.sqlite3"
|
| 26 |
MODEL_PATH = BASE_DIR / "traffic_classifier.h5"
|
| 27 |
ALLOWED_EXTENSIONS = {"png", "jpg", "jpeg", "webp"}
|
|
|
|
| 28 |
URL_CONTENT_TYPES = {
|
| 29 |
"image/jpeg": "jpg",
|
| 30 |
"image/png": "png",
|
|
@@ -227,7 +228,9 @@ def save_uploaded_image(file):
|
|
| 227 |
def prepare_image(path):
|
| 228 |
image = Image.open(path).convert("RGB")
|
| 229 |
image = image.resize((30, 30))
|
| 230 |
-
array = np.asarray(image, dtype=np.float32)
|
|
|
|
|
|
|
| 231 |
return np.expand_dims(array, axis=0)
|
| 232 |
|
| 233 |
|
|
|
|
| 25 |
DATABASE_PATH = BASE_DIR / "instance" / "traffic_signs.sqlite3"
|
| 26 |
MODEL_PATH = BASE_DIR / "traffic_classifier.h5"
|
| 27 |
ALLOWED_EXTENSIONS = {"png", "jpg", "jpeg", "webp"}
|
| 28 |
+
NORMALIZE_INPUT = os.environ.get("NORMALIZE_INPUT", "false").lower() in {"1", "true", "yes"}
|
| 29 |
URL_CONTENT_TYPES = {
|
| 30 |
"image/jpeg": "jpg",
|
| 31 |
"image/png": "png",
|
|
|
|
| 228 |
def prepare_image(path):
|
| 229 |
image = Image.open(path).convert("RGB")
|
| 230 |
image = image.resize((30, 30))
|
| 231 |
+
array = np.asarray(image, dtype=np.float32)
|
| 232 |
+
if NORMALIZE_INPUT:
|
| 233 |
+
array = array / 255.0
|
| 234 |
return np.expand_dims(array, axis=0)
|
| 235 |
|
| 236 |
|