Just a reminder that this is /r/AskScience, so we expect top-level comments to be supportable by scientific sources, and they should not contain personal anecdotes.
I’m not sure about this specifically, but the most common way people find out whether animals and babies can differentiate between things is by using a habituation test.
A habituation test is an experimental procedure where you show images or objects to the subject over and over until they get habituated to it (like getting bored). The most common way to measure this habituation is by measuring how long they look at the object.
If you show a baby a picture of a cat thirty times in a row, they’re not going to stare at the thirtieth cat as long as they did the first one. But if you switch to a dog, they go right back to paying attention. That’s how we know that babies can tell the difference between some kinds of animals and objects.
If you wanted to objectively study whether dogs can tell how old a human is, this is probably the easiest way to do it. Show them pictures of older people until they stop paying attention, then switch to an infant.