Occupancy map creation using positions

The name of the pictureThe name of the pictureThe name of the pictureClash 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))






share|improve this question





















  • Still no answer but I need your helps!!!
    – Baran Nama
    Jun 12 at 11:05
















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))






share|improve this question





















  • Still no answer but I need your helps!!!
    – Baran Nama
    Jun 12 at 11:05












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))






share|improve this question













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))








share|improve this question












share|improve this question




share|improve this question








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
















  • 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















active

oldest

votes











Your Answer




StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
);
);
, "mathjax-editing");

StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "196"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















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



































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes










 

draft saved


draft discarded


























 


draft saved


draft discarded














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













































































Popular posts from this blog

Greedy Best First Search implementation in Rust

Function to Return a JSON Like Objects Using VBA Collections and Arrays

C++11 CLH Lock Implementation