Update backend/main.py
Browse files- backend/main.py +3 -3
backend/main.py
CHANGED
|
@@ -13,7 +13,7 @@ from fastapi.responses import FileResponse, JSONResponse
|
|
| 13 |
import cv2 # type: ignore
|
| 14 |
import joblib # type: ignore
|
| 15 |
import tensorflow as tf # type: ignore
|
| 16 |
-
|
| 17 |
import os
|
| 18 |
os.environ["SM_FRAMEWORK"] = "tf.keras"
|
| 19 |
|
|
@@ -65,16 +65,16 @@ def get_preprocess_input():
|
|
| 65 |
# -----------------------------
|
| 66 |
# Preprocessing (as requested)
|
| 67 |
# -----------------------------
|
| 68 |
-
def load_data(image_path
|
| 69 |
image = tf.io.read_file(image_path)
|
| 70 |
image = tf.io.decode_png(image, channels=3)
|
| 71 |
image = tf.image.resize(image, [224, 224], method="bilinear")
|
| 72 |
image = tf.cast(image, tf.float32)
|
| 73 |
-
preprocess_input = get_preprocess_input()
|
| 74 |
image = preprocess_input(image)
|
| 75 |
return image
|
| 76 |
|
| 77 |
|
|
|
|
| 78 |
def extract_frames_to_pngs(video_bytes: bytes, max_frames: int = 300) -> List[str]:
|
| 79 |
"""Decode video bytes with OpenCV and write frames as PNGs to a temp dir.
|
| 80 |
|
|
|
|
| 13 |
import cv2 # type: ignore
|
| 14 |
import joblib # type: ignore
|
| 15 |
import tensorflow as tf # type: ignore
|
| 16 |
+
from tensorflow.keras.applications.resnet import preprocess_input
|
| 17 |
import os
|
| 18 |
os.environ["SM_FRAMEWORK"] = "tf.keras"
|
| 19 |
|
|
|
|
| 65 |
# -----------------------------
|
| 66 |
# Preprocessing (as requested)
|
| 67 |
# -----------------------------
|
| 68 |
+
def load_data(image_path):
|
| 69 |
image = tf.io.read_file(image_path)
|
| 70 |
image = tf.io.decode_png(image, channels=3)
|
| 71 |
image = tf.image.resize(image, [224, 224], method="bilinear")
|
| 72 |
image = tf.cast(image, tf.float32)
|
|
|
|
| 73 |
image = preprocess_input(image)
|
| 74 |
return image
|
| 75 |
|
| 76 |
|
| 77 |
+
|
| 78 |
def extract_frames_to_pngs(video_bytes: bytes, max_frames: int = 300) -> List[str]:
|
| 79 |
"""Decode video bytes with OpenCV and write frames as PNGs to a temp dir.
|
| 80 |
|