Exercise 8.8ii in Kechris Classical Descriptive Set Theory asks to prove that if $f\colon X\to Y$ is a continuous function between Polish spaces such that $f(X)$ is uncountable, then there is a Cantor set $C\subseteq X$ such $f\upharpoonright C$ is injective (this is one way to prove that $\mathbf{\Sigma}^1_1(Y)$ sets have the perfect set property).
I know how to build one such Cantor set by using a carefully constructed Cantor scheme on $X$, however the hints at the end of the book suggest showing that $\{K\in K(X)\mid f\upharpoonright K \text{ is injective}\}$ is a dense $G_\delta$ set in $K(X)$, the hyperspace of compact sets equipped with the Vietoris topology (this solves 8.8ii by combining it with 8.8i: the compact perfect sets are also a dense $G_\delta$ in $K(X)$).
It's not clear to me how to do this, hence my question: How do you prove that if $f\colon X\to Y$ is a continuous function between Polish spaces such that $f(X)$ is uncountable, then $\{K\in K(X)\mid f\upharpoonright K\text{ is injective}\}$ is a dense $G_\delta$ set in $K(X)$?