Skip to content

Commit

Permalink
Removing CutOff (WildChlamydia#15)
Browse files Browse the repository at this point in the history
* Fixing readme and removing CutOff

---------

Co-authored-by: mvkuprashevich <[email protected]>
Co-authored-by: sweetdream779 <[email protected]>
  • Loading branch information
3 people authored Aug 21, 2023
1 parent 918f8a6 commit 4d055cb
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 34 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,5 @@ Testing notebook.ipynb

output/
input/

run.sh
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,24 @@ python3 eval_pretrained.py \

Supported dataset names: "utk", "imdb", "lagenda", "fairface", "adience".


## Changelog

15.08.20223 - 0.4.1dev

### Added
- Support for video streams, including YouTube URLs
- Instructions and explanations for various export types.

### Changed
- Removed CutOff operation. It has been proven to be ineffective for inference time and quite costly at the same time. Now it is only used during training.

## ONNX and TensorRT export

As of now (11.08.2023), while ONNX export is technically feasible, it is not advisable due to the poor performance of the resulting model with batch processing.
TensorRT export is impossible due to its lack of support for col2im.
As of now (11.08.2023), while ONNX export is technically feasible, it is not advisable due to the poor performance of the resulting model with batch processing.
**TensorRT** and **OpenVINO** export is impossible due to its lack of support for col2im.

If you remain absolutely committed to utilizing ONNX export, you can refer to [these instructions](https://github.com/WildChlamydia/MiVOLO/issues/14#issuecomment-1675245889).
If you remain absolutely committed to utilizing ONNX export, you can refer to [these instructions](https://github.com/WildChlamydia/MiVOLO/issues/14#issuecomment-1675245889).

The most highly recommended export method at present **is using TorchScript**. You can achieve this with a single line of code:
```python
Expand Down
9 changes: 4 additions & 5 deletions mivolo/data/dataset/reader_age_gender.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import cv2
import numpy as np
from mivolo.data.data_reader import AnnotType, PictureInfo, get_all_files, read_csv_annotation_file
from mivolo.data.misc import IOU, class_letterbox, cropout_black_parts
from mivolo.data.misc import IOU, class_letterbox
from timm.data.readers.reader import Reader
from tqdm import tqdm

Expand Down Expand Up @@ -461,10 +461,9 @@ def _cropout_asced_objs(

crop[aobj_ymin:aobj_ymax, aobj_xmin:aobj_xmax] = crop_out_color

crop, cropped_ratio = cropout_black_parts(crop, crop_round_tol)
if (
crop.shape[0] < min_person_size or crop.shape[1] < min_person_size
) or cropped_ratio < min_person_aftercut_ratio:
# calc useful non-black area
remain_ratio = np.count_nonzero(crop) / (crop.shape[0] * crop.shape[1] * crop.shape[2])
if (crop.shape[0] < min_person_size or crop.shape[1] < min_person_size) or remain_ratio < min_person_aftercut_ratio:
crop = None
empty = True

Expand Down
21 changes: 0 additions & 21 deletions mivolo/data/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,6 @@ def aggregate_votes_winsorized(ages, max_age_dist=6):
return np.mean(ages)


def cropout_black_parts(img, tol=0.3):
# Create a binary mask of zero pixels
zero_pixels_mask = np.all(img == 0, axis=2)
# Calculate the threshold for zero pixels in rows and columns
threshold = img.shape[0] - img.shape[0] * tol
# Calculate row sums and column sums of zero pixels mask
row_sums = np.sum(zero_pixels_mask, axis=1)
col_sums = np.sum(zero_pixels_mask, axis=0)
# Find the first and last rows with zero pixel sums above the threshold
start_row = np.argmin(row_sums > threshold)
end_row = img.shape[0] - np.argmin(row_sums[::-1] > threshold)
# Find the first and last columns with zero pixel sums above the threshold
start_col = np.argmin(col_sums > threshold)
end_col = img.shape[1] - np.argmin(col_sums[::-1] > threshold)
# Crop the image
cropped_img = img[start_row:end_row, start_col:end_col, :]
area = cropped_img.shape[0] * cropped_img.shape[1]
area_orig = img.shape[0] * img.shape[1]
return cropped_img, area / area_orig


def natural_key(string_):
"""See http://www.codinghorror.com/blog/archives/001018.html"""
return [int(s) if s.isdigit() else s for s in re.split(r"(\d+)", string_.lower())]
Expand Down
2 changes: 1 addition & 1 deletion mivolo/predictor.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def recognize_video(self, source: str) -> Generator:
# add tr_persons and tr_faces to history
for guid, data in cur_persons.items():
# not useful for tracking :)
if None not in data:
if None not in data:
detected_objects_history[guid].append(data)
for guid, data in cur_faces.items():
if None not in data:
Expand Down
6 changes: 3 additions & 3 deletions mivolo/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import cv2
import numpy as np
import torch
from mivolo.data.misc import aggregate_votes_winsorized, assign_faces, box_iou, cropout_black_parts
from mivolo.data.misc import aggregate_votes_winsorized, assign_faces, box_iou
from ultralytics.yolo.engine.results import Results
from ultralytics.yolo.utils.plotting import Annotator, colors

Expand Down Expand Up @@ -317,7 +317,7 @@ def _gather_tracking_result(
person_ages = [r[0] for r in tracked_objects[pguid] if r[0] is not None] if pguid in tracked_objects else []
person_genders = [r[1] for r in tracked_objects[pguid] if r[1] is not None] if pguid in tracked_objects else []

if not face_ages and not person_ages: # both empty
if not face_ages and not person_ages: # both empty
return None, None

# You can play here with different aggregation strategies
Expand Down Expand Up @@ -434,7 +434,7 @@ def crop_object(

obj_image[o_y1:o_y2, o_x1:o_x2] = 0

obj_image, remain_ratio = cropout_black_parts(obj_image, CROP_ROUND_RATE)
remain_ratio = np.count_nonzero(obj_image) / (obj_image.shape[0] * obj_image.shape[1] * obj_image.shape[2])
if remain_ratio < MIN_PERSON_CROP_AFTERCUT_RATIO:
return None

Expand Down
2 changes: 1 addition & 1 deletion mivolo/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.3.0dev"
__version__ = "0.4.1dev"

0 comments on commit 4d055cb

Please sign in to comment.