Exemplo n.º 1
0
    def __init__(self, FLAGS, darknet=None):
        self.ntrain = 0
        if isinstance(FLAGS, dict):
            defaultSettings = {
                "binary": "./bin/",
                "config": "./cfg/",
                "batch": 16,
                "threshold": 0.1,
                "train": False,
                "verbalise": False,
                "gpu": 0.0
            }
            defaultSettings.update(FLAGS)
            FLAGS = dotdict(defaultSettings)

        if darknet is None:
            darknet = Darknet(FLAGS)
            self.ntrain = len(darknet.layers)
            #self.ntrain = 1

        self.darknet = darknet
        args = [darknet.meta, FLAGS]
        self.num_layer = len(darknet.layers)
        self.framework = create_framework(*args)

        self.meta = darknet.meta
        self.FLAGS = FLAGS

        self.say('\nBuilding net ...')
        start = time.time()
        self.graph = tf.Graph()
        with self.graph.as_default() as g:
            self.build_forward()
            self.setup_meta_ops()
        self.say('Finished in {}s\n'.format(time.time() - start))
    def __init__(self, FLAGS, darknet=None):
        self.ntrain = 0

        if isinstance(FLAGS, dict):
            defaultSettings = {
                "binary": "./bin/",
                "config": "./cfg/",
                "batch": 16,
                "threshold": 0.1,
                "train": False,
                "verbalise": False,
                "gpuName": "/gpu:0",
                "gpu": 0.0
            }
            defaultSettings.update(FLAGS)
            FLAGS = dotdict(defaultSettings)

        self.FLAGS = FLAGS
        if self.FLAGS.pbLoad and self.FLAGS.metaLoad:
            self.say('\nLoading from .pb and .meta')
            self.graph = tf.Graph()
            with self.graph.as_default() as g:
                device = FLAGS.gpuName \
                 if FLAGS.gpu > 0.0 else None
                with g.device(device):
                    self.build_from_pb()
            return

        if darknet is None:
            darknet = Darknet(FLAGS)
            self.ntrain = len(darknet.layers)

        self.darknet = darknet
        args = [darknet.meta, FLAGS]
        self.num_layer = len(darknet.layers)
        self.framework = create_framework(*args)

        self.meta = darknet.meta

        self.say('\nBuilding net ...')
        start = time.time()
        self.graph = tf.Graph()
        with self.graph.as_default() as g:
            device = FLAGS.gpuName \
             if FLAGS.gpu > 0.0 else None
            with g.device(device):
                self.build_forward()
                self.setup_meta_ops()
        self.say('Finished in {}s\n'.format(time.time() - start))
Exemplo n.º 3
0
    def __init__(self, FLAGS, darknet=None):
        self.ntrain = 0

        if isinstance(FLAGS, dict):
            from darkflow.defaults import argHandler
            newFLAGS = argHandler()
            newFLAGS.setDefaults()
            newFLAGS.update(FLAGS)
            FLAGS = newFLAGS

        self.FLAGS = FLAGS
        if self.FLAGS.pbLoad and self.FLAGS.metaLoad:
            self.say('\nLoading from .pb and .meta')
            self.graph = tf.Graph()
            device_name = FLAGS.gpuName \
                if FLAGS.gpu > 0.0 else None
            with tf.device(device_name):
                with self.graph.as_default() as g:
                    self.build_from_pb()
            return

        if darknet is None:
            darknet = Darknet(FLAGS)
            self.ntrain = len(darknet.layers)

        self.darknet = darknet
        args = [darknet.meta, FLAGS]
        self.num_layer = len(darknet.layers)
        #self.framework = create_framework(*args)
        self.framework = YOLOv2ForBusDetection(*args)

        self.meta = darknet.meta

        self.say('\nBuilding net ...')
        start = time.time()
        self.graph = tf.Graph()
        device_name = FLAGS.gpuName \
            if FLAGS.gpu > 0.0 else None
        with tf.device(device_name):
            with self.graph.as_default() as g:
                self.build_forward()
                self.setup_meta_ops()
        self.say('Finished in {}s\n'.format(time.time() - start))
