It now seems that some layers have a wrong shape so you would have to check the number of feature of the properly flattened tensor and make sure that the following layer uses the same number of features as its input.