Yolov5-Lite: Minimal YoloV5 Implementation
Overview
It has been simplified by editing detect.py in the yolov5 repository.
Installation
git clone https://github.com/kadirnar/yolov5-lite
cd yolov5-lite
pip install -r requirements.txt
Yolov5-Lite Prediction:
It is the edited version of the codes in the detect file.
class Yolov5:
def __init__(self, weights, device, data):
self.weights = weights
self.device = device
def load_model(self, weights, device, data):
self.device = select_device(device)
self.model = DetectMultiBackend(weights, device=self.device, data=data)
def preprocces_img(self, img, imgsz):
self.npy_im = numpy_img(img, imgsz)
self.tensor_im = file_to_torch(self.npy_im, self.device)
def detect(self):
# Inference
pred = self.model(self.tensor_im) # shape: torch.Size([1, 3, 640, 480])
# NMS
pred = non_max_suppression(pred, conf_thres=0.25, iou_thres=0.45, max_det=1000)
for det in pred:
det[:, :4] = scale_coords(self.tensor_im.shape[2:], det[:, :4], self.npy_im.shape).round()
self.det = det
def show_img(self, view_img=True):
# Write results
for *xyxy, conf, cls in reversed(self.det):
annotator = Annotator(self.npy_im, line_width=3, example=str(self.model.names))
logging.info("\t+ Label: %s, Conf: %.5f" % (self.model.names[int(cls)], conf.item()))
if view_img: # Add bbox to image
label = "%s %.2f" % (self.model.names[int(cls)], conf)
annotator.box_label(xyxy, label, color=colors(int(cls), True))
# Stream results
im0 = annotator.result()
if view_img:
cv2.imshow("frame", im0)
cv2.waitKey(0)
cv2.destroyAllWindows()
Yolov5-Lite Run Code:
You can take the detect.py file as an example to load and visualize your yolov5 models.
weights = "yolov5s.pt"
img = "data/images/bus.jpg"
data = "data/coco128.yaml"
device = "cpu"
imgsz = 640
view_img = True
model = Yolov5(weights, device, data)
model.load_model(weights, device, data)
model.preprocces_img(img, imgsz)
model.detect()
model.show_img(view_img)
Reference:
Metadata
Release files for yolite 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| yolite-0.0.3.tar.gz | 3.2 kB | Without provenance | Details for yolite-0.0.3.tar.gz |
Release files / yolite-0.0.3.tar.gz
| Download URL | yolite-0.0.3.tar.gz |
|---|---|
| Size | 3.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
04066f10b93260b79b5929e0cb5e19b49d1136c78e25611e34d94cd92a8327c0
|
|
BLAKE2b-256 checksum How to use checksums |
d0b99a6e890d85ffce5527c2d449ba148c1a048cee25dc6bbaf9fa53f78e9ec0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.10.4
|
Security for yolite 0.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.