He won't have sex with me but hell masturbate

I don't get it. I told him that I really wish he would have sex with me more we've been together almost three years and have kids and have went from sex everyday to maybe twice a month in the last year. I bring it up to him and he says he hasn't even been thinking of sex then I catch him masturbating this morning. Cool so is he just not attracted to me anymore or what?