Rock classification holds significant importance in geological evolution, resource exploration, and environmental protection. This study selects a public database containing over 110,000 images of metamorphic, sedimentary, and igneous rocks for a ternary classification task. Initially, the Grounded-segment-anything algorithm is employed to segregate rocks from their backgrounds. Subsequently, a comparative analysis is conducted between the unsupervised learning algorithm SimCLR and the supervised learning algorithm ResNet to determine their recognition efficacies. Optimal parameters are then identified to establish the best rock classification model. Furthermore, this study delves into the effects of varying training sample sizes and label quantities on the recognition accuracy of both algorithms, as well as the enhancement of SimCLR's accuracy through unlabeled images. The findings reveal that: (1) SimCLR-18 outperforms ResNet-34, achieving an F1 score of 0.740 and a recognition accuracy of 73.5% on the test set; (2) Across different sample sizes, the SimCLR-18 model consistently demonstrates superior accuracy compared to the ResNet-34 model; (3) To achieve comparable accuracy, SimCLR-18 requires approximately 11% of the labels needed by ResNet-34; (4) Incorporating unlabeled rock images can further enhance the accuracy of the SimCLR-18 model. The methodology presented in this study offers an efficient and intelligent approach to rock classification. Additionally, it provides cost-effective insights into expanding database sizes to further improve classification accuracy.