# "Neural Networks" example doesn't work

**URL:** <https://discourse.edwardlib.org/t/neural-networks-example-doesnt-work/587>\
**Category:** General\
**Created:** [January 13, 2018, 3:42am UTC](https://discourse.edwardlib.org/t/neural-networks-example-doesnt-work/587 "2018-01-13T03:42:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jim](https://avatars.discourse-cdn.com/v4/letter/j/ac91a4/32.png) [@jim](https://discourse.edwardlib.org/u/jim)\
**Post date:** [January 13, 2018, 3:42am UTC](https://discourse.edwardlib.org/t/neural-networks-example-doesnt-work/587/1 "2018-01-13T03:42:18Z")

</div>

Hello All,

I am attempting to use a keras neural net in one of my Edward models, and running into trouble. Essentially I am taking a keras `Model` and trying to apply it to an Edward `RandomVariable`, which doesn’t seem to work.

From the documentation [here](http://edwardlib.org/api/model-compositionality) this would be achieved simply:

```
from edward.models import Bernoulli, Normal
from keras.layers import Dense

z = Normal(loc=tf.zeros([N, d]), scale=tf.ones([N, d]))
h = Dense(256, activation='relu')(z)
x = Bernoulli(logits=Dense(28 * 28)(h))

```

however when I try I get the following error:

```
ValueError: Layer dense_1 was called with an input that isn't a symbolic tensor. Received type: <class 'abc.Normal'>. Full input: [<ed.RandomVariable 'Normal/' shape=(10, 4) dtype=float32>]. All inputs to the layer should be tensors.

```

It seems that `keras` doesn’t play nice with `edward`. Is there a work around?

Thanks!

---

<div class="post-metadata">

**Author:** ![bkayalibay](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.edwardlib.org/bkayalibay/32/223_2.png) [@bkayalibay](https://discourse.edwardlib.org/u/bkayalibay)\
**Post date:** [January 14, 2018, 1:23am UTC](https://discourse.edwardlib.org/t/neural-networks-example-doesnt-work/587/2 "2018-01-14T01:23:52Z")

</div>

You need to call `Dense` this way:

```python
h = Dense(256, activation='relu')(z.value())

```

Keras layers stopped accepting instances of `ed.RandomVariable` as input starting with version 2.0.5 ([here](https://github.com/keras-team/keras/issues/6979) is an issue about that).

---

<div class="post-metadata">

**Author:** ![jim](https://avatars.discourse-cdn.com/v4/letter/j/ac91a4/32.png) [@jim](https://discourse.edwardlib.org/u/jim)\
**Post date:** [January 14, 2018, 3:35am UTC](https://discourse.edwardlib.org/t/neural-networks-example-doesnt-work/587/3 "2018-01-14T03:35:05Z")

</div>

Awesome, thanks. This is also the solution in my applcation where I am calling a keras `Model`. Thanks @bkayalibay!
