您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Keras(Tensorflow后端)错误-在图表中找不到在feed_devices或fetch_devices中指定的Tensor输入_1:0

Keras(Tensorflow后端)错误-在图表中找不到在feed_devices或fetch_devices中指定的Tensor输入_1:0

好吧,在经历了许多痛苦和折磨之后,我发现了以下内容

尽管模型具有Session和Graph,但在某些张量流方法中,仍使用认的Session和Graph。为了解决这个问题,我必须明确地说我想同时使用Session和Graph作为认值:

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

完整代码

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)
其他 2022/1/1 18:34:16 有430人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