def __init__(self): self.anchors_path = './model_data/yolo_anchors.txt' self.classes_path = './model_data/coco_classes.txt' self.class_names = read_classes(self.classes_path) self.anchors = read_anchors(self.anchors_path) self.threshold = threshold self.ignore_thresh = ignore_thresh self.INPUT_SIZE = (Input_shape, Input_shape ) # fixed size or (None, None) self.is_fixed_size = self.INPUT_SIZE != (None, None)
def vehicle_detection_YOLO(self,img): #Read in the class names and anchor locations self.class_names = yolo_utils.read_class_names(self.class_path) self.anchors = yolo_utils.read_anchors(self.anchors_path) #Pre-process the incoming frame resized_img = cv2.resize(img,(416,416)) batch_img = resized_img/255. batch_img = np.expand_dims(batch_img, axis=0) #Perform the prediction n_classes = len(self.class_names) out_boxes, out_scores, out_classes = yolo_utils.YOLO_predict(img, batch_img, self.sess, self.model, self.anchors, n_classes) return out_boxes, out_scores, out_classes
def __init__(self): self.anchors_path = path + '/model/yolo_anchors.txt' self.COCO = False self.trainable = True args1 = sys.argv[2] if args1 == 'COCO': print("-----------COCO-----------") self.COCO = True self.classes_path = path + '/model/coco_classes.txt' self.trainable = False elif args1 == 'VOC': print("-----------VOC------------") self.classes_path = path + '/model/voc_classes.txt' elif args1 == 'boat': print("-----------boat-----------") self.classes_path = path + '/model/boat_classes.txt' # args = self.argument() # if args.COCO: # print("-----------COCO-----------") # self.COCO = True # self.classes_path = self.PATH + '/model/coco_classes.txt' # self.trainable = False # elif args.VOC: # print("-----------VOC------------") # self.classes_path = self.PATH + '/model/voc_classes.txt' # elif args.boat: # print("-----------boat-----------") # self.classes_path = self.PATH + '/model/boat_classes.txt' self.class_names = read_classes(self.classes_path) self.anchors = read_anchors(self.anchors_path) self.threshold = 0.5 # threshold self.ignore_thresh = ignore_thresh self.INPUT_SIZE = (Input_shape, Input_shape ) # fixed size or (None, None) self.is_fixed_size = self.INPUT_SIZE != (None, None) # LOADING SESSION... self.boxes, self.scores, self.classes, self.sess = self.load()
def __init__(self): self.anchors_path = anchors_path self.COCO = False self.trainable = True # self.args = self.argument() if args.COCO: print("-----------COCO-----------") self.COCO = True self.trainable = False else: print("----------{}-----------".format(dataset_name)) self.class_names = read_classes(dataset_class_file) self.anchors = read_anchors(self.anchors_path) self.threshold = threshold # threshold self.ignore_thresh = ignore_thresh self.INPUT_SIZE = (Input_shape, Input_shape ) # fixed size or (None, None) self.is_fixed_size = self.INPUT_SIZE != (None, None) # LOADING SESSION... self.boxes, self.scores, self.classes, self.sess = self.load()
from PIL import ImageFile ImageFile.LOAD_TRUNCATED_IMAGES = True import argparse import numpy as np import tensorflow as tf import time import os os.environ["CUDA_VISIBLE_DEVICES"] = visible_GPU np.random.seed(101) # PATH = path + '/yolo3' classes_data = read_classes(dataset_class_file) anchors = read_anchors(anchors_path) data_path_train = 'Do_not_use_for_now' data_path_valid = 'Do_not_use_for_now' data_path_test = 'Do_not_use_for_now' input_shape = (Input_shape, Input_shape) # multiple of 32 ######################################################################################################################## """ # Clear the current graph in each run, to avoid variable duplication # tf.reset_default_graph() """ print("Starting 1st session...") # Explicitly create a Graph object graph = tf.Graph() with graph.as_default():
colors = generate_colors(class_names) image = draw_boxes(image, out_scores, out_boxes, out_classes, class_names, colors) return image if __name__ == "__main__": sess = K.get_session() yolo_model = load_model("model_data/tiny-yolo.h5") #yolo_model.summary() class_names = read_classes("model_data/yolo_coco_classes.txt") anchors = read_anchors("model_data/yolo_anchors.txt") ''' # image detection image_file = "dog.jpg" image_path = "images/" image_shape = np.float32(cv2.imread(image_path + image_file).shape[:2]) yolo_outputs = yolo_head(yolo_model.output, anchors, len(class_names)) scores, boxes, classes = yolo_eval(yolo_outputs, image_shape=image_shape) out_scores, out_boxes, out_classes = image_detection(sess, image_path, image_file) ''' # video detection camera = cv2.VideoCapture(0) #camera.set(cv2.CAP_PROP_FRAME_WIDTH, 288) # 設計解析度