Exemplo n.º 4
0
    def __init__(self, FLAGS, darknet=None):
        print('>>__init__')
        self.ntrain = 0
        self.male = 0
        self.female = 0
        self.FLAGS = FLAGS
        self.frame_count = 0
        self.record = np.array([['0000000000000000000'], [0], [0]])

        if isinstance(FLAGS, dict):
            newFLAGS = argHandler()
            newFLAGS.update(FLAGS)
            FLAGS = newFLAGS

        self.FLAGS = FLAGS
        if self.FLAGS.pbLoad and self.FLAGS.metaLoad:
            self.say('\nLoading from .pb and .meta')
            self.graph = tf.Graph()
            device_name = FLAGS.gpuName if FLAGS.gpu > 0.0 else None
            with tf.device(device_name):
                with self.graph.as_default() as g:
                    self.build_from_pb()
            return

        # init socket
        if self.FLAGS.socket == 'yes':
            self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
            self.sock.connect((FLAGS.hostname, FLAGS.port))
            print('Client socket name is {}'.format(self.sock.getsockname()))

            text = 'Client connected'
            print('Socket connected')
            data = text.encode('ascii')
            self.sock.send(data)

        if darknet is None:
            print('>>darknet = Darknet(FLAGS)')
            darknet = Darknet(FLAGS)

            self.ntrain = len(darknet.layers)

        self.darknet = darknet
        args = [darknet.meta, FLAGS]

        self.num_layer = len(darknet.layers)
        print('>>layers = ', self.num_layer)
        self.framework = create_framework(*args)

        # meta dict
        #self.meta={'net': {'type': '[net]', 'batch': 1, 'subdivisions': 1, 'width': 608, 'height': 608, 'channels': 3, 'momentum': 0.9, 'decay': 0.0005, 'angle': 0, 'saturation': 1.5, 'exposure': 1.5, 'hue': 0.1, 'learning_rate': 0.001, 'burn_in': 1000, 'max_batches': 500200, 'policy': 'steps', 'steps': '400000,450000', 'scales': '.1,.1'}, 'type': '[region]', 'anchors': [0.57273, 0.677385, 1.87446, 2.06253, 3.33843, 5.47434, 7.88282, 3.52778, 9.77052, 9.16828], 'bias_match': 1, 'classes': 80, 'coords': 4, 'num': 5, 'softmax': 1, 'jitter': 0.3, 'rescore': 1, 'object_scale': 5, 'noobject_scale': 1, 'class_scale': 1, 'coord_scale': 1, 'absolute': 1, 'thresh': 0.3, 'random': 1, 'model': 'cfg/yolo.cfg', 'inp_size': [608, 608, 3], 'out_size': [19, 19, 425], 'name': 'yolo', 'labels': ['person', 'bicycle', 'car', 'motorbike', 'aeroplane', 'bus', 'train', 'truck', 'boat', 'traffic light', 'fire hydrant', 'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog', 'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe', 'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee', 'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat', 'baseball glove', 'skateboard', 'surfboard', 'tennis racket', 'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl', 'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot', 'hot dog', 'pizza', 'donut', 'cake', 'chair', 'sofa', 'pottedplant', 'bed', 'diningtable', 'toilet', 'tvmonitor', 'laptop', 'mouse', 'remote', 'keyboard', 'cell phone', 'microwave', 'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock', 'vase', 'scissors', 'teddy bear', 'hair drier', 'toothbrush'], 'colors': [(254.0, 254.0, 254), (248.92, 228.6, 127), (243.84, 203.20000000000002, 0), (238.76, 177.79999999999998, -127), (233.68, 152.4, -254), (228.6, 127.0, 254), (223.52, 101.60000000000001, 127), (218.44, 76.20000000000002, 0), (213.35999999999999, 50.79999999999999, -127), (208.28000000000003, 25.399999999999995, -254), (203.20000000000002, 0.0, 254), (198.12, -25.400000000000023, 127), (193.04, -50.79999999999999, 0), (187.96, -76.20000000000002, -127), (182.88, -101.59999999999998, -254), (177.79999999999998, -127.0, 254), (172.71999999999997, -152.40000000000003, 127), (167.64, -177.79999999999998, 0), (162.56, -203.20000000000002, -127), (157.48, -228.59999999999997, -254), (152.4, -254.0, 254), (147.32000000000002, -279.40000000000003, 127), (142.24, -304.80000000000007, 0), (137.16, -330.19999999999993, -127), (132.08, -355.59999999999997, -254), (127.0, 254.0, 254), (121.92, 228.6, 127), (116.83999999999999, 203.20000000000002, 0), (111.75999999999999, 177.79999999999998, -127), (106.68, 152.4, -254), (101.60000000000001, 127.0, 254), (96.52, 101.60000000000001, 127), (91.44, 76.20000000000002, 0), (86.35999999999999, 50.79999999999999, -127), (81.27999999999999, 25.399999999999995, -254), (76.20000000000002, 0.0, 254), (71.12, -25.400000000000023, 127), (66.04, -50.79999999999999, 0), (60.96, -76.20000000000002, -127), (55.879999999999995, -101.59999999999998, -254), (50.79999999999999, -127.0, 254), (45.72000000000001, -152.40000000000003, 127), (40.64000000000001, -177.79999999999998, 0), (35.56, -203.20000000000002, -127), (30.48, -228.59999999999997, -254), (25.399999999999995, -254.0, 254), (20.31999999999999, -279.40000000000003, 127), (15.240000000000013, -304.80000000000007, 0), (10.160000000000009, -330.19999999999993, -127), (5.0800000000000045, -355.59999999999997, -254), (0.0, 254.0, 254), (-5.0800000000000045, 228.6, 127), (-10.160000000000009, 203.20000000000002, 0), (-15.240000000000013, 177.79999999999998, -127), (-20.320000000000018, 152.4, -254), (-25.400000000000023, 127.0, 254), (-30.480000000000025, 101.60000000000001, 127), (-35.559999999999974, 76.20000000000002, 0), (-40.63999999999998, 50.79999999999999, -127), (-45.719999999999985, 25.399999999999995, -254), (-50.79999999999999, 0.0, 254), (-55.879999999999995, -25.400000000000023, 127), (-60.96, -50.79999999999999, 0), (-66.04, -76.20000000000002, -127), (-71.12, -101.59999999999998, -254), (-76.20000000000002, -127.0, 254), (-81.28000000000002, -152.40000000000003, 127), (-86.36000000000001, -177.79999999999998, 0), (-91.44000000000003, -203.20000000000002, -127), (-96.51999999999997, -228.59999999999997, -254), (-101.59999999999998, -254.0, 254), (-106.67999999999998, -279.40000000000003, 127), (-111.75999999999999, -304.80000000000007, 0), (-116.83999999999999, -330.19999999999993, -127), (-121.92, -355.59999999999997, -254), (-127.0, 254.0, 254), (-132.08, 228.6, 127), (-137.16, 203.20000000000002, 0), (-142.24, 177.79999999999998, -127), (-147.32000000000002, 152.4, -254)]}
        self.meta = darknet.meta  #auto define
        print(self.meta)

        print('>>meta class = ', len(self.meta['labels']))

        self.say('\nBuilding net ...')
        start = time.time()
        self.graph = tf.Graph()
        device_name = FLAGS.gpuName if FLAGS.gpu > 0.0 else None
        with tf.device(device_name):
            with self.graph.as_default() as g:
                self.build_forward()
                self.setup_meta_ops()
        self.say('Finished in {}s\n'.format(time.time() - start))