Keras (Tensorflow backend) Error - Tensor input_1:0, specified in either feed_devices or fetch_devices was not found in the Graph

tensor is not an element of this graph flask
invalid argument specified in either feed_devices or fetch_devices was not found in the graph
not found: container localhost does not exist.
tensor conv2d_5_input 0 specified in either feed_devices or fetch_devices was not found in the graph
tensor tenso is not an element of this graph
invalidargumenterror
keras cannot be interpreted as a tensor
valueerror invalid argument matrix passed to k function with tensorflow backend

When trying to predict using a simple model I've previously trained I get the following error:

Tensor input_1:0, specified in either feed_devices or fetch_devices was not found in the Graph

at line:

seatbelt_model.predict(image_arr, verbose=1)

in code:

from tensorflow import keras
import tensorflow as tf
import numpy as np

graph = tf.get_default_graph()

seatbelt_model = keras.models.load_model(filepath='./graphs/seatbelt_A_3_81.h5')

class SeatbeltPredictor:
    INPUT_SHAPE = (-1, 120, 160, 1)

    @staticmethod
    def predict_seatbelt(image_arr):
        with graph.as_default():
            image_arr = np.array(image_arr).reshape(SeatbeltPredictor.INPUT_SHAPE)
            predicted_labels = seatbelt_model.predict(image_arr, verbose=1)
            return predicted_labels

The model has the following shape:

input_layer = keras.layers.Input(shape=(IMAGE_HEIGHT, IMAGE_WIDTH, 1))
conv_0 = keras.layers.Conv2D(filters=32, kernel_size=[5, 5], activation=tf.nn.relu, padding="SAME")(input_layer)
pool_0 = keras.layers.MaxPool2D(pool_size=[2, 2], strides=2, padding="VALID")(conv_0)
conv_1 = keras.layers.Conv2D(filters=32, kernel_size=[5, 5], activation=tf.nn.relu, padding="SAME")(pool_0)
pool_1 = keras.layers.MaxPool2D(pool_size=[2, 2], strides=2, padding="VALID")(conv_1)
flat_0 = keras.layers.Flatten()(pool_1)
dense_0 = keras.layers.Dense(units=1024, activation=tf.nn.relu)(flat_0)
drop_0 = keras.layers.Dropout(rate=0.4, trainable=True)(dense_0)
dense_1 = keras.layers.Dense(units=2, activation=tf.nn.softmax)(drop_0)

If I run the following, I get a tensor result:

graph.get_tensor_by_name('input_1:0')
<tf.Tensor 'input_1:0' shape=(?, 120, 160, 1) dtype=float32>

The name of the first layer is input_1

image_arr is of shape (1, 120, 160, 1)

Tensorflow 1.12

Any ideas?

OK, after a lot of pain and suffering and diving into the bowels of tensorflow I found the following:

Although the model has a Session and Graph, in some tensorflow methods, the default Session and Graph are used. To fix this I had to explicity say that I wanted to use both my Session and my Graph as the default:

with session.as_default():
    with session.graph.as_default():

Full Code:

from tensorflow import keras
import tensorflow as tf
import numpy as np
import log

config = tf.ConfigProto(
    device_count={'GPU': 1},
    intra_op_parallelism_threads=1,
    allow_soft_placement=True
)

config.gpu_options.allow_growth = True
config.gpu_options.per_process_gpu_memory_fraction = 0.6

session = tf.Session(config=config)

keras.backend.set_session(session)

seatbelt_model = keras.models.load_model(filepath='./seatbelt.h5')

SEATBEL_INPUT_SHAPE = (-1, 120, 160, 1)

def predict_seatbelt(image_arr):
    try:
        with session.as_default():
            with session.graph.as_default():
                image_arr = np.array(image_arr).reshape(SEATBEL_INPUT_SHAPE)
                predicted_labels = seatbelt_model.predict(image_arr, verbose=1)
                return predicted_labels
    except Exception as ex:
        log.log('Seatbelt Prediction Error', ex, ex.__traceback__.tb_lineno)

