Example #1
0
        d[ord(c)] = 1
        pred = predict(net, d)
        d[ord(c)] = 0
    c = s[-1]
    while 1:
        d[ord(c)] = 1
        pred = predict(net, d)
        d[ord(c)] = 0
        pred = [pred[i] for i in range(256)]
        ind = sample(pred)
        c = chr(ind)
        prob += math.log(pred[ind])
        if len(tac) and tac[-1] == '.':
            break
        tac = tac + c
    return (tac, prob)


def predict_tactics(net, s, n):
    tacs = []
    for i in range(n):
        reset_rnn(net)
        tacs.append(predict_tactic(net, s))
    tacs = sorted(tacs, key=lambda x: -x[1])
    return tacs


net = load_net("cfg/coq.test.cfg", "/home/pjreddie/backup/coq.backup", 0)
t = predict_tactics(net, "+++++\n", 10)
print(t)
Created on Thu Aug  9 21:51:14 2018

@author: julien
"""

import cv2
import os
from python import darknet as dn

# load the Neural Network and the meta
path = "./char/"
cfg = os.path.join(path, "yolov3_plate.cfg").encode()
weights = os.path.join(path, "yolov3_plate_4000_ok.weights").encode()
data = os.path.join(path, "obj_plate.data").encode()

net = dn.load_net(cfg, weights, 0)
meta = dn.load_meta(data)

path_v = "/home/jehl/darknet/char/img_char"

files = os.listdir(path_v)

for f in files:
    img_path = os.path.join(path_v, f)
    result, im = dn.detect(net, meta, img_path.encode(), thresh=0.1)
    if len(result) != 0:
        print("Recognize !!!!!!!!!!!!!!!!!!")
        for p in result:
            x1 = int(p[2][0] - p[2][2] / 2)
            y1 = int(p[2][1] - p[2][3] / 2)
            x2 = int(p[2][0] + p[2][2] / 2)
Example #3
0
import time
import random
import colorsys
import numpy as np
from PIL import Image, ImageDraw, ImageFont
import cv2
import python.darknet as dn

# prepare YOLO
net = dn.load_net(str.encode("cfg/tiny-yolo.cfg"),
                  str.encode("weights/tiny-yolo.weights"), 0)
meta = dn.load_meta(str.encode("cfg/coco.data"))

# box colors
box_colors = None


def generate_colors(num_classes):
    global box_colors

    if box_colors != None and len(box_colors) > num_classes:
        return box_colors

    hsv_tuples = [(x / num_classes, 1., 1.) for x in range(num_classes)]
    box_colors = list(map(lambda x: colorsys.hsv_to_rgb(*x), hsv_tuples))
    box_colors = list(
        map(lambda x: (int(x[0] * 255), int(x[1] * 255), int(x[2] * 255)),
            box_colors))
    random.seed(10101)  # Fixed seed for consistent colors across runs.
    # Shuffle colors to decorrelate adjacent classes.
    random.shuffle(box_colors)
# import os
# os.chdir('/Users/xierong/Desktop/Master_2016/googleMLCamp2019/objectDetection/darknet')

import python.darknet as dn


def detection(image, net, meta):
    res = dn.detect(net, meta, str.encode(image))
    return res


if __name__ == "__main__":
    dn.set_gpu(0)
    net = dn.load_net(str.encode("cfg/yolov3.cfg"),
                      str.encode("yolov3.weights"), 0)
    meta = dn.load_meta(str.encode("cfg/coco.data"))
    image = "data/googleCat.jpg"
    res = detection(image, net, meta)
    print(res)
    # for r in res:
    #     r = list(r)
    #     r[0] = str(r[0], encoding = "utf-8")
Example #5
0
else:
    sys.path.append('.')

import python.darknet as dn
from custom.deep_sort import nn_matching
from custom.deep_sort.tracker import Tracker
from custom.deep_sort.detection import Detection
from custom.application_util import preprocessing
import custom.application_util.geometry as geometry

net_config = {
    'weights': b'yolov3.weights',
    'config': b'cfg/yolov3.cfg',
    'dataset': b'cfg/coco.data',
}
net = dn.load_net(net_config['config'], net_config['weights'], 0)
net_meta = dn.load_meta(net_config['dataset'])


class ObjectTracking:
    def __init__(self,
                 thresh=0.4,
                 counting_line=None,
                 nms_max_overlap=1.0,
                 min_detection_height=20,
                 max_cosine_distance=0.2,
                 metric_name='cosine',
                 classes=('car', 'truck', 'bus')):
        self.thresh = thresh
        self.counting_line = counting_line
        self.nms_max_overlap = nms_max_overlap
Example #6
0
# this script must be runned from the darknet folder

input_dir = "../video/"
output_path = "../output.mp4"

data = "cfg/aerial.data"
cfg = "cfg/yolov3-aerial.cfg"
weights = "backup/yolov3-aerial.backup"

images = [d for d in os.listdir(input_dir) if d.endswith('.jpg')]
images.sort()

img = cv2.imread(images[0])
height, width, channels = img.shape

net = dn.load_net(cfg.encode(), weights.encode(), 0)
meta = dn.load_meta(data.encode())

fourcc = cv2.VideoWriter_fourcc(*'mp4v')
out = cv2.VideoWriter(output_path, fourcc, 20.0, (width, height))

count = 0
total = len(images)
for i in images:
    count += 1
    print("Exportation {}%".format(count / total), end="\r")

    img_path = os.path.join(input_dir, i)
    r = dn.detect(net, meta, im.encode())
    out.write(draw_yolo_result(im, r, ['car', 'bus', 'truck']))
Example #7
0



# In[2]:


weights = 'yolov4.weights'
netcfg  = 'cfg/yolov4.cfg'
data = 'cfg/coco.data'


# In[ ]:


net  = dn.load_net(netcfg.encode('utf-8'), weights.encode('utf-8'), 0)
meta = dn.load_meta(data.encode('utf-8'))


# In[ ]:

cam = 0
# cam = 'rtsp://*****:*****@192.168.88.249:554/Streaming/channels/1'
# cap = camera(cam)
# print(f"Camera is alive?: {cap.p.is_alive()}")
cap = cv2.VideoCapture(cam)


# In[7]: