Question Device freezes and restarts

Hey guys , from past week I'm experiencing random freezes and restarts . I thoughts its my custom rom so I tried reverting back to stock but it didn't helped . I got restart even on the setup guide after flashing stock rom . After that I got restart while loading pictures in gallery . Anyone experienced this problem