ai2thor
ai2thor copied to clipboard
The question about the distance between the object and the agent
HI! This is my code:
############# from ai2thor.controller import Controller from ai2thor.util.metrics import path_distance from ai2thor.util.metrics import get_shortest_path_to_object_type
controller = Controller(scene="FloorPlan201",renderDepthImage=True) event = controller.step("Stand") b = event.metadata["objects"][6]["distance"] print(event.metadata["objects"][6]['objectType'],b) # 6 means a Laptop # 2.3176186084747314
postition = event.metadata["agent"]["position"] path = get_shortest_path_to_object_type(controller=controller,object_type="Laptop",initial_position=postition) a = path_distance(path) print(a) # 1.0606601717798212 #############
When I call these two methods to calculate the distance. The Euclidean distance is longer than the second way which is to measure distance. I fell very surprised. the first distance: 2.3176186084747314 the second distance: 1.0606601717798212
Refer to the paper here: https://arxiv.org/pdf/1807.06757.pdf I think the first way of calculating distance should be shorter than the second way.
So I want to ask what algorithm is used in the second calculation of the Shortest Path? and where can I view this algorithm? Thank you very much for your help.
I believe what is happening is that your first distance measurement is using the distance
metadata reported by objects. This distance
value is just the distance between the agent's position and that object's position. You can visualize what that might look like below.
Notably, this is different than the distance, or the length, of the shortest path to a given target object. The value returned by path_distance()
is the length of the path the agent must take to visibly see the object. I've visualized the range of vision the agent has with a dotted blue line centered around the agent in both of these images. Below you can see why the value of the shortest path distance could be lower than the actual distance to the object returned by event.metadata
because the event metadata does not consider things like visibility or environmental structures that may block the agent, it's just a measure of pure world relative distance between the object and the agent.
To summarize, the shortest path is the shortest path the agent must take to get to a position where the target object is visible, while the metadata distance for a specific object is just the absolute distance between the agent and the target object.
The exact function called to generate this path starts from here: https://github.com/allenai/ai2thor/blob/db856525b770e0ff5af38e9efa27ac0073221be3/unity/Assets/Scripts/BaseFPSAgentController.cs#L3675
I believe what is happening is that your first distance measurement is using the
distance
metadata reported by objects. Thisdistance
value is just the distance between the agent's position and that object's position. You can visualize what that might look like below.Notably, this is different than the distance, or the length, of the shortest path to a given target object. The value returned by
path_distance()
is the length of the path the agent must take to visibly see the object. I've visualized the range of vision the agent has with a dotted blue line centered around the agent in both of these images. Below you can see why the value of the shortest path distance could be lower than the actual distance to the object returned byevent.metadata
because the event metadata does not consider things like visibility or environmental structures that may block the agent, it's just a measure of pure world relative distance between the object and the agent.To summarize, the shortest path is the shortest path the agent must take to get to a position where the target object is visible, while the metadata distance for a specific object is just the absolute distance between the agent and the target object.
The exact function called to generate this path starts from here:
https://github.com/allenai/ai2thor/blob/db856525b770e0ff5af38e9efa27ac0073221be3/unity/Assets/Scripts/BaseFPSAgentController.cs#L3675
yeah, thank you for your response, i think i understand it.