def __init__(self, config, connector_type):
        super().__init__()
        self.__config = config

        self.input_size = 416
        onnx_fn = "/data/yolov4_e_scooter.onnx"

        ## cpu'da daha hızlı ama false positive fazla
        # self.input_size = 640
        # onnx_fn = "/data/yolov5_e_scooter.onnx"

        onnx_fn = os.path.dirname(os.path.abspath(__file__)) + onnx_fn.replace(
            "/", os.path.sep)

        classes_fn = "/data/class.names"
        classes_fn = os.path.dirname(
            os.path.abspath(__file__)) + classes_fn.replace("/", os.path.sep)

        self.class_names = onnx_helper.parse_class_names(classes_fn)
        self.sess_tuple = onnx_helper.get_sess_tuple(onnx_fn)

        # region Demo
        self._last_sent = None
        self._last_candidate = None
        self._last_candidate_counter = 0
Пример #2
0
    def __init__(self, config, _connector_type):
        super().__init__()

        # # onnx_fn = "/data/small_30.onnx"
        # onnx_fn = "/data/best.onnx"
        # # self. = "/data/last.onnx"
        # self.input_size = 640

        onnx_fn = "/data/yolov4_helmet.onnx"
        self.input_size = 416

        self.average_of_frames = config.get("average_of_frames", 1)
        self.confirm_count = config.get("confirm_count", 1)
        self.confirm_val = 0

        self._use_person = config.get("use_person", True)

        if not os.path.isfile(onnx_fn):
            onnx_fn = os.path.dirname(
                os.path.abspath(__file__)) + onnx_fn.replace("/", os.path.sep)

        classes_filename = "/data/class.names"
        if not os.path.isfile(classes_filename):
            classes_filename = os.path.dirname(
                os.path.abspath(__file__)) + classes_filename.replace(
                    "/", os.path.sep)
        self.class_names = onnx_helper.parse_class_names(classes_filename)
        self.sess_tuple = onnx_helper.get_sess_tuple(onnx_fn)

        self.debug_mode = NDUUtility.is_debug_mode()
        self.last_data = None
        self.queue = []
Пример #3
0
    def __init__(self, config, _connector_type):
        super().__init__()

        onnx_fn = path.dirname(
            path.abspath(__file__)) + "/data/weights.29-3.76_utk.hdf5.onnx"
        if not path.isfile(onnx_fn):
            raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT),
                                    onnx_fn)
        self.sess_tuple = onnx_helper.get_sess_tuple(onnx_fn)
Пример #4
0
    def __init__(self, config, connector_type):
        super().__init__()
        self.__config = config
        self.input_size = config.get("input_size", 512)

        #### OLD
        # # 416 msec üst üste var
        # self.input_size = 512
        # onnx_fn = "/data/yolov4_-1_3_512_512_dynamic.onnx"

        # # 550 msec başarılı (default)
        # self.input_size = 608
        # onnx_fn = "/data/yolov4_-1_3_608_608_dynamic.onnx"

        # ### başarısız
        # # 335 msec
        # self.input_size = 512
        # onnx_fn = "/data/old/yolov4-csp_1_3_512_512_static.onnx"

        # # 793 msec  üst üste çok var
        # self.input_size = 640
        # onnx_fn = "/data/yolov4x-mish_1_3_640_640_static.onnx"

        # ### OK
        # 550 msec  başarılı  - vino onnx 350
        self.input_size = 608
        onnx_fn = "/data/yolov4-1_3_608_608_static.onnx"


        # # 22 msec  güzel  - vino onnx 16
        # self.input_size = 416
        # onnx_fn = "/data/yolov4-tiny_1_3_416_416_static.onnx"



        # # vehicles
        # self.input_size = 416
        # onnx_fn = "/data/yolov4-tiny_vehicles_416_static.onnx"


        # # vehicles
        # self.input_size = 416
        # onnx_fn = "/data/yolov4-tiny_vehicle_lp_7_416_static.onnx"






        if not os.path.isfile(onnx_fn):
            onnx_fn = os.path.dirname(os.path.abspath(__file__)) + onnx_fn.replace("/", os.path.sep)

        classes_filename = config.get("classes_filename", "/data/coco.names")
        if not os.path.isfile(classes_filename):
            classes_filename = os.path.dirname(os.path.abspath(__file__)) + classes_filename.replace("/", os.path.sep)
        self.class_names = onnx_helper.parse_class_names(classes_filename)
        self.sess_tuple = onnx_helper.get_sess_tuple(onnx_fn)
