栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

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

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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 kerasimport tensorflow as tfimport numpy as npimport logconfig = tf.ConfigProto(    device_count={'GPU': 1},    intra_op_parallelism_threads=1,    allow_soft_placement=True)config.gpu_options.allow_growth = Trueconfig.gpu_options.per_process_gpu_memory_fraction = 0.6session = 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)


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/645539.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号