def Top1Accuracy(predictions, recognition_solution):
  """Computes top-1 accuracy for recognition prediction.

  Note that test images without ground-truth are ignored.

  Args:
    predictions: Dict mapping test image ID to a dict with keys 'class'
      (integer) and 'score' (float).
    recognition_solution: Dict mapping test image ID to list of ground-truth
      landmark IDs.

  Returns:
    accuracy: Top-1 accuracy (float).
  """
  # Loop over test images in solution. If it has at least one class label, we
  # check if the predicion is correct.
  num_correct_predictions = 0
  num_test_images_with_ground_truth = 0
  for key, ground_truth in recognition_solution.items():
    if ground_truth:
      num_test_images_with_ground_truth += 1
      if key in predictions:
        if predictions[key]['class'] in ground_truth:
          num_correct_predictions += 1

  return num_correct_predictions / num_test_images_with_ground_truth