コード例 #1
0
ファイル: parse.py プロジェクト: jackfan00/YOLOpython
def parse_network_cfg(cfg_path):
	# list of section
	sections = read_cfg(cfg_path)

	if sections[0].type != '[net]':
		print 'Error::cfg first section must be [net], %s' %(sections[0].type)
		exit()

	net = darknet.network()
	parse_net_options(sections[0].options, net)

	params = darknet.network()
	params.h = net.h
	params.w = net.w
	params.c = net.c
	params.inputs = net.inputs
	params.batch = net.batch

	# loop all section except the first one
	net.layers = []
	for s in sections:
		if s.type == '[net]':
			continue
		options = s.options

		# keras model creation
		if s.type == '[crop]':
			l=parse_corp(options, params)
		elif s.type == '[convolutional]':
			l=parse_convolutional(options, params)
		elif s.type == '[maxpool]':
			l=parse_maxpool(options, params)
		elif s.type == '[connected]':
			l=parse_connected(options, params)
		elif s.type == '[dropout]':
			l=parse_dropout(options, params)
		elif s.type == '[detection]':
			l=parse_detection(options, params)
		else:
			print 'Error::Type not recognized: %s' %(s.type)
			exit()

		print s.type
		l.type = s.type
		net.layers.append(l)
		params.h = l.outh
		params.w = l.outw
		params.c = l.outc
		params.inputs = l.outputs
	return net
コード例 #2
0
ファイル: detector.py プロジェクト: chencgln/darknet
def detect_image(image_path):
    net = dn.network(net_cfg, weights)
    meta = dn.metadata(meta_cfg)

    img = cv2.imread(image_path)
    res = dn.detect(net, meta, img)
    img = draw_box(img, res)
    cv2.imshow("frame", img)
    cv2.waitKey(0)

    return res
コード例 #3
0
ファイル: detector.py プロジェクト: chencgln/darknet
def detect_video(video_path):
    net = dn.network(net_cfg, weights)
    meta = dn.metadata(meta_cfg)

    capture = cv2.VideoCapture(video_path)
    read_flag, frame = capture.read()
    while (read_flag):
        res = dn.detect(net, meta, frame)
        img = draw_box(frame, res)
        cv2.imshow("frame", img)
        cv2.waitKey(0)
        read_flag, frame = capture.read()

    capture.release()
コード例 #4
0
ファイル: detector.py プロジェクト: chencgln/darknet
import sys, os
import cv2

sys.path.append(os.path.join(os.getcwd(), 'python/'))
import darknet as dn

# net_cfg="cfg/yolo9000.cfg"
# weights="yolo9000.weights"
# meta_cfg = "cfg/combine9k.data"

net_cfg = "cfg/yolov2.cfg"
weights = "yolov2.weights"
meta_cfg = "cfg/coco.data"

net = dn.network(net_cfg, weights)
meta = dn.metadata(meta_cfg)


def draw_box(img, results):
    for box in results:
        x = box[2][0]
        y = box[2][1]
        box_width = box[2][2]
        box_height = box[2][3]
        x1 = int(x - 1 / 2 * box_width)
        y1 = int(y - 1 / 2 * box_height)
        x2 = int(x + 1 / 2 * box_width)
        y2 = int(y + 1 / 2 * box_height)

        img = cv2.putText(img, box[0], (x1, y1), cv2.FONT_HERSHEY_PLAIN, 1,