In order to solve the problem that most of the tested objects are in normal state, the fault samples are scarce and the accuracy of fault classification is not high, on the basis of deep learning theory, A fault diagnosis model based on DenseNet and weighted loss function is proposed, The fault diagnosis of unbalanced samples is realized. First, the dense convolution neural network model is introduced. Then, in the loss function, penalty coefficients are added to different types of samples to realize the weighted average of unbalanced sample errors. Furthermore, combining advantages of both the DenseNet and weighted loss function, a novel network architecture, W-DenseNet is proposed in this paper. Finally, to verify the effectiveness of the model, the classification performance of the pressure reducing valve data sets with different balance degrees is tested and compared with the traditional convolution neural network and dense convolution neural network. The experimental results show that the proposed model can significantly improve the classification accuracy of a small number of samples without reducing the overall classification accuracy.