keras icon indicating copy to clipboard operation
keras copied to clipboard

minval can be greater than maxval in tf.keras.initializers.RandomUniform

Open cheyennee opened this issue 3 years ago • 6 comments
trafficstars

minval should be less than maxval. However, when minval is greater than maxval, the code works.

import tensorflow as tf
results={}
try:
  minval = 10
  maxval = -6
  seed = 124
  arg_class = tf.keras.initializers.RandomUniform(minval=minval,maxval=maxval,seed=seed,)
  arg_input = [9,6,7,]
  results["res"] = arg_class(arg_input)
except Exception as e:
  results["err"] = "Error:"+str(e)

cheyennee avatar Aug 31 '22 09:08 cheyennee

@cheyennee, The output of the minval and maxval was working as expected in tf.keras.initializers.RandomUniform. Also we change the min and max values the output was different in both the cases. Kindly find the gist of it here.

tilakrayal avatar Sep 02 '22 11:09 tilakrayal

@tilakrayal In other API, when minval is greater than maxval, it will throw an exception. I dont know why tf.keras.initializers.RandomUniform doesnt throw an exception, although it works as expected.

cheyennee avatar Sep 02 '22 13:09 cheyennee

@cheyennee, Could you please provide the API doc link where it was mentioned that the exception was thrown. It helps to analyse the issue. Thank you!

tilakrayal avatar Sep 08 '22 11:09 tilakrayal

@tilakrayal doc. In documentation, minval is the lower bound of the range of random values and maxval is the upper bound of the range of random values. So, I think the lower bound should be less than upper.

cheyennee avatar Sep 08 '22 14:09 cheyennee

@gadagashwini, I was able to reproduce the issue on tensoflow v2.8, v2.9 and nightly. Kindly find the gist of it here.

tilakrayal avatar Sep 09 '22 10:09 tilakrayal

@gadagashwini @cheyennee Logically, yes it should throw an error. But i tried it multiple times and it initializes values in range [minval, maxval] or [maxval, minval] whichever holds. I would be happy to send a PR, in case we think it is required.

old-school-kid avatar Sep 24 '22 09:09 old-school-kid