import collections


def split_class_instances(classnames):
  """Split sounds from the same class into separate classes.

  After splitting, we add a count number after instance number 1.
  For example original class names of ['cat', 'dog', 'cat'] will be returned
  as ['cat', 'dog', 'cat_2'].

  Args:
    classnames: list of classes.
  Returns:
    list of modified classnames.
  """
  classname_count = collections.defaultdict(int)
  new_classnames = []
  for classname in classnames:
    classname_count[classname] += 1
    if classname_count[classname] > 1:
      new_classnames.append(classname +
                            '_{}'.format(classname_count[classname]))
    else:
      new_classnames.append(classname)
  return new_classnames