Keras (Tensorflow backend) Error - Tensor input_1:0, specified in either feed_devices or fetch_devices was not found in the Graph
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)