Skip to content

Commit

Permalink
Added gifs and things
Browse files Browse the repository at this point in the history
  • Loading branch information
ksanjeevan committed Jul 20, 2018
1 parent 8d7ad1d commit 73aa653
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Original paper and github: [YOLO9000: Better, Faster, Stronger](https://arxiv.or
- [h5py](http://www.h5py.org/)
- [opencv](https://pypi.org/project/opencv-python/)
- [python3.5](https://www.python.org/)

- [moviepy](https://zulko.github.io/moviepy/) (optional, gifs)
### Simple use
---
1. Download pretrained [model](https://drive.google.com/open?id=1khOgS8VD-paUD8KhjOLOzEXkzaXNAAMq) and place it in **dourflow/**.
Expand Down Expand Up @@ -192,7 +192,7 @@ Running:

`python3 dourflow.py genp -c config.json`

Will store your the bounding box priors wherever the path indicates in the config file under **config['config_path']['anchors']** with the prefix 'custom_' (so as to not overwrite accidentally).
Will store the custom bounding box priors wherever the path indicates in the config file under **config['config_path']['anchors']** with the prefix 'custom_' (so as to not overwrite accidentally).

##### Tensorboard

Expand Down
14 changes: 9 additions & 5 deletions net/netparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@
default='weights.h5')


argparser.add_argument(
'--gif',
help='video output stored as gif also',
action='store_true')


args = argparser.parse_args()


Expand Down Expand Up @@ -101,22 +107,20 @@ class YoloParams(object):

PREDICT_IMAGE = action


#Paths
TRAIN_IMG_PATH = config['train']['image_folder']
TRAIN_ANN_PATH = config['train']['annot_folder']

VALIDATION_IMG_PATH = config['valid']['image_folder']
VALIDATION_ANN_PATH = config['valid']['annot_folder']
VALIDATION_OUT_PATH = config['valid']['pred_folder']

STORE_GIF = args.gif

# Model
#IN_MODEL = config['config_path']['in_model']
IN_MODEL = args.model

assert os.path.isfile(IN_MODEL), "Pass valid input keras model."

OUT_MODEL_NAME = config['train']['out_model_name']

ARCH_FNAME = config['config_path']['arch_plotname']

# Classes
Expand Down
8 changes: 8 additions & 0 deletions net/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import copy
import cv2

from moviepy.editor import VideoFileClip



def mkdir_p(path):
Expand Down Expand Up @@ -230,6 +232,12 @@ def handle_empty_indexing(arr, idx):
return []


def generate_gif(filename):
outname = filename.split('.')[-2] + '.gif'
VideoFileClip(filename).write_gif(
outname,fps=20, program='ffmpeg', fuzz=3)
print('\n')


if __name__ == '__main__':

Expand Down
17 changes: 10 additions & 7 deletions yolov2.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from keras.optimizers import SGD, Adam, RMSprop

from net.utils import parse_annotation, mkdir_p, \
setup_logging, draw_boxes
setup_logging, draw_boxes, generate_gif

from net.netparams import YoloParams
from net.netloss import YoloLoss
Expand All @@ -23,8 +23,6 @@





class YoloV2(object):


Expand Down Expand Up @@ -107,9 +105,9 @@ def _video_params(self, name):
def video_inference(self, filename):

cap, size, video_len, fps = self._video_params(filename)

outname = filename.split('.')[0]+"_pred.mp4"
fourcc = cv2.VideoWriter_fourcc('m','p','4','v')
writer = cv2.VideoWriter(filename.split('.')[0]+"_pred.mp4", fourcc, fps, size)
writer = cv2.VideoWriter(outname, fourcc, fps, size)

for i in tqdm(range(video_len)):

Expand All @@ -127,13 +125,16 @@ def video_inference(self, filename):
writer.release()
cv2.destroyAllWindows()

if YoloParams.STORE_GIF: generate_gif(outname)



def cam_inference(self, fname):

cap, size, _, fps = self._video_params(0)

fourcc = cv2.VideoWriter_fourcc('m','p','4','v')
if fname: writer = cv2.VideoWriter("out.mp4", fourcc, fps, size)
if fname: writer = cv2.VideoWriter(fname, fourcc, 40, size)

while(cap.isOpened()):

Expand All @@ -150,7 +151,9 @@ def cam_inference(self, fname):
break

cap.release()
if fname: writer.release()
if fname:
writer.release()
if YoloParams.STORE_GIF: generate_gif(fname)
cv2.destroyAllWindows()


Expand Down

0 comments on commit 73aa653

Please sign in to comment.