TensorFlow RuntimeError:在SavedModel中找不到与标签服务相关联的MetaGraphDef

时间:2018-09-06 17:43:25

标签: python tensorflow

当我使用simple_save保存模型时,尝试加载模型时出现运行时错误。

要保存的代码是:

session = Session()
inputs = tf.placeholder(dtype=tf.float32, shape=(None, height, width, in_channel_size), name='input_img')
model = Some_Model(inputs, num_classes=no_of_defects, is_training=False)
logits, _ = model.build_model()
predictor = tf.nn.softmax(self.logits, name='logits_to_softmax')
feed_dict = {inputs: inputs}
prediction_probabilities = session.run(self.predictor, feed_dict=feed_dict)

tf.saved_model.simple_save(self.session, path,
                               inputs={"inputs" : self.inputs},
                               outputs={"predictor": self.predictor})

要加载的代码是:

tf.saved_model.loader.load(session, tag_constants.SERVING, path)

出现错误:

RuntimeError: MetaGraphDef associated with tags serve could not be found in SavedModel. To inspect available tag-sets in the SavedModel, please use the SavedModel CLI: `saved_model_cli`

我跑步时

saved_model_cli show --dir path --tag_set serve --signature_def serving_default

我明白了

The given SavedModel SignatureDef contains the following input(s):
  inputs['inputs'] tensor_info:
      dtype: DT_FLOAT
      shape: (-1, 512, 1024, 8)
      name: input_img:0
The given SavedModel SignatureDef contains the following output(s):
  outputs['predictor'] tensor_info:
      dtype: DT_FLOAT
      shape: (-1, 512, 1024, 25)
      name: logits_to_softmax:0
Method name is: tensorflow/serving/predict

我在做什么错了?

1 个答案:

答案 0 :(得分:4)

问题在于加载调用。应该是:

int main (void)
{
  /* Start with the empty list */
  struct MP3* head = NULL;

  //Declare a global user input
  int userInput = 0;

  //Buffer and Len variables declared for use with fgets
  char buffer[BUFFERSIZE];
  int len = 0;


  //While loop to run the program until user wishes to exit
  while(userInput != 3)
 {
  //Welcome message explaining to the user what options do what. Also prompts them to select an option
  printf("Welcome to Collin's MP3 Storage Program!\n\nPlease enter 1 to add an MP3, 2 to print your list or 3 to exit\n\n Enter your choice now: ");

  //Receives the user input
  scanf ("%d", &userInput);

  if (userInput == 1)
  {
    //Declare temporary values to hold the user input data
    char* tempArtist;
    char* tempTitle;
    char* tempDate;
    int placeholder = 0;

    //Prompt the user to enter the song artist
    printf("\nEnter Artist Name: ");

    //If the user input is not null,
    if (fgets(buffer, BUFFERSIZE, stdin) != NULL)
    {
        //Sets the length of our len placeholder to the length of the string input by the user
        len = (int) strlen(buffer);
        //Marks the end of the artist string
        buffer[len - 1] = '\0';
        //Declares enough memory dynamically to hold the artist name in our tempvar
        tempArtist = (char *) malloc(len);
        //Copies the artist name that the user input from our buffer to our temp var
        strcpy(tempArtist, buffer);
    }

    //Prompt the user to enter the song name
    printf("\nEnter Song Name: ");

    //If the user input is not null,
    if (fgets(buffer, BUFFERSIZE, stdin) != NULL)
    {
        //Sets the length of our len placeholder to the length of the string input by the user
        len = (int) strlen(buffer);
        //Marks the end of the artist string
        buffer[len - 1] = '\0';
        //Declares enough memory dynamically to hold the artist name in our tempvar
        tempTitle = (char *) malloc(len);
        //Copies the artist name that the user input from our buffer to our temp var
        strcpy(tempTitle, buffer);
    }

    //Prompt the user to enter the song date
    printf("\nEnter Date Released: ");

    //If the user input is not null,
    if (fgets(buffer, BUFFERSIZE, stdin) != NULL)
    {
        //Sets the length of our len placeholder to the length of the string input by the user
        len = (int) strlen(buffer);
        //Marks the end of the artist string
        buffer[len - 1] = '\0';
        //Declares enough memory dynamically to hold the artist name in our tempvar
        tempDate = (char *) malloc(len);
        //Copies the artist name that the user input from our buffer to our temp var
        strcpy(tempDate, buffer);
    }

    //Promp the user for the runtime in seconds
    printf("\nPlease enter the runtime in seconds: ");
    //Scan for input and store it in placeholder
    scanf("%d", &placeholder);

    //Create the new MP3
    addMP3(&head, tempArtist, tempTitle, tempDate, placeholder);

    //Frees all of the memory
    free(tempArtist);
    free(tempTitle);
    free(tempDate);

  }

  else if (userInput == 2)
  {
      //Invoke print list on the refernece to the head
      printForward(head);
  }

  }

  //return 0 after exiting the while
  return 0;

}