Пример #5
0
    def __init__(self, config, _connector_type):
        super().__init__()
        self.counter = 0
        self._send_data = config.get("send_data", False)

        city_codes_fn = "/data/city_codes.json"
        if not os.path.isfile(city_codes_fn):
            city_codes_fn = os.path.dirname(
                os.path.abspath(__file__)) + city_codes_fn.replace(
                    "/", os.path.sep)
        with open(city_codes_fn, encoding="UTF-8") as f_in:
            self._cities = json.load(f_in)

        conf_fn = "/data/openalpr_64/openalpr.conf"
        #conf_fn = "//usr/local/share/openalpr/config/openalpr.defaults.conf"
        # conf_fn = "/data/openalpr_64/runtime_data/config/eu.conf"
        if not os.path.isfile(conf_fn):
            conf_fn = os.path.dirname(
                os.path.abspath(__file__)) + conf_fn.replace("/", os.path.sep)

        runtime_data = "/data/openalpr_64/runtime_data/"
        #runtime_data = "/usr/local/share/openalpr/runtime_data/"
        if not os.path.isdir(runtime_data):
            runtime_data = os.path.dirname(
                os.path.abspath(__file__)) + runtime_data.replace(
                    "/", os.path.sep)

        # self._alpr = Alpr("us", "/path/to/openalpr.conf", "/path/to/runtime_data")
        # self._alpr = Alpr("eu", conf_fn, runtime_data)
        self._alpr = Alpr("tr", conf_fn, runtime_data)

        if not self._alpr.is_loaded():
            print("Error loading OpenALPR")

        # self._alpr.set_top_n(20)
        # self._alpr.set_default_region("md")
        # self._alpr.set_top_n(1)
        self._alpr.set_default_region("tr")
        self._alpr.set_country("tr")

        # region lp detection,
        onnx_fn = "/data/yolov4-tiny_lp_416_static.onnx"
        self.input_size = 416

        if not os.path.isfile(onnx_fn):
            onnx_fn = os.path.dirname(
                os.path.abspath(__file__)) + onnx_fn.replace("/", os.path.sep)

        classes_filename = "/data/class.names"
        if not os.path.isfile(classes_filename):
            classes_filename = os.path.dirname(
                os.path.abspath(__file__)) + classes_filename.replace(
                    "/", os.path.sep)
        self.class_names = ["lp"]
        self.sess_tuple = onnx_helper.get_sess_tuple(onnx_fn)
Пример #6
0
    def __init__(self, config, connector_type):
        super().__init__()
        onnx_fn = "/data/yolov5s.onnx"
        classes_filename = "/data/coco.names"
        self.input_size = 640

        if not os.path.isfile(onnx_fn):
            onnx_fn = os.path.dirname(os.path.abspath(__file__)) + onnx_fn.replace("/", os.path.sep)
        if not os.path.isfile(classes_filename):
            classes_filename = os.path.dirname(os.path.abspath(__file__)) + classes_filename.replace("/", os.path.sep)
        self.class_names = onnx_helper.parse_class_names(classes_filename)
        self.sess_tuple = onnx_helper.get_sess_tuple(onnx_fn)
