def getY(filename, trainIDs, testIDs, predict): path = os.getcwd()+'/' IDDict = futil.LoadDictFromTxt(path+filename, 'vid') compressed = 'compressed' in filename #filepath = makePathMR(filename, '-mergerMinRanges') filepath = makeFullPath(filename, '-mergerRanges.txt') MR = np.loadtxt(filepath, dtype='int') Ytrain = np.array([]) #will have numTrain*numFrames rows and 1 column Ytest = np.array([]) if not numUsing == 0: MR = MR[:numUsing] for row in MR: YVID = np.ascontiguousarray(getYInner(row,IDDict[row[0]], predict, compressed)) if row[0] in trainIDs: Ytrain=append(Ytrain,YVID) #uses append because Y is small in memory print("Finished getting Y data for Merger with VID:",row[0]," and it is a training example") else: Ytest=append(Ytest,YVID) print("Finished getting Y data for Merger with VID:",row[0]," and it is a test example") return np.ascontiguousarray(Ytrain), np.ascontiguousarray(Ytest)
def getX(filename, trainIDs, testIDs, mean_centered): #filename="res/101_trajectories/aug_trajectories-0750am-0805am.txt" path = os.getcwd()+'/' compressed = 'compressed' in filename frameDict = futil.LoadDictFromTxt(path+filename, 'frame') print("Gotten frameDict",time.ctime()) dictOfGrids = futil.GetGridsFromFrameDict(frameDict, mean_centered, compressed) print("Gotten dictOfGrids",time.ctime()) #filepath = makePathMR(filename, '-mergerMinRanges') filepath = makeFullPath(filename, '-mergerRanges.txt') MR = np.loadtxt(filepath, dtype='int') '''MR=MergeRanges. MR[:,0]=merge ids, MR[:,1]=start frame, MR[:,2] = end''' print ("Done loading in getX", time.ctime()) start = getStartVals(filename) Xtrain = np.array([]) #will have numTrain*numFrames rows and size(grid)+1 columns Xtest = np.array([]) it = 0 trainEmpty = True testEmpty = True if not numUsing == 0: MR = MR[:numUsing] for row in MR: thisStart = start[it] XVID = sparse.csr_matrix(np.ascontiguousarray(getXInner(row, dictOfGrids,thisStart,frameDict, compressed))) if row[0] in trainIDs: if trainEmpty == True: Xtrain = XVID trainEmpty = False else: Xtrain = sparse.vstack((Xtrain,XVID))#,axis=0) print("Finished getting X data for Merger with VID:",row[0]," and it is a training example", time.ctime()) else: if testEmpty == True: Xtest = XVID testEmpty = False else: Xtest = sparse.vstack((Xtest,XVID))#np.append(Xtest,XVID,axis=0) print("Finished getting X data for Merger with VID:",row[0]," and it is a test example") it += 1 print(Xtrain.shape) return Xtrain, Xtest
def main(argv): frameDict = futil.LoadDictFromTxt( "res/Lankershim/aug_trajectories-0750am-0805am.txt", 'frame') futil.AnimateFrames(frameDict)