The reliable detection of atrial fibrillation (AF) is of great significance for monitoring disease progression and developing tailored care paths. In this work, we proposed a novel and robust method based on deep learning for the accurate detection of AF. Using RR interval sequences, a multiscale grouped convolutional neural network (MGNN) combined with self-attention was designed for automatic feature extraction, and AF and non-AF classification. An average accuracy of 97.07% was obtained in the 5-fold cross-validation. The generalization ability of the proposed MGNN was further independently tested on four other unseen datasets, and the accuracy was 92.23%, 96.86%, 94.23% and 95.91%. Moreover, comparison of the network structures indicated that the MGNN had not only better detection performance but also lower computational complexity. In conclusion, the proposed model is shown to be an efficient AF detector that has great potential for use in clinical auxiliary diagnosis and long-term home monitoring based on wearable devices.