-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinference_direct.py
More file actions
40 lines (27 loc) · 1.14 KB
/
inference_direct.py
File metadata and controls
40 lines (27 loc) · 1.14 KB
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
"""
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()