Solved by vahvero in post #2 
              
              
                I have found the error. 
The classes "labels" should be [N] not [N , 1]. I had been stuck here for multiple days and now feel extremely stupid.