From f1a2fef0e2fb7fa76ed00873842c118e02bad091 Mon Sep 17 00:00:00 2001 From: Yashesh Savani Date: Fri, 19 Jan 2018 13:47:33 +0530 Subject: [PATCH 1/2] Add files via upload --- predict.py | 69 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 43 insertions(+), 26 deletions(-) diff --git a/predict.py b/predict.py index 4e6727d75..62b66e756 100644 --- a/predict.py +++ b/predict.py @@ -1,5 +1,6 @@ #! /usr/bin/env python +from __future__ import print_function import argparse import os import cv2 @@ -9,9 +10,11 @@ from utils import draw_boxes from frontend import YOLO import json +import os +import os.path os.environ["CUDA_DEVICE_ORDER"]="PCI_BUS_ID" -os.environ["CUDA_VISIBLE_DEVICES"]="" +os.environ["CUDA_VISIBLE_DEVICES"]="0" argparser = argparse.ArgumentParser( description='Train and validate YOLO_v2 model on any dataset') @@ -54,45 +57,59 @@ def _main_(args): # Load trained weights ############################### - print weights_path + print (weights_path) yolo.load_weights(weights_path) ############################### # Predict bounding boxes ############################### - if image_path[-4:] == '.mp4': - video_out = image_path[:-4] + '_detected' + image_path[-4:] + ################## + #A for loop for every item in [images] folder.. + + for file in os.listdir(image_path): + + # Just Created another directory in output directory so input image and output image will be diffrentiated + + if (os.path.isfile(os.path.join(image_path,file))): - video_reader = cv2.VideoCapture(image_path) + output_path = os.path.join(image_path,'output') + if not os.path.exists(output_path): + os.mkdir(output_path) - nb_frames = int(video_reader.get(cv2.CAP_PROP_FRAME_COUNT)) - frame_h = int(video_reader.get(cv2.CAP_PROP_FRAME_HEIGHT)) - frame_w = int(video_reader.get(cv2.CAP_PROP_FRAME_WIDTH)) + if file[-4:] == '.mp4': + video_out = file[:-4] + '_detected' + file[-4:] - video_writer = cv2.VideoWriter(video_out, - cv2.VideoWriter_fourcc(*'MPEG'), - 50.0, - (frame_w, frame_h)) + video_reader = cv2.VideoCapture(os.path.join(image_path,file)) + + nb_frames = int(video_reader.get(cv2.CAP_PROP_FRAME_COUNT)) + frame_h = int(video_reader.get(cv2.CAP_PROP_FRAME_HEIGHT)) + frame_w = int(video_reader.get(cv2.CAP_PROP_FRAME_WIDTH)) - for i in tqdm(range(nb_frames)): - _, image = video_reader.read() - - boxes = yolo.predict(image) - image = draw_boxes(image, boxes, config['model']['labels']) + video_writer = cv2.VideoWriter(os.path.join(output_path,video_out), + cv2.VideoWriter_fourcc(*'MPEG'), + 50.0, + (frame_w, frame_h)) - video_writer.write(np.uint8(image)) + for i in tqdm(range(nb_frames)): + _, image = video_reader.read() + + boxes = yolo.predict(image) + image = draw_boxes(image, boxes, config['model']['labels']) - video_reader.release() - video_writer.release() - else: - image = cv2.imread(image_path) - boxes = yolo.predict(image) - image = draw_boxes(image, boxes, config['model']['labels']) + video_writer.write(np.uint8(image)) - print len(boxes), 'boxes are found' + video_reader.release() + video_writer.release() + else: + image = cv2.imread(os.path.join(image_path,file)) ### joined the file name with the path + boxes = yolo.predict(image) + image = draw_boxes(image, boxes, config['model']['labels']) - cv2.imwrite(image_path[:-4] + '_detected' + image_path[-4:], image) + print (len(boxes), 'boxes are found') + + new_file_name = file[:-4] + '_detected' + file[-4:] ####added new file name + cv2.imwrite(os.path.join(output_path, new_file_name),image) if __name__ == '__main__': args = argparser.parse_args() From d1f98e048f5a007894afa1b8f500f73e463cddac Mon Sep 17 00:00:00 2001 From: Yashesh Savani Date: Fri, 19 Jan 2018 13:53:14 +0530 Subject: [PATCH 2/2] Add files via upload