-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
63 lines (50 loc) · 2.25 KB
/
main.py
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import concurrent.futures
import logging
from datetime import datetime
from pathlib import Path
import json
from tqdm import tqdm
from decouple import config
from src.connection_handler import ConnectionHandler
from src.frame_predictions import FramePredictions
from src.object_detection_model import ObjectDetectionModel
def configure_logger(team_name):
log_folder = "./_logs/"
Path(log_folder).mkdir(parents=True, exist_ok=True)
log_filename = datetime.now().strftime(log_folder + team_name + '_%Y_%m_%d__%H_%M_%S_%f.log')
logging.basicConfig(filename=log_filename, level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s')
def run():
print("Started...")
# Get configurations from .env file
config.search_path = "./config/"
team_name = config('TEAM_NAME')
password = config('PASSWORD')
evaluation_server_url = config("EVALUATION_SERVER_URL")
# Declare logging configuration.
configure_logger(team_name)
# Teams can implement their codes within ObjectDetectionModel class. (OPTIONAL)
detection_model = ObjectDetectionModel(evaluation_server_url)
# Connect to the evaluation server.
server = ConnectionHandler(evaluation_server_url, username=team_name, password=password)
# Get all frames from current active session.
frames_json = server.get_frames()
# Create images folder
images_folder = "./_images/"
Path(images_folder).mkdir(parents=True, exist_ok=True)
print(len(frames_json))
# Run object detection model frame by frame.
for frame in tqdm(frames_json):
# Create a prediction object to store frame info and detections
predictions = FramePredictions(frame['url'], frame['image_url'], frame['video_name'])
#print(predictions.image_url)
# Run detection model
predictions = detection_model.process(predictions,evaluation_server_url)
if predictions == "error":
continue
# Send model predictions of this frame to the evaluation server
#with open(f"./test/{frame['image_url'].rsplit('/', 1)[-1]}.json", 'w') as file:
# json.dump(predictions.create_payload(evaluation_server_url), file)
result = server.send_prediction(predictions)
if __name__ == '__main__':
run()