mvp_grasp icon indicating copy to clipboard operation
mvp_grasp copied to clipboard

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

Open aPonza opened this issue 5 years ago • 5 comments

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:

  • I'm not 100% positive there is absolutely no grasp if the neighborhood doesn't have a non-null sum (and I suppose you do know);
  • it leads to two more warnings (which I can think about tomorrow):
/home/ap/mvp_ws/src/mvp_grasp/mvp_grasping/ros_nodes/grasp_entropy_node.py:263: RuntimeWarning: invalid value encountered in sqrt
  ret.velocity_cmd.linear.z = -1 * (np.sqrt(1 - diff[0]**2 - diff[1]**2))
/home/ap/mvp_ws/src/mvp_grasp/dougsm_helpers/src/dougsm_helpers/gridshow.py:25: RuntimeWarning: invalid value encountered in divide
  img = (img - img.min())/(img.max() - img.min())

aPonza avatar Feb 24 '20 17:02 aPonza

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.

dougsm avatar Mar 02 '20 04:03 dougsm

@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

HanwenCao avatar Jan 24 '21 12:01 HanwenCao

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

fkendlessly avatar Nov 21 '21 14:11 fkendlessly

@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.

HanwenCao avatar Nov 21 '21 15:11 HanwenCao

Thank you, i will try to solve it.

fkendlessly avatar Nov 23 '21 07:11 fkendlessly