python - tf.keras.estimator.model_to_estimator 与 Tf.Hub 故障
问题描述
我需要将模型转换为处理 B64 图像而不是我正在使用的 JSONtf.keras.estimator.model_to_estimator
tf-nightly version:
Version: 1.15.0-dev20190714
Eager mode: True
Hub version: 0.5.0
GPU is available
基于本教程
我使用 tf.Hub 层创建了一个 Keras 模型:
https://tfhub.dev/google/tf2-preview/mobilenet_v2/feature_vector/4
转换为估计器:
estimator = tf.keras.estimator.model_to_estimator(
keras_model_path=h5_model_path,
custom_objects={'KerasLayer':hub.KerasLayer},
model_dir=tf_model_path)
我得到:
ValueError: Unknown layer: KerasLayer
型号总结:
model.summary()
Model: "sequential"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
keras_layer (KerasLayer) (None, 1280) 2257984
_________________________________________________________________
dense (Dense) (None, 5) 6405
=================================================================
Total params: 2,264,389
Trainable params: 6,405
Non-trainable params: 2,257,984
如果我通过 Keras 模型对象:
estimator = tf.keras.estimator.model_to_estimator(
keras_model=model,
custom_objects={'KerasLayer':hub.KerasLayer},
model_dir=tf_model_path)
我得到:
FailedPreconditionError: 2 root error(s) found.
(0) Failed precondition: Error while reading resource variable save_counter from Container: localhost. This could mean that the variable was uninitialized. Not found: Resource localhost/save_counter/N10tensorflow3VarE does not exist.
[[{{node save_counter/Read/ReadVariableOp}}]]
(1) Failed precondition: Error while reading resource variable save_counter from Container: localhost. This could mean that the variable was uninitialized. Not found: Resource localhost/save_counter/N10tensorflow3VarE does not exist.
[[{{node save_counter/Read/ReadVariableOp}}]]
[[MobilenetV2/expanded_conv_15/project/weights/Read/ReadVariableOp/_2363]]
0 successful operations.
0 derived errors ignored.
解决方案
推荐阅读
- laravel - 雄辩的 'with()' 返回 null
- r - 对具有最少条目的变量的排名求和
- java - 我可以从创建通用类对象的主方法访问插入数据吗
- tensorflow - 如果在数据集或每个数据集样本上运行,keras model.predict() 是否返回相同的值?
- r - 根据另一个数据框中的数据删除行?
- python - 如何使用 PDFplumber 在 pdf 文件中仅提取没有表格的文本?
- c# - 如何读取数据库表并将其显示在文本框中
- php - PrestaShop:创建特定价格后如何刷新购物车
- ios - 如何将一个数组中的单个项目附加到另一个数组?
- java - 检测特定块何时中断 [Spigot Plugin]