Пример #7
0
    def __init__(self, config, connector_type):
        super().__init__()
        onnx_fn = config.get("onnx_fn", "ssd_mobilenet_v1_10.onnx")
        if not os.path.isfile(onnx_fn):
            onnx_fn = os.path.dirname(os.path.abspath(__file__)) + onnx_fn.replace("/", os.path.sep)

        classes_filename = config.get("classes_filename", "mscoco_label_map.pbtxt.json")
        if not os.path.isfile(classes_filename):
            classes_filename = os.path.dirname(os.path.abspath(__file__)) + classes_filename.replace("/", os.path.sep)

        self.class_names = self._parse_pbtxt(classes_filename)
        self.sess_tuple = onnx_helper.get_sess_tuple(onnx_fn)
Пример #8
0
    def __init__(self, config, _connector_type):
        super().__init__()

        onnx_fn = "/data/yolov4_aerial_vehicle.onnx"
        self.input_size = 416

        if not os.path.isfile(onnx_fn):
            onnx_fn = os.path.dirname(os.path.abspath(__file__)) + onnx_fn.replace("/", os.path.sep)

        classes_filename = "/data/class.names"
        if not os.path.isfile(classes_filename):
            classes_filename = os.path.dirname(os.path.abspath(__file__)) + classes_filename.replace("/", os.path.sep)
        self.class_names = onnx_helper.parse_class_names(classes_filename)
        self.sess_tuple = onnx_helper.get_sess_tuple(onnx_fn)
Пример #9
0
    def __init__(self, config, connector_type):
        super().__init__()
        self.__config = config
        self.input_size = config.get("input_size", 416)

        onnx_fn = config.get("onnx_fn", "/data/yolov3.onnx")
        if not os.path.isfile(onnx_fn):
            onnx_fn = os.path.dirname(os.path.abspath(__file__)) + onnx_fn.replace("/", os.path.sep)

        classes_filename = config.get("classes_filename", "coco.names")
        if not os.path.isfile(classes_filename):
            classes_filename = os.path.dirname(os.path.abspath(__file__)) + classes_filename.replace("/", os.path.sep)
        self.class_names = onnx_helper.parse_class_names(classes_filename)
        self.sess_tuple = onnx_helper.get_sess_tuple(onnx_fn)
Пример #10
0
    def __init__(self, config, connector_type):
        super().__init__()
        self.__config = config
        self.__connector_type = connector_type

        onnx_fn = path.dirname(path.abspath(__file__)) + "/data/emotion-ferplus-8.onnx"

        class_names_fn = path.dirname(path.abspath(__file__)) + "/data/emotion.names"
        if not path.isfile(onnx_fn):
            raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), onnx_fn)
        if not path.isfile(class_names_fn):
            raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), class_names_fn)

        self.class_names = onnx_helper.parse_class_names(class_names_fn)
        self.sess_tuple = onnx_helper.get_sess_tuple(onnx_fn)
Пример #11
0
    def __init__(self, config, connector_type):
        super().__init__()

        # onnx_fn = "/data/transpalet_last.onnx"
        onnx_fn = "/data/transpalet_best.onnx"
        self.input_size = 608

        if not os.path.isfile(onnx_fn):
            onnx_fn = os.path.dirname(
                os.path.abspath(__file__)) + onnx_fn.replace("/", os.path.sep)

        classes_filename = "/data/class.names"
        if not os.path.isfile(classes_filename):
            classes_filename = os.path.dirname(
                os.path.abspath(__file__)) + classes_filename.replace(
                    "/", os.path.sep)
        self.class_names = onnx_helper.parse_class_names(classes_filename)
        self.sess_tuple = onnx_helper.get_sess_tuple(
            onnx_fn, config.get("max_engine_count", 0))
