Skip to content
Snippets Groups Projects
Commit b165ab46 authored by michael.divia's avatar michael.divia
Browse files

Added Dynamic size

parent dddeebf2
Branches
No related tags found
No related merge requests found
......@@ -11,15 +11,19 @@ args = parser.parse_args()
if args.model == "1":
h5_path = "../models/ResNet50/pokedex_ResNet50.h5"
onnx_path = "../models/ResNet50/pokedex_ResNet50.onnx"
size=(224, 224, 3)
size_2=(1, 224, 224, 3)
elif args.model == "2":
h5_path = "../models/Xception/pokedex_Xception.h5"
onnx_path = "../models/ResNet50/pokedex_Xception.onnx"
size=(256, 256, 3)
size_2=(1, 256, 256, 3)
# --- Load Sequential model ---
seq_model = tf.keras.models.load_model(h5_path, compile=False)
# --- Create input layer with same shape ---
inputs = tf.keras.Input(shape=(224, 224, 3), name="input")
inputs = tf.keras.Input(shape=size, name="input")
# --- Call the Sequential model as a function ---
outputs = seq_model(inputs)
......@@ -28,7 +32,7 @@ outputs = seq_model(inputs)
model = tf.keras.Model(inputs=inputs, outputs=outputs)
# --- Convert to ONNX ---
spec = (tf.TensorSpec((1, 224, 224, 3), tf.float32, name="input"),)
spec = (tf.TensorSpec(size_2, tf.float32, name="input"),)
onnx_model, _ = tf2onnx.convert.from_keras(
model,
input_signature=spec,
......
......@@ -13,9 +13,11 @@ args = parser.parse_args()
if args.model == "1":
hef_path = "../models/ResNet50/pokedex_ResNet50.hef"
json_path = "../models/ResNet50/class_names.json"
size=(224,224)
elif args.model == "2":
hef_path = "../models/Xception/pokedex_Xception.hef"
json_path = "../models/Xception/class_names.json"
size=(256,256)
# Load class names
with open(json_path, "r") as f:
......@@ -42,7 +44,7 @@ if not ret:
exit()
# --- Preprocess image ---
image = cv2.resize(frame, (224, 224))
image = cv2.resize(frame, size)
image = image.astype(np.float32) / 255.0 # Normalize to [0, 1]
image = np.expand_dims(image, axis=0) # Add batch dimension
image = np.transpose(image, (0, 3, 1, 2)) # NHWC ? NCHW if required (check your model)
......
......@@ -16,9 +16,11 @@ args = parser.parse_args()
if args.model == "1":
h5_path = "../models/ResNet50/pokedex_ResNet50.h5"
json_path = "../models/ResNet50/class_names.json"
size = (224,224)
elif args.model == "2":
h5_path = "../models/Xception/pokedex_Xception.h5"
json_path = "../models/Xception/class_names.json"
size = (256,256)
# --- Load class names from JSON ---
with open(json_path, "r") as f:
......@@ -45,7 +47,7 @@ for i in range(4):
img_path = os.path.join(class_folder, random_image)
# --- Load & Preprocess Image ---
img = keras.utils.load_img(img_path, target_size=(224, 224)) # resize to match model input
img = keras.utils.load_img(img_path, target_size=size) # resize to match model input
img_array = keras.utils.img_to_array(img)
img_array = img_array / 255.0 # normalize if your model expects it
img_array = tf.expand_dims(img_array, 0)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment