ABSTRACT Particle swarm optimization algorithm is a branch of evolutionary computing and can search for a better solution in a given feature space. This paper introduces the particle swarm optimization algorithm and greedy strategy for the defect detection and location of industrial components and then proposes a greedy particle swarm optimization algorithm. This paper employs sparse random projection to map the vast high-dimensional information to the low-dimensional space while maintaining the relative distance between the data. This employment helps to accelerate the training and prediction speed of the model and remove some unimportant features or noise. This algorithm first adopts particle swarm optimization (PSO) to initialize the cluster centers in an effort to minimize the maximum distance between all unlabeled data points and these centers. The algorithm then utilizes the greedy strategy to select a batch of data points to represent the corresponding features of the normal image, thereby improving the coverage of the model to the data. Experiments have shown that the results of most categories of data sets are close to or better than the current existing methods, especially in defect detection. In terms of defect localization for object categories, our method achieves a pixel-level anomaly localization index (AUROC) of 98.3% on the MVTec AD dataset.