tf.keras.estimator.model_to_estimator出现Tf.Hub失败

时间:2019-07-15 17:03:44

标签: python tensorflow keras

我需要将模型转换为处理B64图像而不是JSON,我正在使用tf.keras.estimator.model_to_estimator

tf-nightly version:

Version:  1.15.0-dev20190714
Eager mode:  True
Hub version:  0.5.0
GPU is available

基于this教程

我使用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.

0 个答案:

没有答案