Пример #12
0
    def __init__(self, config, connector_type):
        super().__init__()
        self.__connector_type = connector_type

        self.__dont_use_face_rects = config.get("dont_use_face_rects", False)
        self.__upscale_person = config.get("upscale_person", False)
        self.__upscale_person = True  ####################
        self._debug = True  #####
        self._max_rect = config.get(
            "max_rect", 0
        )  # örneğin 0.5 verilirse, max dim değeri frame'in yarısından büyük olan bbox'lar kabul edilmez.
        self._last_data = None
        self.confirm_count = config.get("confirm_count", 1)
        self.confirm_val = 0
        self.time_start = 0
        self.start_cooldown_next_iter = False
        self.cooldown_timer = 0
        self.original_frame = ''
        self.capture_frames = config.get("capture_frames", False)
        onnx_fn = path.dirname(
            path.abspath(__file__)) + "/data/model360.onnx".replace(
                "/", os.path.sep)
        class_names_fn = path.dirname(
            path.abspath(__file__)) + "/data/face_mask.names".replace(
                "/", os.path.sep)
        if not path.isfile(onnx_fn):
            raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT),
                                    onnx_fn)
        if not path.isfile(class_names_fn):
            raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT),
                                    class_names_fn)
        self.class_names = onnx_helper.parse_class_names(class_names_fn)
        self.sess_tuple = onnx_helper.get_sess_tuple(onnx_fn)

        def generate_anchors(feature_map_sizes_, anchor_sizes_,
                             anchor_ratios_):
            """
            generate anchors.
            :param feature_map_sizes_: list of list, for example: [[40,40], [20,20]]
            :param anchor_sizes_: list of list, for example: [[0.05, 0.075], [0.1, 0.15]]
            :param anchor_ratios_: list of list, for example: [[1, 0.5], [1, 0.5]]
            :return:
            """
            anchor_bboxes = []
            for idx, feature_size in enumerate(feature_map_sizes_):
                cx = (np.linspace(0, feature_size[0] - 1, feature_size[0]) +
                      0.5) / feature_size[0]
                cy = (np.linspace(0, feature_size[1] - 1, feature_size[1]) +
                      0.5) / feature_size[1]
                cx_grid, cy_grid = np.meshgrid(cx, cy)
                cx_grid_expend = np.expand_dims(cx_grid, axis=-1)
                cy_grid_expend = np.expand_dims(cy_grid, axis=-1)
                center = np.concatenate((cx_grid_expend, cy_grid_expend),
                                        axis=-1)

                num_anchors = len(anchor_sizes_[idx]) + len(
                    anchor_ratios_[idx]) - 1
                center_tiled = np.tile(center, (1, 1, 2 * num_anchors))
                anchor_width_heights = []

                # different scales with the first aspect ratio
                for scale in anchor_sizes_[idx]:
                    ratio = anchor_ratios_[idx][0]  # select the first ratio
                    width = scale * np.sqrt(ratio)
                    height = scale / np.sqrt(ratio)
                    anchor_width_heights.extend([
                        -width / 2.0, -height / 2.0, width / 2.0, height / 2.0
                    ])

                # the first scale, with different aspect ratios (except the first one)
                for ratio in anchor_ratios_[idx][1:]:
                    s1 = anchor_sizes_[idx][0]  # select the first scale
                    width = s1 * np.sqrt(ratio)
                    height = s1 / np.sqrt(ratio)
                    anchor_width_heights.extend([
                        -width / 2.0, -height / 2.0, width / 2.0, height / 2.0
                    ])

                bbox_coords = center_tiled + np.array(anchor_width_heights)
                bbox_coords_reshape = bbox_coords.reshape((-1, 4))
                anchor_bboxes.append(bbox_coords_reshape)
            anchor_bboxes = np.concatenate(anchor_bboxes, axis=0)
            return anchor_bboxes

        feature_map_sizes = [[45, 45], [23, 23], [12, 12], [6, 6], [4, 4]]
        # feature_map_sizes = [[33, 33], [17, 17], [9, 9], [5, 5], [3, 3]] #160 için

        anchor_sizes = [[0.04, 0.056], [0.08, 0.11], [0.16, 0.22],
                        [0.32, 0.45], [0.64, 0.72]]
        anchor_ratios = [[1, 0.62, 0.42]] * 5
        # generate anchors
        anchors = generate_anchors(feature_map_sizes, anchor_sizes,
                                   anchor_ratios)

        # for inference , the batch size is 1, the model output shape is [1, N, 4],
        # so we expand dim for anchors to [1, anchor_num, 4]
        self.__anchors_exp = np.expand_dims(anchors, axis=0)