dougsm / mvp_grasp

Multi-Viewpoint Picking (ICRA 2019)
BSD 3-Clause "New" or "Revised" License
205 stars 47 forks source link

`Weights sum to zero, can't be normalized` in grasp entropy node's update callback #17

Open aPonza opened 4 years ago

aPonza commented 4 years ago

Numpy returns this error:

Error processing request: Weights sum to zero, can't be normalized
['Traceback (most recent call last):
', '  File "/opt/ros/kinetic/lib/python2.7/dist-packages/rospy/impl/tcpros_service.py", line 625, in _handle_request
    response = convert_return_to_response(self.handler(request), self.response_class)
', '  File "/home/ap/mvp_ws/src/mvp_grasp/mvp_grasping/ros_nodes/grasp_entropy_node.py", line 172, in update_service_handler
    q_am_neigh_avg = np.average(q_am_neigh, weights=neighbour_weights, axis=0)
', '  File "/home/ap/.local/lib/python2.7/site-packages/numpy/lib/function_base.py", line 422, in average
    "Weights sum to zero, can't be normalized")
', "ZeroDivisionError: Weights sum to zero, can't be normalized
"]

What would be the ideal solution? I temporarily went with surrounding the call with a try/except:

try:
    q_am_neigh_avg = np.average(q_am_neigh, weights=neighbour_weights, axis=0)
except ZeroDivisionError:
    q_am_neigh_avg = [0, 0]

but:

dougsm commented 4 years ago

As you say, I think this is a symptom of a larger problem. This is only possible if there's not a single value stored anywhere in the histogram, as it implies that the maximum value is 0. This shouldn't be possible if the histogram has been updated with a grasp estimate.

HanwenCao commented 3 years ago

@aPonza Hi, I was wondering if you have figured it out? I am facing the same error

q_am_neigh_avg = np.average(q_am_neigh, weights=neighbour_weights, axis=0)
ZeroDivisionError: Weights sum to zero, can't be normalized
fkendlessly commented 2 years ago

HI, @HanwenCao,I encountered the same problem as you. Did you solve it?

HanwenCao commented 2 years ago

@fkendlessly Sorry man I do not have a perfect solution. One thing you could probably try is to bypass it. I think you can do grasping without that. But forgive me, that is all I can remember since it has been a long time.

fkendlessly commented 2 years ago

Thank you, i will try to solve it.