python - 使用保存的 pb 模型进行预测
问题描述
我使用以下代码训练并保存了一个模型:
history = model_R.fit([X_train1, X_train2], y_train,
validation_data=([X_test1, X_test2], y_test),
epochs=15,
batch_size=64,
verbose=2)
predicted = model_R.predict([X_test1, X_test2])
predicted = np.argmax(predicted, axis=1)
print(metrics.classification_report(y_test, predicted, digits=4))
model_R.save('C_Models/name')
我使用以下方法加载了没有错误的模型:
model = tf.keras.models.load_model('name')
但是,当我尝试通过以下方式使用此模型进行预测时:
predicted = model.predict([X_test1, X_test2])
predicted = np.argmax(predicted, axis=1)
print(metrics.classification_report(y_test, predicted, digits=4))
我收到此错误:
InvalidArgumentError Traceback (most recent call last)
<ipython-input-10-62d80c09b105> in <module>()
----> 1 predicted = model.predict([X_test1, X_test2])
2
3 predicted = np.argmax(predicted, axis=1)
4 print(metrics.classification_report(y_test, predicted, digits=4))
5 frames
/usr/local/lib/python3.7/dist-packages/tensorflow/python/eager/execute.py in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name)
58 ctx.ensure_initialized()
59 tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
---> 60 inputs, attrs, num_outputs)
61 except core._NotOkStatusException as e:
62 if name is not None:
InvalidArgumentError: indices[30,181] = 14073 is not in [0, 10327)
[[node Final_output/embedding_1/embedding_lookup (defined at <ipython-input-10-62d80c09b105>:1) ]] [Op:__inference_predict_function_33895]
我错过了什么 ??
解决方案
推荐阅读
- sublimetext3 - 折叠或折叠所有未选择的行以在崇高文本中进行多次编辑
- javascript - 我有一个从 API 获取的对象数组,其内容为字符串格式。如何将其转换为日期?
- firebase - 颤振:[错误:颤振/lib/ui/ui_dart_state.cc(199)]未处理的异常:'CustomException'的实例
- neo4j - CYPHER 中 SET 语句的正则表达式
- python - Python grpc-tools 在我安装后立即被声明为丢失
- swift - 无法在 Linux 上运行 Swift 创建的可执行文件
- oauth-2.0 - spring security - oauth2 userInfoEndpoint 没有调用
- windows - 是否可以使用 pg_upgrade 将 postgresql 从 9.4 升级到 13.3?
- word2vec - Word2Vec变换的直观理解
- ruby-on-rails - Dokku 运行命令未进入应用程序文件夹