You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

部署NLP模型遇FileNotFoundError,pickle与.h5保存均报错求助

NLP模型部署FileNotFoundError问题解决

报错信息

FileNotFoundError: Unsuccessful TensorSliceReader constructor: Failed to find any matching files for ram://a603e930-4fda-4105-8554-7af5e5fc02f5/variables/variables
You may be trying to load on a different device from the computational device. Consider setting the experimental_io_device option in tf.saved_model.LoadOptions to the io_device such as '/job:localhost'

问题背景

先后使用pickle、.h5格式保存NLP模型,加载时均触发上述错误。

解决方法

  • 加载模型时指定experimental_io_device参数,强制使用本地设备读取文件:
    import tensorflow as tf
    
    load_options = tf.saved_model.LoadOptions(experimental_io_device='/job:localhost')
    model = tf.keras.models.load_model('你的模型文件路径.h5', options=load_options)
    
  • 重新完整保存模型:确保模型保存过程未中断,执行以下代码重新生成.h5文件:
    model.save('完整的模型保存路径.h5', save_format='h5')
    
  • 明确指定加载设备:若训练与加载设备不一致(如训练用GPU,加载用CPU),添加设备上下文:
    import tensorflow as tf
    
    load_options = tf.saved_model.LoadOptions(experimental_io_device='/job:localhost')
    with tf.device('/CPU:0'):
        model = tf.keras.models.load_model('你的模型文件路径.h5', options=load_options)
    

内容的提问来源于stack exchange,提问作者Karthik Bhandary

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 23:57:26