keras-kinetics-i3d
keras-kinetics-i3d copied to clipboard
how to test model on my sample video
Hi dears, sorry for send email directly,
I'm interested in I3D method for action recognition and i cloned the github project "https://github.com/deepmind/kinetics-i3d" i want to test the model with my sample recorded video but don't know how to convert my *.mp4 video file (25fps rgb) to *rgb.npz and *flow.npz
could it possible to help or share me a reprocessing script file
best regards.
Hi, I wrote a simple script to apply on gif files:
#open the cricket shot video under data/ and convert it into a npy array of shape (1, num_frames, 224, 224, 3)
from PIL import Image from PIL import GifImagePlugin import numpy as np import os import re import shutil
#delete the folder test_files shutil.rmtree('test_files', ignore_errors=True) #create new empty one os.mkdir('test_files')
#select the .gif imageObject = Image.open('data/dog.gif')
print(imageObject.is_animated)
print(imageObject.n_frames)
Display individual frames from the loaded animated GIF file
for frame in range(0,imageObject.n_frames):
imageObject.seek(frame)
image_name = frame
resized_im = imageObject.resize((224,224))
resized_im.save('test_files/' + str(frame) + '.png')
#get the filenames with os file_list = os.listdir('test_files/') #sort maybe that matters
#to not take ds store
#ONLY needed when .DS store file in the dir, if craeted newly by script--> no .DS #file_list = file_list[1:]
file_list.sort(key=lambda f: int(re.sub('\D', '', f)))
#pipeline which can be easily adapted for my data in image files
#base of stack pic = Image.open('test_files/0.png') pic = pic.convert('RGB') pix = np.array(pic.getdata()).reshape(pic.size[0], pic.size[1], 3) video_array = np.reshape(pix, (1, 224, 224,3))
for file in range(1,len(file_list)):
pic = Image.open('test_files/' + file_list[file])
pic = pic.convert('RGB')
pix = np.array(pic.getdata()).reshape(pic.size[0], pic.size[1], 3)
pix = np.reshape(pix, (1, 224, 224,3))
#stack all frame arrays or better concatenate
video_array = np.concatenate((video_array, pix))
def convert_pixel_value(pixel_value):
converted = ((pixel_value-128)/128) * 1
return converted
video_array = convert_pixel_value(video_array)
frames = (np.shape(video_array))[0]
np.save('data/input_array.npy', video_array)
video_array = np.reshape(video_array, (1, frames, 224, 224, 3))