Many chronic diseases, such as cardiovascular disease and sleep disorders, can be diagnosed and treated by assessing the sleeping quality. Sleep posture recognition is an important part of determining sleep quality in sleep research. While most recent studies focus on the classification problem with the number of sleeping postures being equal to or less than ten, this study aims to achieve state-of-the-art results on 17 in-bed position classification. To do this, a spatial pyramid pooling module was added to the top of the EfficientNet B0 model and the contrastive loss and cross-entropy loss functions are combined to act as the main loss function. The random 10% salt and pepper noise are utilized to augment the training data. Experimental results confirm that the proposed approach achieves the best accuracy of 96.01% and outperforms the existing methods. Additionally, we also provide an estimation related to the impact of various combinations of backbone models and loss functions on the performance of the classifier.