MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / create_tensor_data

Function create_tensor_data

tensorflow/lite/testing/generate_examples_lib.py:239–256  ·  view source on GitHub ↗

Build tensor data spreading the range [min_value, max_value).

(dtype, shape, min_value=-100, max_value=100)

Source from the content-addressed store, hash-verified

237
238
239def create_tensor_data(dtype, shape, min_value=-100, max_value=100):
240 """Build tensor data spreading the range [min_value, max_value)."""
241
242 if dtype in TF_TYPE_INFO:
243 dtype = TF_TYPE_INFO[dtype][0]
244
245 if dtype in (tf.float32, tf.float16):
246 value = (max_value-min_value)*np.random.random_sample(shape)+min_value
247 elif dtype in (tf.int32, tf.uint8, tf.int64, tf.int16):
248 value = np.random.randint(min_value, max_value+1, shape)
249 elif dtype == tf.bool:
250 value = np.random.choice([True, False], size=shape)
251 elif dtype == np.string_:
252 # Not the best strings, but they will do for some basic testing.
253 letters = list(string.ascii_uppercase)
254 return np.random.choice(letters, size=shape).astype(dtype)
255 return np.dtype(dtype).type(value) if np.isscalar(value) else value.astype(
256 dtype)
257
258
259def create_scalar_data(dtype, min_value=-100, max_value=100):

Callers 3

build_inputsFunction · 0.85
build_tflite_inputsFunction · 0.85
build_graphFunction · 0.85

Calls 2

typeMethod · 0.65
dtypeMethod · 0.45

Tested by

no test coverage detected