Package: y5gg
packaged ultralytics/yolov5pip install yolov5OverviewYou can finally installYOLOv5 object detectorusingpipand integrate into your project easily.InstallInstall 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 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, x2, y1, 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, x2, y1, 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.pt2Visualize your experiments viaNeptune.AI:$yolov5train--datadata.yaml--weightsyolov5s.pt--neptune_projectNAMESPACE/PROJECT_NAME--neptune_tokenYOUR_NEPTUNE_TOKENInferenceyolov5 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'