Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F88652386
datareader_preprocessed.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Oct 19, 23:48
Size
3 KB
Mime Type
text/x-objective-c
Expires
Mon, Oct 21, 23:48 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
21803507
Attached To
R6590 project14
datareader_preprocessed.py
View Options
import
pickle
import
os
import
pickle
import
argparse
import
time
import
torch
from
torch.autograd
import
Variable
import
numpy
as
np
import
project.data_utils
as
du
# all_files = os.listdir("test/") # imagine you're one directory above test dir
# print(all_files) #
'''
Reads preprocessed data. For each pedestrian, the coordinates are normalized and the coordinates of pedestrians in same frames are expressed
relatively to them
'''
#import utils
def
DataPaths
():
'''
returns the path of all videos for each scene
DataPaths[0] = biwi
DataPaths[1] = crowds
DataPaths[2] = mot
DataPaths[3] = stanford
'''
#biwi datasets Project/preprocessed_data/biwi/biwi_hotel.txt_5.txt
biwi_list
=
os
.
listdir
(
'preprocessed_data/biwi'
)
#print(os.listdir('Project/preprocessed_data/biwi'))
#print(biwi_list, 'biwi list')
if
'Icon
\r
'
in
biwi_list
:
#remove the icon file
biwi_list
.
remove
(
'Icon
\r
'
)
biwi_files
=
np
.
array
(
biwi_list
)
#
biwi_paths
=
np
.
array
([
'preprocessed_data/biwi/'
+
x
for
x
in
biwi_files
])
#print(biwi_files,'biwi')
#crowds
crowds_list
=
os
.
listdir
(
'preprocessed_data/crowds'
)
if
'Icon
\r
'
in
crowds_list
:
#remove the icon file
crowds_list
.
remove
(
'Icon
\r
'
)
crowds_files
=
np
.
array
(
crowds_list
)
#
crowds_paths
=
np
.
array
([
'preprocessed_data/crowds/'
+
x
for
x
in
crowds_files
])
#mot
mot_list
=
os
.
listdir
(
'preprocessed_data/mot'
)
if
'Icon
\r
'
in
mot_list
:
#remove the icon file
mot_list
.
remove
(
'Icon
\r
'
)
mot_files
=
np
.
array
(
mot_list
)
#
mot_paths
=
np
.
array
([
'preprocessed_data/mot/'
+
x
for
x
in
mot_files
])
#stanford
stanford_list
=
os
.
listdir
(
'preprocessed_data/stanford'
)
if
'Icon
\r
'
in
stanford_list
:
#remove the icon file
stanford_list
.
remove
(
'Icon
\r
'
)
stanford_files
=
np
.
array
(
stanford_list
)
#
stanford_paths
=
np
.
array
([
'preprocessed_data/stanford/'
+
x
for
x
in
stanford_files
])
path_dataset
=
[
biwi_paths
,
crowds_paths
,
mot_paths
,
stanford_paths
]
return
path_dataset
class
Pedestrian
():
'''
Class of pedestrians, instanciated from data text files
Attributes:
frames: frames where the pedestrian appears
neighbors : other pedestrians in the frames
coords : coordinates of the pedestrian in each frame
neigh_coords: coordinates of the neighbors in each frame
'''
def
__init__
(
self
,
pedID
,
frames
,
coords
,
neighbors
,
velocity
):
self
.
pedID
=
pedID
self
.
frames
=
frames
self
.
coords
=
coords
self
.
neighbors
=
neighbors
self
.
velocity
=
velocity
def
getPedID
(
self
):
return
self
.
pedID
def
getFrames
(
self
):
return
self
.
frames
def
getCoords
(
self
):
return
self
.
coords
def
getNeighbors
(
self
):
return
self
.
neighbors
def
getVelocity
(
self
):
return
self
.
velocity
def
DataLoader
(
path_dataset
):
'''
Returns a list of "Pedestrian" objects for each dataset passed as arg
'''
datalist
=
[]
numpeds
=
len
(
path_dataset
)
for
directory
in
range
(
0
,
len
(
path_dataset
)):
data
=
np
.
genfromtxt
(
path_dataset
[
directory
],
dtype
=
'float'
)
pedID
=
data
[
0
,
1
]
ped_data
=
data
[
np
.
where
(
data
[:,
1
]
==
pedID
)]
frames
=
np
.
asarray
(
ped_data
[:,
0
])
coords
=
np
.
asarray
(
ped_data
[:,
2
:
4
])
print
(
dtype
(
coords
))
neighbors
=
data
[
np
.
where
(
data
[:,
1
]
!=
pedID
)]
velocity
=
du
.
computeVelocity
(
coords
)
current_ped
=
Pedestrian
(
pedID
,
frames
,
coords
,
neighbors
)
datalist
.
append
(
current_ped
)
#print('Number of frames: %f' %len(frameList))
print
(
'Number of pedestrians:
%f
'
%
numpeds
)
return
datalist
Event Timeline
Log In to Comment