Remove python related files
Browse files- app.py +48 -32
- configs/{yolo8n-bytetrack-cpu.yaml → yolo8n-cpu.yaml} +2 -1
- pipeline/__pycache__/__init__.cpython-312.pyc +0 -0
- pipeline/__pycache__/pipeline.cpython-312.pyc +0 -0
- pipeline/detectors/__pycache__/__init__.cpython-312.pyc +0 -0
- pipeline/detectors/__pycache__/yolo.cpython-312.pyc +0 -0
- pipeline/trackers/__init__.py +8 -2
- pipeline/trackers/__pycache__/__init__.cpython-312.pyc +0 -0
- pipeline/trackers/__pycache__/bytetrack.cpython-312.pyc +0 -0
- pipeline/trackers/dummytrack.py +7 -0
- utils/__pycache__/__init__.cpython-312.pyc +0 -0
- utils/__pycache__/check_point.cpython-312.pyc +0 -0
- utils/__pycache__/config.cpython-312.pyc +0 -0
- utils/__pycache__/model_loader.cpython-312.pyc +0 -0
- utils/__pycache__/yacs.cpython-312.pyc +0 -0
app.py
CHANGED
|
@@ -25,19 +25,20 @@ from utils import cfg, load_config, load_onnx_model
|
|
| 25 |
|
| 26 |
# Configuration constants
|
| 27 |
CHECKPOINTS = [
|
| 28 |
-
"
|
| 29 |
-
"ustc-community/dfine-medium-
|
| 30 |
-
"ustc-community/dfine-medium-
|
| 31 |
-
"ustc-community/dfine-
|
| 32 |
-
"ustc-community/dfine-
|
| 33 |
-
"ustc-community/dfine-
|
| 34 |
-
"ustc-community/dfine-
|
| 35 |
-
"ustc-community/dfine-
|
| 36 |
-
"ustc-community/dfine-
|
| 37 |
-
"ustc-community/dfine-
|
| 38 |
-
"ustc-community/dfine-
|
| 39 |
-
"ustc-community/dfine-
|
| 40 |
-
"ustc-community/dfine-
|
|
|
|
| 41 |
]
|
| 42 |
DEFAULT_CHECKPOINT = CHECKPOINTS[0]
|
| 43 |
DEFAULT_CONFIDENCE_THRESHOLD = 0.3
|
|
@@ -109,9 +110,13 @@ def detect_objects(
|
|
| 109 |
classes: Optional[List[str]] = None,
|
| 110 |
):
|
| 111 |
|
| 112 |
-
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 113 |
-
model, image_processor = get_model_and_processor(checkpoint)
|
| 114 |
-
model = model.to(device)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
|
| 116 |
if classes is not None:
|
| 117 |
wrong_classes = [cls for cls in classes if cls not in model.config.label2id]
|
|
@@ -130,22 +135,35 @@ def detect_objects(
|
|
| 130 |
for batch in tqdm.tqdm(batches, desc="Processing frames"):
|
| 131 |
|
| 132 |
# preprocess images
|
| 133 |
-
inputs = image_processor(images=batch, return_tensors="pt")
|
| 134 |
-
inputs = inputs.to(device).to(TORCH_DTYPE)
|
| 135 |
|
| 136 |
-
# forward pass
|
| 137 |
-
with torch.no_grad():
|
| 138 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
|
| 140 |
# postprocess outputs
|
| 141 |
-
if target_size:
|
| 142 |
-
|
| 143 |
-
else:
|
| 144 |
-
|
| 145 |
|
| 146 |
-
batch_results = image_processor.post_process_object_detection(
|
| 147 |
-
|
| 148 |
-
)
|
|
|
|
| 149 |
|
| 150 |
results.extend(batch_results)
|
| 151 |
|
|
@@ -156,7 +174,8 @@ def detect_objects(
|
|
| 156 |
keep = torch.isin(results[i]["labels"], torch.tensor(keep_ids))
|
| 157 |
results[i] = {k: v[keep] for k, v in results[i].items()}
|
| 158 |
|
| 159 |
-
return results, model.config.id2label
|
|
|
|
| 160 |
|
| 161 |
|
| 162 |
def process_image(
|
|
@@ -566,7 +585,4 @@ with gr.Blocks(theme=gr.themes.Ocean()) as demo:
|
|
| 566 |
)
|
| 567 |
|
| 568 |
if __name__ == "__main__":
|
| 569 |
-
load_config(cfg, 'configs/yolo8n-bytetrack-cpu.yaml')
|
| 570 |
-
pipeline = build_pipeline(cfg.pipeline)
|
| 571 |
-
load_onnx_model(pipeline.detector, 'downloads/yolo8n-416.onnx')
|
| 572 |
demo.queue(max_size=20).launch()
|
|
|
|
| 25 |
|
| 26 |
# Configuration constants
|
| 27 |
CHECKPOINTS = [
|
| 28 |
+
"yolo8n-cpu",
|
| 29 |
+
# "ustc-community/dfine-medium-obj2coco",
|
| 30 |
+
# "ustc-community/dfine-medium-coco",
|
| 31 |
+
# "ustc-community/dfine-medium-obj365",
|
| 32 |
+
# "ustc-community/dfine-nano-coco",
|
| 33 |
+
# "ustc-community/dfine-small-coco",
|
| 34 |
+
# "ustc-community/dfine-large-coco",
|
| 35 |
+
# "ustc-community/dfine-xlarge-coco",
|
| 36 |
+
# "ustc-community/dfine-small-obj365",
|
| 37 |
+
# "ustc-community/dfine-large-obj365",
|
| 38 |
+
# "ustc-community/dfine-xlarge-obj365",
|
| 39 |
+
# "ustc-community/dfine-small-obj2coco",
|
| 40 |
+
# "ustc-community/dfine-large-obj2coco-e25",
|
| 41 |
+
# "ustc-community/dfine-xlarge-obj2coco",
|
| 42 |
]
|
| 43 |
DEFAULT_CHECKPOINT = CHECKPOINTS[0]
|
| 44 |
DEFAULT_CONFIDENCE_THRESHOLD = 0.3
|
|
|
|
| 110 |
classes: Optional[List[str]] = None,
|
| 111 |
):
|
| 112 |
|
| 113 |
+
# device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 114 |
+
# model, image_processor = get_model_and_processor(checkpoint)
|
| 115 |
+
# model = model.to(device)
|
| 116 |
+
|
| 117 |
+
load_config(cfg, f'configs/{checkpoint}.yaml')
|
| 118 |
+
pipeline = build_pipeline(cfg.pipeline)
|
| 119 |
+
load_onnx_model(pipeline.detector, 'downloads/yolo8n-416.onnx')
|
| 120 |
|
| 121 |
if classes is not None:
|
| 122 |
wrong_classes = [cls for cls in classes if cls not in model.config.label2id]
|
|
|
|
| 135 |
for batch in tqdm.tqdm(batches, desc="Processing frames"):
|
| 136 |
|
| 137 |
# preprocess images
|
| 138 |
+
# inputs = image_processor(images=batch, return_tensors="pt")
|
| 139 |
+
# inputs = inputs.to(device).to(TORCH_DTYPE)
|
| 140 |
|
| 141 |
+
# # forward pass
|
| 142 |
+
# with torch.no_grad():
|
| 143 |
+
# outputs = model(**inputs)
|
| 144 |
+
|
| 145 |
+
outputs = []
|
| 146 |
+
for i in range(len(batch)):
|
| 147 |
+
img = batch[i]
|
| 148 |
+
output_ = pipeline(img)
|
| 149 |
+
output_1 = {
|
| 150 |
+
"scores": torch.from_numpy(output_.confidence) if isinstance(output_.confidence, np.ndarray) else output_.confidence,
|
| 151 |
+
"labels": torch.from_numpy(output_.class_id) if isinstance(output_.class_id, np.ndarray) else output_.class_id,
|
| 152 |
+
"boxes": torch.from_numpy(output_.xyxy) if isinstance(output_.xyxy, np.ndarray) else output_.xyxy,
|
| 153 |
+
}
|
| 154 |
+
outputs.append(output_1)
|
| 155 |
+
|
| 156 |
|
| 157 |
# postprocess outputs
|
| 158 |
+
# if target_size:
|
| 159 |
+
# target_sizes = [target_size] * len(batch)
|
| 160 |
+
# else:
|
| 161 |
+
# target_sizes = [(image.shape[0], image.shape[1]) for image in batch]
|
| 162 |
|
| 163 |
+
# batch_results = image_processor.post_process_object_detection(
|
| 164 |
+
# outputs, target_sizes=target_sizes, threshold=confidence_threshold
|
| 165 |
+
# )
|
| 166 |
+
batch_results = outputs
|
| 167 |
|
| 168 |
results.extend(batch_results)
|
| 169 |
|
|
|
|
| 174 |
keep = torch.isin(results[i]["labels"], torch.tensor(keep_ids))
|
| 175 |
results[i] = {k: v[keep] for k, v in results[i].items()}
|
| 176 |
|
| 177 |
+
# return results, model.config.id2label
|
| 178 |
+
return results, pipeline.detector.get_category_mapping()
|
| 179 |
|
| 180 |
|
| 181 |
def process_image(
|
|
|
|
| 585 |
)
|
| 586 |
|
| 587 |
if __name__ == "__main__":
|
|
|
|
|
|
|
|
|
|
| 588 |
demo.queue(max_size=20).launch()
|
configs/{yolo8n-bytetrack-cpu.yaml → yolo8n-cpu.yaml}
RENAMED
|
@@ -11,4 +11,5 @@ pipeline:
|
|
| 11 |
device: cpu
|
| 12 |
|
| 13 |
tracker:
|
| 14 |
-
algorithm:
|
|
|
|
|
|
| 11 |
device: cpu
|
| 12 |
|
| 13 |
tracker:
|
| 14 |
+
algorithm: dummytrack
|
| 15 |
+
|
pipeline/__pycache__/__init__.cpython-312.pyc
DELETED
|
Binary file (679 Bytes)
|
|
|
pipeline/__pycache__/pipeline.cpython-312.pyc
DELETED
|
Binary file (1.38 kB)
|
|
|
pipeline/detectors/__pycache__/__init__.cpython-312.pyc
DELETED
|
Binary file (705 Bytes)
|
|
|
pipeline/detectors/__pycache__/yolo.cpython-312.pyc
DELETED
|
Binary file (4 kB)
|
|
|
pipeline/trackers/__init__.py
CHANGED
|
@@ -1,8 +1,14 @@
|
|
| 1 |
from .bytetrack import ByteTrack
|
|
|
|
| 2 |
|
| 3 |
-
def build_tracker(
|
| 4 |
"""
|
| 5 |
Build the tracking model based on the provided configuration.
|
| 6 |
"""
|
| 7 |
# Initialize the tracker
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from .bytetrack import ByteTrack
|
| 2 |
+
from .dummytrack import DummyTrack
|
| 3 |
|
| 4 |
+
def build_tracker(config):
|
| 5 |
"""
|
| 6 |
Build the tracking model based on the provided configuration.
|
| 7 |
"""
|
| 8 |
# Initialize the tracker
|
| 9 |
+
if config.algorithm == "bytetrack":
|
| 10 |
+
return ByteTrack()
|
| 11 |
+
elif config.algorithm == "dummytrack":
|
| 12 |
+
return DummyTrack()
|
| 13 |
+
else:
|
| 14 |
+
raise ValueError(f"Unknown tracker type: {config.tracker.algorithm}")
|
pipeline/trackers/__pycache__/__init__.cpython-312.pyc
DELETED
|
Binary file (407 Bytes)
|
|
|
pipeline/trackers/__pycache__/bytetrack.cpython-312.pyc
DELETED
|
Binary file (1.05 kB)
|
|
|
pipeline/trackers/dummytrack.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class DummyTrack:
|
| 2 |
+
def __init__(self, *args, **kwargs):
|
| 3 |
+
pass
|
| 4 |
+
|
| 5 |
+
def __call__(self, detections, *args, **kwargs):
|
| 6 |
+
# Just return the detections as-is
|
| 7 |
+
return detections
|
utils/__pycache__/__init__.cpython-312.pyc
DELETED
|
Binary file (293 Bytes)
|
|
|
utils/__pycache__/check_point.cpython-312.pyc
DELETED
|
Binary file (310 Bytes)
|
|
|
utils/__pycache__/config.cpython-312.pyc
DELETED
|
Binary file (1.72 kB)
|
|
|
utils/__pycache__/model_loader.cpython-312.pyc
DELETED
|
Binary file (311 Bytes)
|
|
|
utils/__pycache__/yacs.cpython-312.pyc
DELETED
|
Binary file (21.7 kB)
|
|
|