Skip to content

Commit

Permalink
input preprocess script added. lanenet connection added.
Browse files Browse the repository at this point in the history
  • Loading branch information
ynalcakan committed Sep 16, 2019
1 parent 50a0b7e commit 245957b
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 6 deletions.
22 changes: 17 additions & 5 deletions get_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
from keras.utils.np_utils import to_categorical
import random

#from lanenet_repo.tools import test_lanenet

ROOT_PATH = ''


def get_video_frames(src, fpv, frame_height, frame_width):
# print('reading video from', src)
cap = cv2.VideoCapture(src)
#filename = src.split('/')[3][:-4]

frames = []
if not cap.isOpened():
Expand All @@ -30,7 +33,6 @@ def get_video_frames(src, fpv, frame_height, frame_width):
rnd_frame = frames[rnd_idx]
rnd_frame = cv2.resize(rnd_frame,(224,224)) # Needed for Densenet121-2d

# Return fpv=10 frames
step = len(frames)//fpv

# get 16 frames from each half
Expand All @@ -46,6 +48,15 @@ def get_video_frames(src, fpv, frame_height, frame_width):
for af in avg_frames:
rsz_f = cv2.resize(af, (frame_width, frame_height))
avg_resized_frames.append(rsz_f)

# call lanenet for lane detection!
#avg_resized_lanenet_frames = []
#weights_path = '/home/yagiz/Sourcebox/git/T3D-keras/lanenet_repo/model/tusimple_lanenet_vgg/tusimple_lanenet_vgg.ckpt'
#counts = 0
#for image in avg_resized_frames:
# lanenet_frame = test_lanenet.test_lanenet(image, weights_path, filename, counts)
# counts += 1
# avg_resized_lanenet_frames.append(lanenet_frame)
return np.asarray(rnd_frame)/255.0,np.asarray(avg_resized_frames)


Expand All @@ -61,7 +72,6 @@ def get_video_and_label(index, data, frames_per_video, frame_height, frame_width
# print('Frame shape',frame.shape)
# print('Clip shape',clip.shape)


return frame, clip, behavior_class


Expand All @@ -86,9 +96,11 @@ def video_gen(data, frames_per_video, frame_height, frame_width, channels, num_c
i, data, frames_per_video, frame_height, frame_width)

# Appending them to existing batch
frame = np.append(frame, single_frame, axis=0)
clip = np.append(clip, single_clip, axis=0)

try:
frame = np.append(frame, single_frame, axis=0)
clip = np.append(clip, single_clip, axis=0)
except Exception as e:
print(e, single_frame.shape, single_clip.shape, frame.shape, clip.shape)
y_train = np.append(y_train, [behavior_class])
y_train = to_categorical(y_train, num_classes=num_classes)

Expand Down
29 changes: 29 additions & 0 deletions preprocess.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import os
import cv2
import numpy as np

def cutter(src):

cap = cv2.VideoCapture(src)

frames = []
if not cap.isOpened():
cap.open(src)
ret = True
while(True and ret):
# Capture frame-by-frame
ret, frame = cap.read()

frames.append(frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break

# When everything done, release the capture
cap.release()

croped_frames = []
for cf in frames:
rsz_f = cf[300:950, 0:1920] # cut unnecessary sky and car view
croped_frames.append(rsz_f)

return np.asarray(croped_frames)
2 changes: 1 addition & 1 deletion train_T3D_keras.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
FRAME_CHANNEL = 3
NUM_CLASSES = 2
BATCH_SIZE = 2
EPOCHS = 10
EPOCHS = 5
MODEL_FILE_NAME = 'T3D_saved_model.h5'


Expand Down

0 comments on commit 245957b

Please sign in to comment.