Occupancy map creation using positions
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
4
down vote
favorite
This code basically check whether a person is in the grid of another person.
The algorithm should check all possible 2-permutations of persons whether a person is in another person grid. In the first version. It was two for
loops. The outer one iterates all persons while the inner one iterates all persons for the selected person in the outer for
loop.
I changed the code by building and iterating on permutations of persons and using numpy array (original data is pytorch Variable). It got improved 10 times but I'm still looking for further improvements.
mnp = len(pedlist_seq)
#print(pedlist_seq)
#print(lookup_seq)
width, height = dimensions[0], dimensions[1]
#print("width: ",width,"height: ",height)
frame_mask = np.zeros((mnp, mnp, grid_size**2))
frame_np = frame.data.numpy()
#print("frame: ", frame)
width_bound, height_bound = (neighborhood_size/(width*1.0)), (neighborhood_size/(height*1.0))
#width_bound, height_bound = (neighborhood_size/(width*1.0))*2, (neighborhood_size/(height*1.0))*2
#print("weight_bound: ", width_bound, "height_bound: ", height_bound)
list_indices = list(range(0, mnp))
for real_frame_index, other_real_frame_index in itertools.permutations(list_indices, 2):
current_x, current_y = frame_np[real_frame_index, 0], frame_np[real_frame_index, 1]
width_low, width_high = current_x - width_bound/2, current_x + width_bound/2
height_low, height_high = current_y - height_bound/2, current_y + height_bound/2
other_x, other_y = frame_np[other_real_frame_index, 0], frame_np[other_real_frame_index, 1]
#if (other_x >= width_high).all() or (other_x < width_low).all() or (other_y >= height_high).all() or (other_y < height_low).all():
if (other_x >= width_high) or (other_x < width_low) or (other_y >= height_high) or (other_y < height_low):
# Ped not in surrounding, so binary mask should be zero
#print("not surrounding")
continue
# If in surrounding, calculate the grid cell
cell_x = int(np.floor(((other_x - width_low)/width_bound) * grid_size))
cell_y = int(np.floor(((other_y - height_low)/height_bound) * grid_size))
#print("cell_x: ", cell_x, "cell_y: ", cell_y)
if cell_x >= grid_size or cell_x < 0 or cell_y >= grid_size or cell_y < 0:
continue
# Other ped is in the corresponding grid cell of current ped
frame_mask[real_frame_index, other_real_frame_index, cell_x + cell_y*grid_size] = 1
#print("frame mask shape %s"%str(frame_mask.shape))
python performance numpy
add a comment |Â
up vote
4
down vote
favorite
This code basically check whether a person is in the grid of another person.
The algorithm should check all possible 2-permutations of persons whether a person is in another person grid. In the first version. It was two for
loops. The outer one iterates all persons while the inner one iterates all persons for the selected person in the outer for
loop.
I changed the code by building and iterating on permutations of persons and using numpy array (original data is pytorch Variable). It got improved 10 times but I'm still looking for further improvements.
mnp = len(pedlist_seq)
#print(pedlist_seq)
#print(lookup_seq)
width, height = dimensions[0], dimensions[1]
#print("width: ",width,"height: ",height)
frame_mask = np.zeros((mnp, mnp, grid_size**2))
frame_np = frame.data.numpy()
#print("frame: ", frame)
width_bound, height_bound = (neighborhood_size/(width*1.0)), (neighborhood_size/(height*1.0))
#width_bound, height_bound = (neighborhood_size/(width*1.0))*2, (neighborhood_size/(height*1.0))*2
#print("weight_bound: ", width_bound, "height_bound: ", height_bound)
list_indices = list(range(0, mnp))
for real_frame_index, other_real_frame_index in itertools.permutations(list_indices, 2):
current_x, current_y = frame_np[real_frame_index, 0], frame_np[real_frame_index, 1]
width_low, width_high = current_x - width_bound/2, current_x + width_bound/2
height_low, height_high = current_y - height_bound/2, current_y + height_bound/2
other_x, other_y = frame_np[other_real_frame_index, 0], frame_np[other_real_frame_index, 1]
#if (other_x >= width_high).all() or (other_x < width_low).all() or (other_y >= height_high).all() or (other_y < height_low).all():
if (other_x >= width_high) or (other_x < width_low) or (other_y >= height_high) or (other_y < height_low):
# Ped not in surrounding, so binary mask should be zero
#print("not surrounding")
continue
# If in surrounding, calculate the grid cell
cell_x = int(np.floor(((other_x - width_low)/width_bound) * grid_size))
cell_y = int(np.floor(((other_y - height_low)/height_bound) * grid_size))
#print("cell_x: ", cell_x, "cell_y: ", cell_y)
if cell_x >= grid_size or cell_x < 0 or cell_y >= grid_size or cell_y < 0:
continue
# Other ped is in the corresponding grid cell of current ped
frame_mask[real_frame_index, other_real_frame_index, cell_x + cell_y*grid_size] = 1
#print("frame mask shape %s"%str(frame_mask.shape))
python performance numpy
Still no answer but I need your helps!!!
â Baran Nama
Jun 12 at 11:05
add a comment |Â
up vote
4
down vote
favorite
up vote
4
down vote
favorite
This code basically check whether a person is in the grid of another person.
The algorithm should check all possible 2-permutations of persons whether a person is in another person grid. In the first version. It was two for
loops. The outer one iterates all persons while the inner one iterates all persons for the selected person in the outer for
loop.
I changed the code by building and iterating on permutations of persons and using numpy array (original data is pytorch Variable). It got improved 10 times but I'm still looking for further improvements.
mnp = len(pedlist_seq)
#print(pedlist_seq)
#print(lookup_seq)
width, height = dimensions[0], dimensions[1]
#print("width: ",width,"height: ",height)
frame_mask = np.zeros((mnp, mnp, grid_size**2))
frame_np = frame.data.numpy()
#print("frame: ", frame)
width_bound, height_bound = (neighborhood_size/(width*1.0)), (neighborhood_size/(height*1.0))
#width_bound, height_bound = (neighborhood_size/(width*1.0))*2, (neighborhood_size/(height*1.0))*2
#print("weight_bound: ", width_bound, "height_bound: ", height_bound)
list_indices = list(range(0, mnp))
for real_frame_index, other_real_frame_index in itertools.permutations(list_indices, 2):
current_x, current_y = frame_np[real_frame_index, 0], frame_np[real_frame_index, 1]
width_low, width_high = current_x - width_bound/2, current_x + width_bound/2
height_low, height_high = current_y - height_bound/2, current_y + height_bound/2
other_x, other_y = frame_np[other_real_frame_index, 0], frame_np[other_real_frame_index, 1]
#if (other_x >= width_high).all() or (other_x < width_low).all() or (other_y >= height_high).all() or (other_y < height_low).all():
if (other_x >= width_high) or (other_x < width_low) or (other_y >= height_high) or (other_y < height_low):
# Ped not in surrounding, so binary mask should be zero
#print("not surrounding")
continue
# If in surrounding, calculate the grid cell
cell_x = int(np.floor(((other_x - width_low)/width_bound) * grid_size))
cell_y = int(np.floor(((other_y - height_low)/height_bound) * grid_size))
#print("cell_x: ", cell_x, "cell_y: ", cell_y)
if cell_x >= grid_size or cell_x < 0 or cell_y >= grid_size or cell_y < 0:
continue
# Other ped is in the corresponding grid cell of current ped
frame_mask[real_frame_index, other_real_frame_index, cell_x + cell_y*grid_size] = 1
#print("frame mask shape %s"%str(frame_mask.shape))
python performance numpy
This code basically check whether a person is in the grid of another person.
The algorithm should check all possible 2-permutations of persons whether a person is in another person grid. In the first version. It was two for
loops. The outer one iterates all persons while the inner one iterates all persons for the selected person in the outer for
loop.
I changed the code by building and iterating on permutations of persons and using numpy array (original data is pytorch Variable). It got improved 10 times but I'm still looking for further improvements.
mnp = len(pedlist_seq)
#print(pedlist_seq)
#print(lookup_seq)
width, height = dimensions[0], dimensions[1]
#print("width: ",width,"height: ",height)
frame_mask = np.zeros((mnp, mnp, grid_size**2))
frame_np = frame.data.numpy()
#print("frame: ", frame)
width_bound, height_bound = (neighborhood_size/(width*1.0)), (neighborhood_size/(height*1.0))
#width_bound, height_bound = (neighborhood_size/(width*1.0))*2, (neighborhood_size/(height*1.0))*2
#print("weight_bound: ", width_bound, "height_bound: ", height_bound)
list_indices = list(range(0, mnp))
for real_frame_index, other_real_frame_index in itertools.permutations(list_indices, 2):
current_x, current_y = frame_np[real_frame_index, 0], frame_np[real_frame_index, 1]
width_low, width_high = current_x - width_bound/2, current_x + width_bound/2
height_low, height_high = current_y - height_bound/2, current_y + height_bound/2
other_x, other_y = frame_np[other_real_frame_index, 0], frame_np[other_real_frame_index, 1]
#if (other_x >= width_high).all() or (other_x < width_low).all() or (other_y >= height_high).all() or (other_y < height_low).all():
if (other_x >= width_high) or (other_x < width_low) or (other_y >= height_high) or (other_y < height_low):
# Ped not in surrounding, so binary mask should be zero
#print("not surrounding")
continue
# If in surrounding, calculate the grid cell
cell_x = int(np.floor(((other_x - width_low)/width_bound) * grid_size))
cell_y = int(np.floor(((other_y - height_low)/height_bound) * grid_size))
#print("cell_x: ", cell_x, "cell_y: ", cell_y)
if cell_x >= grid_size or cell_x < 0 or cell_y >= grid_size or cell_y < 0:
continue
# Other ped is in the corresponding grid cell of current ped
frame_mask[real_frame_index, other_real_frame_index, cell_x + cell_y*grid_size] = 1
#print("frame mask shape %s"%str(frame_mask.shape))
python performance numpy
edited Jun 9 at 1:14
Jamalâ¦
30.1k11114225
30.1k11114225
asked Jun 8 at 15:11
Baran Nama
212
212
Still no answer but I need your helps!!!
â Baran Nama
Jun 12 at 11:05
add a comment |Â
Still no answer but I need your helps!!!
â Baran Nama
Jun 12 at 11:05
Still no answer but I need your helps!!!
â Baran Nama
Jun 12 at 11:05
Still no answer but I need your helps!!!
â Baran Nama
Jun 12 at 11:05
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f196121%2foccupancy-map-creation-using-positions%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Still no answer but I need your helps!!!
â Baran Nama
Jun 12 at 11:05