zoukankan      html  css  js  c++  java
  • 解决在django中应用keras模型时出现的ValueError("Tensor %s is not an element of this graph." % obj)问题

    用keras训练好模型,再在django初始化加载模型,这个过程没有问题,但是在调用到模型执行model.predict()的时候就报错:

     raise ValueError("Tensor %s is not an element of this graph." % obj)
    ValueError: Tensor Tensor("dense_2/Softmax:0", shape=(?, 2), dtype=float32) is not an element of this graph.

    解决方法:

    在django中加载模型后,先执行一次model.predict()操作,之后的调用就不会出问题了

    model = load_model(filepath=model_path)
    y = model.predict(x)

    参考:https://zhuanlan.zhihu.com/p/27101000

  • 相关阅读:
    制作文件的备份
    文件的读写
    文件的打开与关闭
    文件操作介绍
    数据类型转换
    位运算
    进制
    函数使用注意事项
    匿名函数
     递归函数
  • 原文地址:https://www.cnblogs.com/bymo/p/8955009.html
Copyright © 2011-2022 走看看