Code smell is the structural design defect that makes programs difficult to understand, maintain, and evolve. Existing works of code smell detection mainly focus on prevalent code smells, such as feature envy, god class, and long method. Few works have been done on detecting brain class/method. Furthermore, existing deep‐learning‐based approaches leverage the CNN model to improve accuracy by barely increasing the number of layers, which may cause a problem of gradient degradation. To this end, this paper proposes a novel approach called MARS to detect brain class/method. MARS improves the gradient degradation by employing an improved residual network. It increases the weight value of those important code metrics to label smelly samples by introducing a metric–attention mechanism. To support the training of MARS, a dataset called BrainCode is generated by extracting more than 270,000 samples from 20 real‐world applications. MARS is evaluated on BrainCode and compared to other machine‐learning‐based and deep‐learning‐based approaches. The experimental results demonstrate that the average accuracy of MARS is 2.01 % higher than that of the existing approaches, which improves state‐of‐the‐art.