Package: yolov5-thin
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 yolov5`2. Full CLI integration withfirepackage3. COCO dataset format support (for training)4.S3support (model and dataset upload)5.NeptuneAIlogger support (metric, model and dataset logging)6. Classwise AP logging during experimentsInstallInstall yolov5 using pip (for Python >=3.7)pip install yolov5Install yolov5 using pip `(for Python 3.6)`pip install "numpy>=1.18.5,<1.20" "matplotlib>=3.2.2,<4"pip install yolov5Use from PythonBasicimportyolov5# load modelmodel=yolov5.load('yolov5s')# 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/')Alternativefromyolov5importYOLOv5# set model paramsmodel_path="yolov5/weights/yolov5s.pt"device="cuda:0"# or "cpu"# init yolov5 modelyolov5=YOLOv5(model_path,device)# load imagesimage1='https://github.com/ultralytics/yolov5/raw/master/data/images/zidane.jpg'image2='https://github.com/ultralytics/yolov5/blob/master/data/images/bus.jpg'# perform inferenceresults=yolov5.predict(image1)# perform inference with larger input sizeresults=yolov5.predict(image1,size=1280)# perform inference with test time augmentationresults=yolov5.predict(image1,augment=True)# perform inference on multiple imagesresults=yolov5.predict([image1,image2],size=1280,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,exporttrain.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.ptVisualize 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 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--include'torchscript,onnx,coreml,pb,tfjs'