# How to pass random value (not tensor) in tensorflow function as a parameter?

**URL:** <https://discuss.ai.google.dev/t/how-to-pass-random-value-not-tensor-in-tensorflow-function-as-a-parameter/29020>\
**Category:** General Discussion\
**Tags:** help\_request\
**Created:** [August 17, 2022, 3:00am UTC](https://discuss.ai.google.dev/t/how-to-pass-random-value-not-tensor-in-tensorflow-function-as-a-parameter/29020 "2022-08-17T03:00:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![urosjarc](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/urosjarc/32/11680_2.png) [@urosjarc](https://discuss.ai.google.dev/u/urosjarc)\
**Post date:** [August 17, 2022, 3:00am UTC](https://discuss.ai.google.dev/t/how-to-pass-random-value-not-tensor-in-tensorflow-function-as-a-parameter/29020/1 "2022-08-17T03:00:11Z")

</div>

I need help

Stackoverflow source: [tensorflow2.0 - Passing random value in tensorflow function as a parameter - Stack Overflow](https://stackoverflow.com/questions/73370248/passing-random-value-in-tensorflow-function-as-a-parameter/73372852#73372852)

I have code in my augmentation tf.data pipeline…

```auto
    # BLURE
    filter_size = tf.random.uniform(shape=[], minval=0, maxval=5)
    image = tfa.image.mean_filter2d(image, filter_shape=filter_size)

```

But I’m constantly getting error…

```auto
 TypeError: The `filter_shape` argument must be a tuple of 2 integers. Received: Tensor("filter_shape:0", shape=(), dtype=int32)

```

I tried getting static value from random tensorflow like this…

```auto
    # BLURE
    filter_size = tf.get_static_value(tf.random.uniform(shape=[], minval=0, maxval=5))
    image = tfa.image.mean_filter2d(image, filter_shape=(filter_size, filter_size))

```

But I get error…

```auto
TypeError: The `filter_shape` argument must be a tuple of 2 integers. Received: None

```

And this errors makes me sad ☹

I want to create augmentation pipeline for `tf.data` btw…

---

<div class="post-metadata">

**Author:** ![rcauvin](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/rcauvin/32/10360_2.png) [@rcauvin](https://discuss.ai.google.dev/u/rcauvin)\
**Post date:** [August 18, 2022, 4:09pm UTC](https://discuss.ai.google.dev/t/how-to-pass-random-value-not-tensor-in-tensorflow-function-as-a-parameter/29020/3 "2022-08-18T16:09:41Z")

</div>

Have you tried setting the type of the random values to integer?

```auto
filter_size = tf.random.uniform(shape=[2], minval=0, maxval=5, dtype=tf.int32)
image = tfa.image.mean_filter2d(image, filter_shape=filter_size)

```

or

```auto
filter_size = tf.get_static_value(tf.random.uniform(shape=[], minval=0, maxval=5, dtype=tf.int32))
image = tfa.image.mean_filter2d(image, filter_shape=(filter_size, filter_size))

```

---

<div class="post-metadata">

**Author:** ![urosjarc](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/urosjarc/32/11680_2.png) [@urosjarc](https://discuss.ai.google.dev/u/urosjarc)\
**Post date:** [August 18, 2022, 5:39pm UTC](https://discuss.ai.google.dev/t/how-to-pass-random-value-not-tensor-in-tensorflow-function-as-a-parameter/29020/4 "2022-08-18T17:39:30Z")

</div>

Yes I did but I get this for the first code…

```auto
TypeError: The `filter_shape` argument must be a tuple of 2 integers.
Received: Tensor("filter_shape:0", shape=(2,), dtype=int32)

```

And for the second…

```auto
ValueError: The `filter_shape` argument must be a tuple of 2 integers.
Received: (None, None) including element None of type <class 'NoneType'>

```

---

<div class="post-metadata">

**Author:** ![Chris\_Harry](https://d1dlmcr85iqnpo.cloudfront.net/user_avatar/discuss.ai.google.dev/chris_harry/32/15051_2.png) [@Chris\_Harry](https://discuss.ai.google.dev/u/Chris_Harry)\
**Post date:** [June 27, 2023, 12:26pm UTC](https://discuss.ai.google.dev/t/how-to-pass-random-value-not-tensor-in-tensorflow-function-as-a-parameter/29020/6 "2023-06-27T12:26:15Z")

</div>

First of all generate the value using a method like np.random from the Numpy library or any other suitable method then convert the value to tensorflow constant or placeholder. you can us tf.constant to create a constant or tf.placeholder() to create a placeholder.Constant are used for fixed the values, while placeholder are used for values which will be provided later during runtime. Regards.
