You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@mxnet.apache.org by GitBox <gi...@apache.org> on 2020/09/29 13:18:10 UTC

[GitHub] [incubator-mxnet] sfraczek removed a comment on issue #19235: question about function _get_optimal_threshold

sfraczek removed a comment on issue #19235:
URL: https://github.com/apache/incubator-mxnet/issues/19235#issuecomment-700688990


   I'm not experienced with Mxnet yet but I made an experiment comparing both functions and the **old version code** seems to not work properly or I am misunderstanding something. The new code seems to return results that look like they make sense.
   For array arr containing `[ 0.990018   -0.92912527  0.88925551  0.29950806  0.5652269   0.91779029 0.70329186  0.93344053  0.26962166  0.23452311]`
   the old returns:
   min: 0.0,
   max: 1.0,
   divergence: 0.012564257718622684
   threshold: 1.0
   
   the new  returns:
   min: -0.92912527
   max: 0.990018
   divergence: [0.] 
   threshold: [0.9338415]
   
   This is my test code:
   ```python
   @with_seed()
   def test_optimal_threshold():
       arr = np.array([0.990018, -0.92912527, 0.88925551, 0.29950806, 0.5652269, 0.91779029, 0.70329186, 0.93344053, 0.26962166, 0.23452311])
       num_bins = 8001
       num_quantized_bins=255
       min_val = np.min(arr)
       max_val = np.max(arr)
       th = max(abs(min_val), abs(max_val))
       hist, hist_edges = np.histogram(arr, bins=num_bins, range=(-th, th))
       print("\narr", arr)
       # print("hist", np.nonzero(hist))
   
       min_val1, max_val1, min_divergence, opt_th = mx.contrib.quant._get_optimal_threshold_old(mx.nd.array(hist), num_bins=num_bins, num_quantized_bins=num_quantized_bins)
       print("old", min_val1, max_val1, min_divergence, opt_th)
   
       quantized_dtype = 'int8'
       hist_data = (hist, hist_edges, min_val, max_val, max_val)
       min_val2, max_val2, threshold, divergence = mx.contrib.quant._get_optimal_threshold(hist_data, quantized_dtype, num_quantized_bins=num_quantized_bins)
       print("new", min_val2, max_val2, divergence, threshold)
   ```
   
   I hope this helps?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@mxnet.apache.org
For additional commands, e-mail: issues-help@mxnet.apache.org