Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F85130926
data_utils.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
Thu, Sep 26, 23:54
Size
2 KB
Mime Type
text/x-python
Expires
Sat, Sep 28, 23:54 (2 d)
Engine
blob
Format
Raw Data
Handle
21132845
Attached To
R6590 project14
data_utils.py
View Options
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
'''
#method = random.randint(1,3)
for
p
in
range
(
0
,
len
(
traindata
)):
#loop of over each pedestrian
if
method
==
1
:
#change signs of x position
print
(
traindata
[
p
]
.
coords
,
'before'
)
traindata
[
p
]
.
coords
[:,
0
]
=
-
traindata
[
p
]
.
coords
[:,
0
]
print
(
traindata
[
p
]
.
coords
,
'after'
)
traindata
[
p
]
.
neighbors
[:,
0
]
=
-
traindata
[
p
]
.
neighbors
[:,
0
]
elif
method
==
2
:
#change signs og y position
traindata
[
p
]
.
neighbors
[:,
1
]
=
-
traindata
[
p
]
.
neighbors
[:,
1
]
#coords[:,1] = -coords[:,1]
else
:
#change both signs
traindata
[
p
]
.
coords
=
-
traindata
[
p
]
.
coords
traindata
[
p
]
.
neighbors
=
-
traindata
[
p
]
.
neighbors
return
traindata
def
getCoords
(
velocity
,
timestep
=
4
):
'''
Compute x and y coordinates given a velocity array
'''
x_pos
=
velocity
[:,
0
]
*
timestep
y_pos
=
velocity
[:,
1
]
*
timestep
return
x_pos
,
y_pos
Event Timeline
Log In to Comment