There's no lib AFAIK, because it's a very complex problem. If you were to only calculate the download speed, how would you compare this to the app responsiveness ? The latter is eventually what is important to the user; download speed is only one factor in a more complex equation. Also, how would you react to temporary network disruptions or slugginess ? (fairly common on Mobile network), they do not necessarily imply a fallback onto lighter images..
It's a pandora's box in my view. I'd tend to design an app for the worst case scenario if I were you. Small images, compatible with good view quality, and bullet proof user-notifications when the ISO stack says that something went wrong (timeout, wrong url, no response from server etc...), meaningful transitions from low pic to high pic res, ability to cancel an ongoing request, progress bars etc..
When the user is notified about what's going on, he/she will avoid/understand edge cases situations, and will not blame on the app if something goes wrong.
Now, if you want to address the app performance paradigm, I've started to look into https://newrelic.com/docs/site/apdex (I have no stake into their business, it's provided as an option with my MBaas). Seems there are good things, but I haven't integrated any of their features yet.
good luck !