Samsung Front Load Washer Overfilling!

I have a Samsung front loading washer that overflows when filling. The thing that has me puzzled, is that it doesn’t do it every time.
I’m leaning towards the water inlet valve, but why is it only overfilling once in a while. Also, the overfilling happens at the beginning of the cycle.
I need to fix the problem or I can never leave the house while the machine is running.
Any advice or fixes are greatly appreciated!

Thanks,

Bluerep