输出的外部尺寸必须未知,“ Const:0”的外部尺寸为12

时间:2018-09-26 13:49:19

标签: python tensorflow classification google-cloud-ml

我已经使用retrain.py创建了分类模型。然后,我将模型部署到Google ml引擎中。它给出了以下错误

创建版本失败。模型验证失败:输出的外部尺寸必须未知,“ Const:0”的外部尺寸为12。有关如何导出Tensorflow SavedModel的更多信息,请参见https://www.tensorflow.org/api_docs/python/tf/saved_model StackOverflow建议更改输出张量尺寸

def export_model(sess,keys, architecture, saved_model_dir):
 print("reached export funct")
 if architecture == 'inception_v3':
   input_tensor = 'DecodeJpeg/contents:0'
 elif architecture.startswith('mobilenet_'):
   input_tensor = 'input:0'
 else:
   raise ValueError('Unknown architecture', architecture)
 in_image = sess.graph.get_tensor_by_name(input_tensor)
 inputs = {'image': tf.saved_model.utils.build_tensor_info(in_image)}

 out_classes = sess.graph.get_tensor_by_name('final_result:0')

 outputs = {'prediction': 
  tf.saved_model.utils.build_tensor_info(out_classes),
         'classes': 
  tf.saved_model.utils.build_tensor_info(tf.convert_to_tensor(list(keys))),}

 signature = tf.saved_model.signature_def_utils.build_signature_def(
  inputs=inputs,
  outputs=outputs,
  method_name=tf.saved_model.signature_constants.PREDICT_METHOD_NAME
  )
 print( 
  tf.saved_model.signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY)
 legacy_init_op = tf.group(tf.tables_initializer(), name='legacy_init_op')

 #  Save out the SavedModel.
 builder = tf.saved_model.builder.SavedModelBuilder(saved_model_dir)
 builder.add_meta_graph_and_variables(
 sess, [tf.saved_model.tag_constants.SERVING],
 signature_def_map={
   tf.saved_model.signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY: 
    signature
    },
    legacy_init_op=legacy_init_op)
 builder.save()

0 个答案:

没有答案