Should I include funny pictures in my slides?
Human cognition is a strange thing, and I won't pretend I know it well enough to give you a guide, but I will suggest that you simply consider your audience and how you want them to move through the information.

A dense, heavy talk with few breaks will tire most audiences.

A light talk that doesn't require much thought will result in many people letting their mind wander.

A talk which carefully weaves the "story" with a variety of dense to light moments, may actually improve retention.

Adding levity in the form of a joke or humor, if the joke is very relevant to the talk, can actually increase retention, as long as it isn't too much of a distraction.  Placing it appropriately is key, though, and I wouldn't do it at the end, because that's what people will remember.  The last few sentences should be a quick summary of the talk and should be memorable.

Placing it in the middle, during a transition - for instance between the problem statement and the methodology - could be good, and allow a release of tension if the problem statement was pretty densely packed.

Starting off with it, as an into to the topic and a method to get attention is also a pretty good choice.

In all things, though, consider your audience first.  What is the journey you are taking them on, and when would be an appropriate point for a rest break, a transition, a wake-up, etc.