The structural complexity and uneven gray distribution of pneumonia images seriously affect the accuracy of pneumonia classification. As DenseNet has the characteristic of continuously transmitting the learned features of each layer backwards, which makes DenseNet not only reduce the model parameters, but also makes the local features learn better. Therefore, this paper proposes a method based on DenseNet to classify pneumonia. This method adds a feature channel attention block Squeeze and Excitation (SE) to DenseNet to highlight pneumonia information in feature maps, replaces the average pooling of the third transition layer in DenseNet with max-pooling to further focus on the lesion region, and by comparing several activation functions, we choose PReLU to avoid neuron death in the process of model training ultimately. Moreover, we preprocess the chest X-ray2017 dataset with data augmentation and normalization. The experimental results show that compared with DenseNet, our model's Accuracy, Precision, Recall and F1-score are improved by 2.4%, 2.0%, 1.8%, 1.8%, respectively, which can reach 92.8%, 92.6%, 96.2%, 94.3%. In this paper, we propose an attention-based DenseNet method for pneumonia classification, which make it pay more attention to the pneumonia areas to improve the classification performance.