diff --git a/data_utils.py b/data_utils.py index 6e93547..b19b74a 100644 --- a/data_utils.py +++ b/data_utils.py @@ -1,90 +1,91 @@ import numpy as np import torch import random def computeVelocity(coords, timestep=4): ''' Compute speed of pedestrian at each timestep given its coordinates during the sequence timestep = 4 seconds by default (observations each 10 frames with a 2.5 framerate) Returns velocity vector (vx, vy) ''' npos = coords.size()[0] #number of observed positions velocity = np.zeros((npos,2)) x = coords[:,0] y = coords[:,1] for i in range(1, npos): velocity[i,0] = (x[i]-x[i-1])/timestep velocity[i,1] = (y[i]-y[i-1])/timestep velocity = torch.from_numpy(velocity) return velocity def getTargets(coords): ''' returns a target array for given coordinates for supervised training ''' targets = coords[1:] return targets def flipPosition(traindata,method): ''' Flips given coordinates of all pedestrian in traindata method: 1: change signs of x position (vertical symmetry) 2: change signs of y position (horizontal symmetry) 3: change signs of x and y positions ''' - print('call flipPosition') - #method = random.randint(1,3) + traindata_new=traindata for p in range(0, len(traindata)): #loop of over each pedestrian - traindata_new=traindata #print(traindata[p].coords) - if traindata_new[p].neighbors== None: + if traindata[p].neighbors is None: continue #print('coords unflipped') #print(traindata[p].coords) if method == 1: #change signs of x position - traindata_new[p].coords[:,0] = - traindata[p].coords[:,0] - traindata_new[p].neighbors[:,2] = - traindata[p].neighbors[:,2] - + #print('befor') + traindata[p].coords[:,0] = - traindata[p].coords[:,0] + traindata[p].neighbors[:,2] = - traindata[p].neighbors[:,2] + #print(traindata[p].coords) elif method == 2: - #change signs og y position - traindata_new[p].neighbors[:,3] = - traindata[p].neighbors[:,3] + #change signs of y position + traindata[p].coords[:,1] = - traindata[p].coords[:,1] + traindata[p].neighbors[:,3] = - traindata[p].neighbors[:,3] + #coords[:,1] = -coords[:,1] else: #change both signs - traindata_new[p].coords = - traindata[p].coords - traindata_new[p].neighbors[:,2:4] = - traindata[p].neighbors[:,2:4] + traindata[p].coords = - traindata[p].coords + traindata[p].neighbors[:,2:4] = - traindata[p].neighbors[:,2:4] - return traindata_new + return traindata def getCoords(velocity, init_coords, timestep = 4): ''' Compute x and y coordinates given a velocity array and the initial coordinates ''' count = 0; x_old = init_coords[:,0] y_old = init_coords[:,1] x_pos = [] y_pos = [] while count < velocity.size()[0]: x_new = velocity[:,0]*timestep + xold y_new = velocity[:,1]*timestep + yold x_pos += [x_new] y_pos += [y_new] x_old = x_new y_old = y_new count += 1 x_pos = torch.cat(x_pos,0) y_pos = torch.cat(y_pos,0) return x_pos, y_pos