tensorflow.python.framework.errors_impl.InvalidArgumentError , Hi, i'm using keras and tensorflow for this code from flask import Flask, request, jsonify, specified in either feed_devices or fetch_devices was not found in the Graph #13901 axis=0) image = numpy.array(image) pred = model. predict_classes([image])[0] sign it shows the error keras.backend. set_session(session). Invalid argument: Tensor INPUT:0, specified in either feed_devices or fetch_devices was not found in the Graph praetorianer777 added the type:bug label May 2, 2020 tensorflow-butler bot assigned Saduf2019 May 2, 2020

Tensor zero_padding2d_1_input:0, specified in either feed_devices , Tensor zero_padding2d_1_input:0, specified in either feed_devices or fetch_devices was not found in the Graph #33744 This error happens on both Tensorflow models I run, so I assume it's a threading problem LP: create a config by gpu cpu backend if os.getenv('HAS_GPU', '0') == '1': config = tf. specified in either feed_devices or fetch_devices was not found in the Graph tensorflow “The specified object was not found in the store” exception “specified pipeline was not found” in amazon elastic transcoder; Codeigniter: The requested URL was not found in the server; The entity with name <entityName> was not found in the MetadataCache

I faced the same issue. I was working on TensorFlow 1.0 so I thought to upgrade it to the latest version (2.1) and then my code worked perfectly.

'Tensor (“something”) is not an element of this graph.' Error in Keras , Error in Keras using Tensorflow backend on Flask Web Server. Tensor Tensor( "dense_1_1/BiasAdd:0", shape=(?, 1), dtype=float32) is not an� The same test code as in the original (re-pasted for completeness) now yields InvalidArgumentError: Tensor input_1:0, specified in either feed_devices or fetch_devices was not found in the Graph. The full traceback is also provided below. Code to reproduce the issue

tf.keras.backend.clear_session, Calling clear_session() releases the global graph state that Keras is holding on to; print(new_layer.name) dense print(tf.keras.backend.learning_phase()) 0. tensorflow.python.framework.errors_impl.InvalidArgumentError: Tensor Input-Token:0, specified in either feed_devices or fetch_devices was not found in the Graph Copy link Quote reply Owner

Solve the problem of loading multiple Keras Model at the same time , _Callable.del of <tensorflow.python.client.session.BaseSession. To avoid below exception:Tensor embedding_1_input:0,. # specified in either feed_devices or fetch_devices was not found in the Graph. try: keras.backend. clear_session(). System information Have I written custom code (as opposed to using example directory): Yes, minimal example attached OS Platform and Distribution (e.g., Linux Ubuntu 16.04): macOS 10.14.5 TensorFlow backend (yes / no): yes TensorFlow ver

keras, This occurs in Keras 2.3.0 but not in Keras <= 2.2.5. comment this next line out, no error is raised. yt = model.predict(np.random.randn(5, Tensor input_1:0, specified in either feed_devices or fetch_devices was not found in the Graph . 0: /usr/src/.venv/lib/python3.7/site-packages/tensorflow/python/keras/backend.py in� I am trying to convert my Keras graph to a TF graph. I managed to run the provided tensorflow_serving examples, but I'm having issues to run my custom model. Here is my code: ` import tensorflow as tf from keras import backend as K from tensorflow.contrib.session_bundle import exporter def export_model_to_tf(model):

Comments
  • What do you get if you remove graph? Most of the tutorials I looked up online didn't touch the graph
  • If I don't use the default graph then I get "ValueError: Tensor Tensor("dense_1/Softmax:0", shape=(?, 2), dtype=float32) is not an element of this graph.".
  • I'm having a similar error, I have tried your good approach, but I'm getting another error - see here: github.com/tensorflow/tensorflow/issues/33744