-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from uug-ai/enhancement
Enhance code and restructure repo
- Loading branch information
Showing
25 changed files
with
1,112 additions
and
429 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from exports.ibase_export import IBaseExport | ||
from utils.VariableClass import VariableClass | ||
from os.path import ( | ||
join as pjoin, | ||
dirname as pdirname, | ||
abspath as pabspath, | ||
) | ||
import os | ||
import time | ||
|
||
|
||
class BaseExport(IBaseExport): | ||
def __init__(self, proj_dir_name): | ||
self._var = VariableClass() | ||
_cur_dir = pdirname(pabspath(__file__)) | ||
self.proj_dir = pjoin(_cur_dir, f'../data/{proj_dir_name}') | ||
self.proj_dir = pabspath(self.proj_dir) # normalise the link | ||
self.result_dir_path = None | ||
|
||
def initialize_save_dir(self): | ||
""" | ||
See ibase_project.py | ||
Returns: | ||
None | ||
""" | ||
self.result_dir_path = pjoin(self.proj_dir, f'{self._var.DATASET_FORMAT}-v{self._var.DATASET_VERSION}') | ||
os.makedirs(self.result_dir_path, exist_ok=True) | ||
|
||
if os.path.exists(self.result_dir_path): | ||
print('Successfully initialize save directory!') | ||
return True | ||
else: | ||
print('Something wrong happened!') | ||
return False | ||
|
||
def save_frame(self, frame, predicted_frames, cv2, labels_and_boxes): | ||
print(f'5.1. Condition met, processing valid frame: {predicted_frames}') | ||
# Save original frame | ||
unix_time = int(time.time()) | ||
print("5.2. Saving frame, labels and boxes") | ||
cv2.imwrite( | ||
f'{self.result_dir_path}/{unix_time}.png', | ||
frame) | ||
# Save labels and boxes | ||
with open(f'{self.result_dir_path}/{unix_time}.txt', | ||
'w') as my_file: | ||
my_file.write(labels_and_boxes) | ||
|
||
# Increase the frame_number and predicted_frames by one. | ||
return predicted_frames + 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from exports.base_export import BaseExport | ||
from exports.yolov8_export import Yolov8Export | ||
from utils.VariableClass import VariableClass | ||
|
||
|
||
class ExportFactory: | ||
""" | ||
Export Factory initializes specific export types. | ||
""" | ||
def __init__(self): | ||
self._var = VariableClass() | ||
self.save_format = self._var.DATASET_FORMAT | ||
|
||
def init(self, proj_name): | ||
if self.save_format == 'yolov8': | ||
return Yolov8Export(proj_name) | ||
elif self.save_format == 'base': | ||
return BaseExport(proj_name) | ||
else: | ||
raise ModuleNotFoundError('Export type not found!') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from abc import ABC, abstractmethod | ||
|
||
|
||
class IBaseExport(ABC): | ||
|
||
@abstractmethod | ||
def initialize_save_dir(self): | ||
pass | ||
|
||
@abstractmethod | ||
def save_frame(self, frame, predicted_frames, cv2, labels_and_boxes): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from abc import ABC, abstractmethod | ||
|
||
|
||
class IYolov8Export(ABC): | ||
|
||
@abstractmethod | ||
def initialize_save_dir(self): | ||
pass | ||
|
||
@abstractmethod | ||
def save_frame(self, frame, predicted_frames, cv2, labels_and_boxes): | ||
pass | ||
|
||
@abstractmethod | ||
def create_yaml(self, model2): | ||
pass |
Oops, something went wrong.