Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update kth.py #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions data/kth.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
import socket
import torch
from scipy import misc
from torch.utils.serialization import load_lua
from imageio import imread
# from torch.utils.serialization import load_lua
import torchfile

class KTH(object):

Expand All @@ -26,7 +28,8 @@ def __init__(self, train, data_root, seq_len = 20, image_size=64):

self.data= {}
for c in self.classes:
self.data[c] = load_lua('%s/%s/%s_meta%dx%d.t7' % (self.data_root, c, data_type, image_size, image_size))
self.data[c] = torchfile.load('%s/%s/%s_meta%dx%d.t7' % (self.data_root, c, data_type, image_size, image_size))
# self.data[c] = load_lua('%s/%s/%s_meta%dx%d.t7' % (self.data_root, c, data_type, image_size, image_size))


self.seed_set = False
Expand All @@ -38,17 +41,21 @@ def get_sequence(self):
c = self.classes[c_idx]
vid_idx = np.random.randint(len(self.data[c]))
vid = self.data[c][vid_idx]
seq_idx = np.random.randint(len(vid['files']))
if len(vid['files'][seq_idx]) - t >= 0:
seq_idx = np.random.randint(len(vid[b'files']))
if len(vid[b'files'][seq_idx]) - t >= 0:
break
dname = '%s/%s/%s' % (self.data_root, c, vid['vid'])
st = random.randint(0, len(vid['files'][seq_idx])-t)
# dname = '%s/%s/%s' % (self.data_root, c, vid[b'vid'])
dname = '%s/%s/%s' % (self.data_root, c, vid[b'vid'].decode())
# st = random.randint(0, len(vid[b'files'][seq_idx])-t)
st = random.randint(0, len(vid[b'files'][seq_idx])-t)


seq = []
for i in range(st, st+t):
fname = '%s/%s' % (dname, vid['files'][seq_idx][i])
im = misc.imread(fname)/255.
# fname = '%s/%s' % (dname, vid[b'files'][seq_idx][i])
fname = '%s/%s' % (dname, vid[b'files'][seq_idx][i].decode())
# im = misc.imread(fname)/255.
im = imread(fname)/255.
seq.append(im[:, :, 0].reshape(self.image_size, self.image_size, 1))
return np.array(seq)

Expand All @@ -62,4 +69,3 @@ def __getitem__(self, index):

def __len__(self):
return len(self.dirs)*36*5 # arbitrary