2016-10-05 12:44:35 8 Comments

I'm trying to use Keras' model in "pure" TensorFlow (I want to use it in Android app). I've successfully exported Keras model to protobuf and imported it to Tensorflow. However running tensorflow model requires providing input and output tensors' names and I don't know how to find them. My model looks like this:

```
seq = Sequential()
seq.add(Convolution2D(32, 3, 3, input_shape=(3, 15, 15), name="Conv1"))
....
seq.add(Activation('softmax', name="Act4"))
seq.compile()
```

When I'm printing tensors in TensorFlow I can find:

```
Tensor("Conv1_W/initial_value:0", shape=(32, 3, 3, 3), dtype=float32)
Tensor("Conv1_W:0", dtype=float32_ref)
Tensor("Conv1_W/Assign:0", shape=(32, 3, 3, 3), dtype=float32_ref)
Tensor("Conv1_W/read:0", dtype=float32)
Tensor("Act4_sample_weights:0", dtype=float32)
Tensor("Act4_target:0", dtype=float32)
```

Hovewer, there are no tensors that have shape (3,15,15).

I've seen here that I can add "my_input_tensor" as input, hovewer I don't know which type is it - I've tried TensorFlow's and Keras' placeholders and they gave me this error:

```
/XXXXXXXXX/lib/python2.7/site-packages/keras/engine/topology.pyc in __init__(self, input, output, name)
1599 # check that x is an input tensor
1600 layer, node_index, tensor_index = x._keras_history
-> 1601 if len(layer.inbound_nodes) > 1 or (layer.inbound_nodes and layer.inbound_nodes[0].inbound_layers):
1602 cls_name = self.__class__.__name__
1603 warnings.warn(cls_name + ' inputs must come from '
AttributeError: 'NoneType' object has no attribute 'inbound_nodes'
```

### Related Questions

#### Sponsored Content

#### 25 Answered Questions

### [SOLVED] Tensorflow: how to save/restore a model?

**2015-11-17 14:37:26****mathetes****347292**View**544**Score**25**Answer- Tags: python tensorflow machine-learning model

#### 2 Answered Questions

### Combine keras functional api with tensorflow

**2018-06-01 22:19:35****lab_rat****786**View**1**Score**2**Answer- Tags: tensorflow keras

#### 2 Answered Questions

### [SOLVED] ValueError: Output tensors to a Model must be the output of a TensorFlow `Layer`

**2018-06-06 08:43:08****HienPham****15206**View**21**Score**2**Answer- Tags: python tensorflow machine-learning keras tensor

#### 2 Answered Questions

### How to set the input of a Keras layer of a functional model, with a Tensorflow tensor?

**2017-05-24 07:32:23****Tal****630**View**2**Score**2**Answer- Tags: tensorflow keras keras-layer

#### 1 Answered Questions

### [SOLVED] building keras Model ValueError

**2019-07-15 16:49:31****BetterEnglish****29**View**0**Score**1**Answer- Tags: python tensorflow keras tf.keras

#### 5 Answered Questions

### [SOLVED] Tensor is not an element of this graph; deploying Keras model

**2018-07-01 22:07:18****DataGuy****9466**View**24**Score**5**Answer- Tags: python tensorflow flask keras

#### 1 Answered Questions

### [SOLVED] Tensor conversion requested dtype string for Tensor with dtype float32 (lambda input)

**2019-04-05 04:21:34****Montana Burr****750**View**0**Score**1**Answer- Tags: python tensorflow keras tensorflow-hub

#### 1 Answered Questions

### [SOLVED] Input tensors to a Model must come from `tf.layers.Input` when I concatenate two models with Keras API on Tensorflow

**2018-08-11 01:52:29****user3368526****4447**View**1**Score**1**Answer- Tags: tensorflow keras

#### 1 Answered Questions

### [SOLVED] TensorFlow to Keras Tensor

**2018-02-23 21:22:47****user9200689****4117**View**3**Score**1**Answer- Tags: python tensorflow keras

## 2 comments

## @rahullak 2019-03-31 06:52:54

To get the input and output tensors of your Keras models, do the following:

The above assumes that there is only 1 input tensor and 1 output tensor. If you have more, then you would have to use the appropriate index to get those tensors.

Note that there is a difference between layer output shapes and tensor output shapes. The two are usually the same, but not always.

## @Daniel Möller 2017-09-05 22:10:43

Call a

`model.summary()`

in Keras to see all the layers.An input tensor will often be called

`input_1`

,`input_2`

, etc. See in the summary the correct name.When you use

`input_shape=(3,15,15)`

in Keras, you're actually using tensors that have shape`(None, 3, 15, 15)`

. Where None will be replaced by the batch size in training or prediction.Often, for these unknonw dimensions, you use

`-1`

, such as in`(-1, 3, 15, 15)`

. But I cannot assure you that it will work like this. It works perfectly for reshaping tensors, but for creating I've never tested.