Memorizing the fretboard

What’s the most complete way to memorize? I’ve picked up most of the natural notes for playing from sheets or playing chords, but as soon I want play chord shapes in different positions I get lost pretty quickly and I have to count or check other notes to find the ones I’m looking for.

Is there a best exercise for this?