From 47e29df3929477f7ea2e036e062a8eb90b5c97a3 Mon Sep 17 00:00:00 2001 From: Kiran Sanjeevan Date: Sun, 8 Jul 2018 19:45:42 -0700 Subject: [PATCH] More Webcam --- dourflow.py | 6 +++++- net/neteval.py | 36 ++++++++++++++++++++++++++++++++++-- net/netparams.py | 8 ++++++-- net/utils.py | 3 +++ 4 files changed, 48 insertions(+), 5 deletions(-) diff --git a/dourflow.py b/dourflow.py index abd9dd0..234e335 100644 --- a/dourflow.py +++ b/dourflow.py @@ -4,6 +4,8 @@ from yolov2 import YoloV2, YoloInferenceModel import os +from net.neteval import gen_anchors + # Add CPU option os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID" @@ -14,7 +16,9 @@ if YoloParams.WEIGHT_FILE: generate_model() - + elif YoloParams.GEN_ANCHORS_PATH: + pass + #gen_anchors(YoloParams.GEN_ANCHORS_PATH) else: YoloV2().run() diff --git a/net/neteval.py b/net/neteval.py index f4a3414..ad0915e 100644 --- a/net/neteval.py +++ b/net/neteval.py @@ -4,13 +4,45 @@ from net.netparams import YoloParams from net.netdecode import YoloOutProcess +from tqdm import tqdm import matplotlib.pyplot as plt import numpy as np import cv2, os import keras -from net.utils import draw_boxes, compute_iou, mkdir_p, yolo_normalize, mkdir_p, handle_empty_indexing +from net.utils import draw_boxes, compute_iou, mkdir_p, \ +yolo_normalize, mkdir_p, handle_empty_indexing, parse_annotation -from tqdm import tqdm + + + +''' +def exrtract_wh(img): + result = [] + pixel_height = img['height'] + pixel_width = img['width'] + + fact_pixel_grid_h = YoloParams.GRID_SIZE / pixel_height + fact_pixel_grid_w = YoloParams.GRID_SIZE / pixel_width + + for obj in img['object']: + grid_h = (obj['ymax'] - obj['ymin']) * fact_pixel_grid_h + grid_w = (obj['xmax'] - obj['xmin']) * fact_pixel_grid_w + + result.append( np.array(grid_h, grid_w) ) + + return result + +def gen_anchors(fname): + + imgs, _ = parse_annotation(ann_dir, img_dir) + + data_wh = [] + for img in imgs: + data_wh += exrtract_wh(img) + + c = AgglomerativeClustering(self.num_clusters, affinity='precomputed', linkage=self.c_type) + +''' diff --git a/net/netparams.py b/net/netparams.py index 783fac3..65fb4f7 100644 --- a/net/netparams.py +++ b/net/netparams.py @@ -72,15 +72,19 @@ class YoloParams(object): PREDICT_IMAGE = '' WEIGHT_FILE = '' WEBCAM_OUT = '' + GEN_ANCHORS_PATH = '' - if action == 'gen': + if action in ['genw', 'generate_weights']: assert args.weight_file, "Need to pass weight file if generating model." WEIGHT_FILE = args.weight_file elif action == 'cams': WEBCAM_OUT = 'cam_out.mp4' YOLO_MODE = 'cam' + elif action in ['genp', 'generate_priors']: + GEN_ANCHORS_PATH = 'new_anchors.png' + YOLO_MODE = 'genp' else: - if action == 'validate' or action == 'train' or action == 'cam': + if action in ['validate', 'train', 'cam']: YOLO_MODE = action else: if os.path.isdir(action): diff --git a/net/utils.py b/net/utils.py index ab48218..0b1fd16 100755 --- a/net/utils.py +++ b/net/utils.py @@ -206,6 +206,9 @@ def parse_annotation(ann_dir, img_dir, labels=[]): + + + def yolo_normalize(image): return image / 255.