In order to solve the problem of fault detection and identification of drug boxes on the conveyor belt of automatic drug vending machine, a target detection algorithm based on machine vision and deep neural network of efficient channel and spatial attention mechanism was proposed, named AT-YOLOV4. Firstly, the data set of Western medicine box fault detection was constructed. Secondly, the target detection model YOLOv4 with One-Stage structure was adopted, and the backbone network of the model was improved. In the Backbone network of this model, the efficient channel and spatial attention mechanism is integrated into the backbone module of YOLOv4 model. The improved model was compared with the unimproved YOLOv4 model, YOLOv3 model, YOLOv3-SPP model and YOLOv5s model for the correlation algorithm index experiments. Results The AT-YOLOV4 model with the efficient channel attention mechanism can effectively improve the recognition rate of the drug box and reduce the weight of the model. The AT-YOLOv4 model was significantly superior to other models in accuracy, recall rate and mean accuracy, and the mean accuracy of drug box identification reached 99.6% .