  We prove that the theory of the $p$-adics ${\mathbb Q}_p$ admits elimination
of imaginaries provided we add a sort for ${\rm GL}_n({\mathbb Q}_p)/{\rm
GL}_n({\mathbb Z}_p)$ for each $n$. We also prove that the elimination of
imaginaries is uniform in $p$. Using $p$-adic and motivic integration, we
deduce the uniform rationality of certain formal zeta functions arising from
definable equivalence relations. This also yields analogous results for
definable equivalence relations over local fields of positive characteristic.
The appendix contains an alternative proof, using cell decomposition, of the
rationality (for fixed $p$) of these formal zeta functions that extends to the
subanalytic context.
  As an application, we prove rationality and uniformity results for zeta
functions obtained by counting twist isomorphism classes of irreducible
representations of finitely generated nilpotent groups; these are analogous to
similar results of Grunewald, Segal and Smith and of du Sautoy and Grunewald
for subgroup zeta functions of finitely generated nilpotent groups.
