modidied stuff
This commit is contained in:
1 parent
9ada7cc1a8
commit
bd776b0a14
2 files changed
+42
-16
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
import json
|
import json
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
import logging
|
||||||
import torch
|
import torch
|
||||||
from ultralytics import YOLO
|
from ultralytics import YOLO
|
||||||
import cv2
|
import cv2
|
||||||
@@ -10,10 +10,22 @@ import numpy as np
|
|||||||
from boxmot import DeepOcSort as DeepOCSORT
|
from boxmot import DeepOcSort as DeepOCSORT
|
||||||
|
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
Color = tuple[int, int, int]
|
Color = tuple[int, int, int]
|
||||||
|
|
||||||
|
|
||||||
|
def get_best_available_torch_device():
|
||||||
|
if torch.cuda.is_available():
|
||||||
|
logger.debug("Using the cuda (gpu) torch device.")
|
||||||
|
return 'cuda'
|
||||||
|
if torch.backends.mps.is_available():
|
||||||
|
logger.debug("Using the mps (apple silicon) torch device.")
|
||||||
|
return 'mps'
|
||||||
|
logger.debug("Default to cpu (no apple silicon or cuda) torch device.")
|
||||||
|
return 'cpu'
|
||||||
|
|
||||||
|
|
||||||
class DetectedObjectBox:
|
class DetectedObjectBox:
|
||||||
def __init__(self, min_threshold: float, color: Color):
|
def __init__(self, min_threshold: float, color: Color):
|
||||||
self.min_threshold = min_threshold
|
self.min_threshold = min_threshold
|
||||||
@@ -93,7 +105,7 @@ class DodgeballTracker:
|
|||||||
for d in tracker_data:
|
for d in tracker_data:
|
||||||
self.print_box(d, frame_idx, frame_ts)
|
self.print_box(d, frame_idx, frame_ts)
|
||||||
|
|
||||||
def plot_boxe_to_frame(self, data, frame):
|
def plot_box_to_frame(self, data, frame):
|
||||||
confidence = float(data[4])
|
confidence = float(data[4])
|
||||||
for detected_box_object in self.detected_box_objects:
|
for detected_box_object in self.detected_box_objects:
|
||||||
|
|
||||||
@@ -126,7 +138,7 @@ class DodgeballTracker:
|
|||||||
def _get_tracker(self):
|
def _get_tracker(self):
|
||||||
return DeepOCSORT(
|
return DeepOCSORT(
|
||||||
Path('lmbn_n_cuhk03_d.pt'), # which ReID model to use
|
Path('lmbn_n_cuhk03_d.pt'), # which ReID model to use
|
||||||
torch.device("cpu"),
|
torch.device(get_best_available_torch_device()),
|
||||||
True,
|
True,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -151,10 +163,8 @@ class DodgeballTracker:
|
|||||||
# run the YOLO model on the frame
|
# run the YOLO model on the frame
|
||||||
res = []
|
res = []
|
||||||
detections = self.run_model_on_frame(model, frame)
|
detections = self.run_model_on_frame(model, frame)
|
||||||
print("ici?")
|
|
||||||
for data in detections.boxes.data.tolist():
|
for data in detections.boxes.data.tolist():
|
||||||
print("la?")
|
is_good_box = self.plot_box_to_frame(data, frame)
|
||||||
is_good_box = self.plot_boxe_to_frame(data, frame)
|
|
||||||
if is_good_box:
|
if is_good_box:
|
||||||
res.append(data)
|
res.append(data)
|
||||||
|
|
||||||
|
|||||||
@@ -2,24 +2,40 @@
|
|||||||
description = "Pre-built CPU-only OpenCV packages for Python. ";
|
description = "Pre-built CPU-only OpenCV packages for Python. ";
|
||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
||||||
opencv-python-related.url = "gitlab:all-dressed-programming/opencv-python-related";
|
opencv-python-related.url =
|
||||||
|
"gitlab:all-dressed-programming/opencv-python-related";
|
||||||
|
opencv-python-related.home-manager.inputs.nixpkgs.follows = "nixpkgs";
|
||||||
flake-utils.url = "github:numtide/flake-utils";
|
flake-utils.url = "github:numtide/flake-utils";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
nixConfig = {
|
||||||
|
extra-substituters = [ "https://cuda-maintainers.cachix.org" ];
|
||||||
|
extra-trusted-public-keys = [
|
||||||
|
"cuda-maintainers.cachix.org-1:0dq3bujKpuEPMCX6U4WylrUDZ9JyUG0VpVZa7CNfq5E="
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
outputs = { self, nixpkgs, flake-utils, opencv-python-related }:
|
outputs = { self, nixpkgs, flake-utils, opencv-python-related }:
|
||||||
flake-utils.lib.eachDefaultSystem (system:
|
flake-utils.lib.eachDefaultSystem (system:
|
||||||
let
|
let
|
||||||
pkgs = nixpkgs.legacyPackages.${system};
|
pkgs = import nixpkgs {
|
||||||
pythonPackages = pkgs.python312Packages // opencv-python-related.packages.${system}.python312Packages;
|
system = system;
|
||||||
virtual-env = pkgs.python312.withPackages (ps: [ ps.matplotlib
|
config.allowUnfree = true;
|
||||||
pythonPackages.opencv4
|
};
|
||||||
pythonPackages.boxmot
|
pythonPackages = pkgs.python312Packages
|
||||||
pythonPackages.ultralytics ]);
|
// opencv-python-related.packages.${system}.python312Packages;
|
||||||
|
virtual-env = pkgs.python312.withPackages (ps: [
|
||||||
|
ps.matplotlib
|
||||||
|
ps.torchWithCuda
|
||||||
|
# pythonPackages.opencv4
|
||||||
|
# pythonPackages.boxmot
|
||||||
|
# pythonPackages.ultralytics
|
||||||
|
]);
|
||||||
|
|
||||||
in {
|
in {
|
||||||
packages = {
|
packages = { env = virtual-env; };
|
||||||
env = virtual-env;
|
devShells.default = pkgs.mkShell {
|
||||||
|
buildInputs = [ virtual-env pkgs.yt-dlp pkgs.ffmpeg_7 ];
|
||||||
};
|
};
|
||||||
devShells.default = pkgs.mkShell { buildInputs = [ virtual-env pkgs.yt-dlp pkgs.ffmpeg_7]; };
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user