You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import cv2
import numpy as np
import tensorflow as tf
import time
# Load the TFLite model
interpreter = tf.lite.Interpreter(model_path="FF/realesr-general-x4v3_float32.tflite")
interpreter.allocate_tensors()
# Get input and output details
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()
# Load the input image
img = cv2.imread('FF/tnn.jpg')
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
# Resize image to match model's expected sizing
img = cv2.resize(img, (input_details[0]['shape'][2], input_details[0]['shape'][1]))
img = np.expand_dims(img, axis=0) # Add batch dimension
# Normalize the image
img = img.astype(np.float32) / 255
# Start time for measuring inference time
start_time = time.time()
# Set the tensor to point to the input data to be inferred
interpreter.set_tensor(input_details[0]['index'], img)
# Run inference
interpreter.invoke()
# Retrieve the model output
out_mat = interpreter.get_tensor(output_details[0]['index'])
# Measure and print elapsed time
elapsed_time = time.time() - start_time
print('Inference time: ', elapsed_time)
# Post-process and save output (as needed)
# Example: Convert output to desired format, visualize, etc.
# Example of saving the output
# Assuming the output is an image-like array
out_mat = (out_mat.squeeze() * 255).clip(0, 255).astype(np.uint8)
output_img = cv2.cvtColor(out_mat, cv2.COLOR_RGB2BGR)
cv2.imwrite('output.jpg', output_img)
print("Output image saved.")
The text was updated successfully, but these errors were encountered:
Can anyone help giving this code in Flutter.
Shape: NHWC (Number, 512 (Height), 512 (Width), 3 (RGB Channel)
Python:
The text was updated successfully, but these errors were encountered: