Hope this helps anyone facing same issue
To know exactly where has occurred, since the running program doesn't mention it as a error with line number
'NoneType' object has no attribute 'shape'
Make sure to add assert after loading the image/frame
For image 
image = cv2.imread('myimage.png')
assert not isinstance(image,type(None)), 'image not found'
For video
cap = cv2.VideoCapture(0)
    while(cap.isOpened()):
        # Capture frame-by-frame
        ret, frame = cap.read()
        if ret:
            assert not isinstance(frame,type(None)), 'frame not found'
Helped me solve a similar issue, in a long script