Skip to content

Commit

Permalink
add interface
Browse files Browse the repository at this point in the history
  • Loading branch information
multimodalitiesfor3dscenes committed Apr 7, 2017
1 parent d4fc813 commit 5789daf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion models/finetuned_resnet.py
@@ -1,7 +1,7 @@
import os
from keras.models import Model
from keras.layers import Dense, Flatten, Dropout
from models.resnet50 import ResNet50
from .resnet50 import ResNet50

N_CLASSES = 101
IMSIZE = (216, 216, 3)
Expand Down
22 changes: 10 additions & 12 deletions predict.py
@@ -1,8 +1,8 @@
import os
import numpy as np
from utils.UCF_utils import two_stream3_generator, two_stream18_generator
from models.two_stream import two_stream_model
from utils.OF_utils import stack_optical_flow
from .utils.UCF_utils import two_stream3_generator, two_stream18_generator
from .models.two_stream import two_stream_model
from .utils.OF_utils import stack_optical_flow
import cv2
import random
from scipy.misc import imresize
Expand Down Expand Up @@ -67,10 +67,7 @@ def predict_two_stream18_test():
print('test accuracy on', steps, 'examples is', float(correct_num) / steps)


def predict_single_video(video_path):
spatial_weights = '/Users/cjc/cv/ActionRecognition/data/finetuned_resnet_RGB_65.h5'
temporal_weights = '/Users/cjc/cv/ActionRecognition/data/temporal_cnn_42.h5'
model = two_stream_model(spatial_weights, temporal_weights)
def predict_single_video(model, video_path, top_num):
cap = cv2.VideoCapture(video_path)
video = list()
while cap.isOpened():
Expand All @@ -93,8 +90,7 @@ def predict_single_video(video_path):

two_stream_input = [single_frame, of_input]
preds = model.predict(two_stream_input)
top_3_types = decode_prediction(preds, top=3)
print('top-3: ', top_3_types)
return decode_prediction(preds, top=top_num)


def _pick_frames(video_sequence, num_frame):
Expand All @@ -112,14 +108,16 @@ def _pick_frames(video_sequence, num_frame):


def decode_prediction(preds, top=3):
index_dir = '/Users/cjc/cv/ActionRecognition/data/ucfTrainTestlist/classInd.txt'
index_dir = '/home/changan/ActionRecognition/data/ucfTrainTestlist/classInd.txt'
class_dict = dict()
with open(index_dir) as fo:
for line in fo:
class_index, class_name = line.split()
class_dict[int(class_index)-1] = class_name
top = np.argsort(preds)[0][-top:][::-1]
return [class_dict[x] for x in top]
print(preds)
print(top)
return [(class_dict[x], preds[0][x]) for x in top]


def preprocess_single_frame(frame):
Expand All @@ -138,4 +136,4 @@ def preprocess_single_frame(frame):
# predict_two_stream18_test()

# predict single video
predict_single_video(video_path='/Users/cjc/cv/ActionRecognition/data/v_BabyCrawling_g01_c01.mp4')
# predict_single_video(video_path='/Users/cjc/cv/ActionRecognition/data/v_BabyCrawling_g01_c01.mp4')

0 comments on commit 5789daf

Please sign in to comment.