Package: yolov5
packaged ultralytics/yolov5pip install yolov5OverviewYou can finally installYOLOv5 object detectorusingpipand integrate into your project easily.This yolov5 package contains everything from ultralytics/yolov5at this commitplus:1. Easy installation via pip:pip install yolov52. Full CLI integration withfirepackage3. COCO dataset format support (for training)4. Full🤗 Hubintegration5.S3support (model and dataset upload)6.NeptuneAIlogger support (metric, model and dataset logging)7. Classwise AP logging during experimentsInstallInstall yolov5 using pip (for Python >=3.7)pip install yolov5Model ZooEffortlessly explore and use finetuned YOLOv5 models with one line of code:awesome-yolov5-modelsUse from Pythonimportyolov5# load pretrained modelmodel=yolov5.load('yolov5s.pt')# or load custom modelmodel=yolov5.load('train/best.pt')# set model parametersmodel.conf=0.25# NMS confidence thresholdmodel.iou=0.45# NMS IoU thresholdmodel.agnostic=False# NMS class-agnosticmodel.multi_label=False# NMS multiple labels per boxmodel.max_det=1000# maximum number of detections per image# set imageimg='https://github.com/ultralytics/yolov5/raw/master/data/images/zidane.jpg'# perform inferenceresults=model(img)# inference with larger input sizeresults=model(img,size=1280)# inference with test time augmentationresults=model(img,augment=True)# parse resultspredictions=results.pred[0]boxes=predictions[:,:4]# x1, y1, x2, y2scores=predictions[:,4]categories=predictions[:,5]# show detection bounding boxes on imageresults.show()# save results into "results/" folderresults.save(save_dir='results/')Train/Detect/Test/ExportYou can directly use these functions by importing them:fromyolov5importtrain,val,detect,export# from yolov5.classify import train, val, predict# from yolov5.segment import train, val, predicttrain.run(imgsz=640,data='coco128.yaml')val.run(imgsz=640,data='coco128.yaml',weights='yolov5s.pt')detect.run(imgsz=640)export.run(imgsz=640,weights='yolov5s.pt')You can pass any argument as input:fromyolov5importdetectimg_url='https://github.com/ultralytics/yolov5/raw/master/data/images/zidane.jpg'detect.run(source=img_url,weights="yolov5s6.pt",conf_thres=0.25,imgsz=640)Use from CLIYou can callyolov5 train,yolov5 detect,yolov5 valandyolov5 exportcommands after installing the package viapip:TrainingFinetune one of the pretrained YOLOv5 models using your customdata.yaml:$yolov5train--datadata.yaml--weightsyolov5s.pt--batch-size16--img640yolov5m.pt8yolov5l.pt4yolov5x.pt2Start a training using a COCO formatted dataset:# data.ymltrain_json_path:"train.json"train_image_dir:"train_image_dir/"val_json_path:"val.json"val_image_dir:"val_image_dir/"$yolov5train--datadata.yaml--weightsyolov5s.ptTrain your model usingRoboflow Universedatasets (roboflow>=0.2.29 required):$yolov5train--dataDATASET_UNIVERSE_URL--weightsyolov5s.pt--roboflow_tokenYOUR_ROBOFLOW_TOKENWhereDATASET_UNIVERSE_URLmust be inhttps://universe.roboflow.com/workspace_name/project_name/project_versionformat.Visualize your experiments viaNeptune.AI(neptune-client>=0.10.10 required):$yolov5train--datadata.yaml--weightsyolov5s.pt--neptune_projectNAMESPACE/PROJECT_NAME--neptune_tokenYOUR_NEPTUNE_TOKENAutomatically upload weights toHuggingface Hub:$yolov5train--datadata.yaml--weightsyolov5s.pt--hf_model_idusername/modelname--hf_tokenYOUR-HF-WRITE-TOKENAutomatically upload weights and datasets to AWS S3 (with Neptune.AI artifact tracking integration):exportAWS_ACCESS_KEY_ID=YOUR_KEYexportAWS_SECRET_ACCESS_KEY=YOUR_KEY$yolov5train--datadata.yaml--weightsyolov5s.pt--s3_upload_dirYOUR_S3_FOLDER_DIRECTORY--upload_datasetAddyolo_s3_data_dirintodata.yamlto match Neptune dataset with a present dataset in S3.# data.ymltrain_json_path:"train.json"train_image_dir:"train_image_dir/"val_json_path:"val.json"val_image_dir:"val_image_dir/"yolo_s3_data_dir:s3://bucket_name/data_dir/Inferenceyolov5 detect command runs inference on a variety of sources, downloading models automatically from thelatest YOLOv5 releaseand saving results toruns/detect.$yolov5detect--source0# webcamfile.jpg# imagefile.mp4# videopath/# directorypath/*.jpg# globrtsp://170.93.143.139/rtplive/470011e600ef003a004ee33696235daa# rtsp streamrtmp://192.168.1.105/live/test# rtmp streamhttp://112.50.243.8/PLTV/88888888/224/3221225900/1.m3u8# http streamExportYou can export your fine-tuned YOLOv5 weights to any format such astorchscript,onnx,coreml,pb,tflite,tfjs:$yolov5export--weightsyolov5s.pt--includetorchscript,onnx,coreml,pb,tfjsClassifyTrain/Val/Predict with YOLOv5 image classifier:$yolov5classifytrain--img640--datamnist2560--weightsyolov5s-cls.pt--epochs1$yolov5classifypredict--img640--weightsyolov5s-cls.pt--sourceimages/SegmentTrain/Val/Predict with YOLOv5 instance segmentation model:$yolov5segmenttrain--img640--weightsyolov5s-seg.pt--epochs1$yolov5segmentpredict--img640--weightsyolov5s-seg.pt--sourceimages/