def get_human_data_from_img_path(self,
                                  img_path: str,
                                  export_path: str = None) -> List[Human]:
     img = cv2.imread(img_path)
     humans = self.get_humans_from_img(img)
     if export_path is not None:
         save_humans_img(img,
                         humans,
                         file_path=os.path.join(
                             get_create_path(export_path),
                             get_filename_from_path(img_path)))
     return humans
Exemplo n.º 2
0
    def __init__(self, model_name: str, model_dir: str):
        self.model_name: str = model_name
        self.model_dir: str = get_create_path(model_dir)

        self.num_epochs = 150
        self.checkpoint_epoch: int = 50

        # Optimizer
        self.learning_rate: float = 0.01
        self.momentum: float = 0.9
        self.weight_decay: float = 5e-4

        # LR Scheduler
        self.learning_rate_scheduler: LearningRateSchedulerBase = LearningRateSchedulerDummy()
Exemplo n.º 3
0
 def __init__(self, func: Callable, cache_config: CacheConfig):
     """
     Cache decorator which currently supports functions with base type, dictionary, list and lambda parameters
     :param func:
     """
     self.func = func
     self.cache_config = cache_config
     try:
         self.func_cache_dir = self.get_function_hash()
     except OSError as err:
         print(
             "OS Error, probably not possible to retrieve source code. Disable cache. Details: '{}'"
             .format(err))
         self.cache_config.cache_enabled = False
         return
     self.is_method = self.__is_method(self.func)
     self.func_cache_dir_path = get_create_path(
         os.path.join(self.cache_config.cache_dir, self.func_cache_dir))
     self.arg_names = list(inspect.signature(self.func).parameters.keys())
     self.replacement_args = None
     if self.func.__name__ in self.cache_config.str_args_replacement_dict.keys(
     ):
         self.replacement_args = self.cache_config.str_args_replacement_dict[
             self.func.__name__]
        "ehpi_journal_2019_03_pose_seed_0_cp0200",
        "ehpi_journal_2019_03_pose_seed_104_cp0200",
        "ehpi_journal_2019_03_pose_seed_123_cp0200",
        "ehpi_journal_2019_03_pose_seed_142_cp0200",
        "ehpi_journal_2019_03_pose_seed_200_cp0200",
        #
        "ehpi_journal_2019_03_both_seed_0_cp0200",
        "ehpi_journal_2019_03_both_seed_104_cp0200",
        "ehpi_journal_2019_03_both_seed_123_cp0200",
        "ehpi_journal_2019_03_both_seed_142_cp0200",
        "ehpi_journal_2019_03_both_seed_200_cp0200",
    ]
    # Test set
    test_set = get_test_set_lab(ehpi_dataset_path, ImageSize(1280, 720))
    result_path = get_create_path(
        os.path.join(data_dir, "results", "its_journal_experiment_results",
                     "lab"))

    # test_set = get_test_set_office(ImageSize(1280, 720))
    # result_path = get_create_path(os.path.join(data_dir, "results", "its_journal_experiment_results", "office"))

    test_loader = DataLoader(test_set, batch_size=1, shuffle=False)

    for model_name in model_names:
        print("Model name: {}".format(model_name))
        weights_path = os.path.join(models_dir, "{}.pth".format(model_name))

        tester = TesterEhpi()
        ehpi_results, seq_results = tester.test(test_loader,
                                                weights_path,
                                                model=EhpiLSTM(15, 5))
Exemplo n.º 5
0
import logging

from nobos_commons.utils.file_helper import get_create_path


#TODO: Make this more useable ...

logger = logging.getLogger()

logFormatter = logging.Formatter("%(asctime)s [%(filename)s | %(funcName)s()] [%(levelname)s]  %(message)s")

logPath = get_create_path("logs") #Todo configurable
fileHandler = logging.FileHandler("{0}/{1}.log".format(r'logs', 'info'))
fileHandler.setFormatter(logFormatter)
fileHandler.setLevel(logging.ERROR)
logger.addHandler(fileHandler)

consoleFormatter = logging.Formatter("[%(funcName)s] %(message)s")
consoleHandler = logging.StreamHandler()
consoleHandler.setFormatter(consoleFormatter)
consoleHandler.setLevel(logging.DEBUG)
logger.addHandler(consoleHandler)

logger.setLevel(logging.INFO)
    for test_name in test_names:
        all_labels_seq = []
        all_preds_seq = []
        all_labels_ehpi = []
        all_preds_ehpi = []
        for seed in seeds:
            model_name = "ehpi_journal_2019_03_{}_seed_{}_cp0200".format(
                test_name.lower(), seed)
            print("Model name: {}".format(model_name))

            ehpi_results = np.load(
                os.path.join(result_path, "{}_ehpis.npy".format(model_name)))
            seq_results = np.load(
                os.path.join(result_path, "{}_seqs.npy".format(model_name)))
            plot_path = get_create_path(os.path.join(result_path, model_name))

            labels_seq, preds_seq, false_detected_seqs = eval_seq(
                seq_results, plot_path,
                "ActionSim ({}) [Seq]: confusion matrix (normalized)".format(
                    test_name))
            labels_ehpi, preds_ehpi = eval_ehpi(
                ehpi_results, plot_path,
                "ActionSim ({}) [TW]: confusion matrix (normalized)".format(
                    test_name))
            all_labels_seq.extend(labels_seq)
            all_preds_seq.extend(preds_seq)
            all_false_detected_seqs[seed][test_name] = false_detected_seqs
            all_labels_ehpi.extend(labels_ehpi)
            all_preds_ehpi.extend(preds_ehpi)
        plot_confusion_matrix(
Exemplo n.º 7
0
        # --------- Draw objects
        bbs_to_draw = [
            bb for bb in image_content.objects if bb.label != "person"
        ]
        list(map(lambda bb: draw_bb(img, bb), bbs_to_draw))

        list(
            map(
                lambda human: draw_bb(
                    img, human.bounding_box, actions[human.uid][0].name
                    if human.uid in actions else "None"),
                image_content.humans))

        img = cv2.resize(img, (1280, 720))

        # cv2.imshow('webcam', img)
        cv2.imwrite(
            os.path.join(
                get_create_path(
                    "/content/drive/My Drive/be proj alternate code/Check3/input1/img_out"
                ), "{}.png".format(str(frame_nr).zfill(5))), img)
        # cv2.imwrite(os.path.join(get_create_path(
        #     "/media/disks/beta/records/with_visualizations/2019_03_13_Freilichtmuseum_Dashcam_Test_FASTMODE"),
        #                          "{}.jpg".format(str(frame_nr).zfill(5))), img)

        key = cv2.waitKey(1)
        if key & 0xFF == ord('q'):
            break

        fps_tracker.print_fps()