Spaces:
Running
Running
File size: 1,167 Bytes
67f4974 a9c685c 67f4974 a9c685c 67f4974 a9c685c 67f4974 a9c685c 67f4974 a9c685c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
"""
Direct inference with hard-coded data
"""
from detection import ml_detection, ml_utils
# Run detection pipeline: load ML model, perform object detection and return json object
def detection_pipeline(model_type, image_bytes):
"""Detection pipeline: load ML model, perform object detection and return json object"""
# Load correct ML model
detr_processor, detr_model = ml_detection.load_model(model_type)
# Perform object detection
results = ml_detection.object_detection(detr_processor, detr_model, image_bytes)
# Convert dictionary of tensors to JSON object
result_json_dict = ml_utils.convert_tensor_dict_to_json(results)
return result_json_dict
def main():
"""Main function"""
print("Main function")
model_type = "facebook/detr-resnet-50"
image_path = "./samples/boats.jpg"
# Reading image file as image_bytes (similar to API request)
print("Reading image file...")
with open(image_path, "rb") as image_file:
image_bytes = image_file.read()
result_json = detection_pipeline(model_type, image_bytes)
print("result_json:", result_json)
if __name__ == "__main__":
main()
|