filter-tiny-segments
copied
ChengZi
2 years ago
4 changed files with 121 additions and 1 deletions
@ -1,2 +1,71 @@ |
|||||
# filter-tiny-segments |
|
||||
|
# Filter Tiny Segments |
||||
|
|
||||
|
*author: Chen Zhang* |
||||
|
|
||||
|
|
||||
|
<br /> |
||||
|
|
||||
|
|
||||
|
|
||||
|
## Description |
||||
|
|
||||
|
This operator can filter tiny detected segments with format of list of `[start_second_1, start_second_2, end_second_1, end_second_2]` |
||||
|
<br /> |
||||
|
|
||||
|
|
||||
|
## Code Example |
||||
|
|
||||
|
|
||||
|
```python |
||||
|
import towhee |
||||
|
towhee.dc['pred']([[[0, 0, 100, 100], [0, 0, 10, 10], [0, 0, 60, 10]]]) \ |
||||
|
.video_copy_detection.filter_tiny_segments['pred', 'filtered_pred'](filter_s_thresh=20) \ |
||||
|
.show() |
||||
|
``` |
||||
|
|
||||
|
![](result.png) |
||||
|
|
||||
|
|
||||
|
|
||||
|
## Factory Constructor |
||||
|
|
||||
|
Create the operator via the following factory method |
||||
|
|
||||
|
***filter_tiny_segments(filter_s_thresh, segment_len_rate)*** |
||||
|
|
||||
|
|
||||
|
**Parameters:** |
||||
|
|
||||
|
***filter_s_thresh:*** *float* |
||||
|
|
||||
|
Use a thresh to filter detected box which is smaller than it. |
||||
|
|
||||
|
***segment_len_rate:*** *float* |
||||
|
|
||||
|
Filter expect longer then segment_len_rate * video length. Only useful for filter expect near video length segments. |
||||
|
|
||||
|
<br /> |
||||
|
|
||||
|
|
||||
|
|
||||
|
## Interface |
||||
|
|
||||
|
A Temporal Network operator takes two numpy.ndarray(shape(N,D) N: number of features. D: dimension of features) and get the duplicated ranges and scores. |
||||
|
|
||||
|
|
||||
|
**Parameters:** |
||||
|
|
||||
|
***pred_value:*** *List* |
||||
|
|
||||
|
List of predicted segment second infos of a video pair |
||||
|
|
||||
|
***sim_hw:*** *Tuple* |
||||
|
|
||||
|
Similarity matrix height and weight of a video pair. If sample rate is 1s, sim_hw is also the lengths of these videos. |
||||
|
|
||||
|
|
||||
|
**Returns:** |
||||
|
|
||||
|
***res_pred_list:*** *List* |
||||
|
|
||||
|
List of filtered predicted segment second infos |
||||
|
@ -0,0 +1,19 @@ |
|||||
|
# Copyright 2022 Zilliz. All rights reserved. |
||||
|
# |
||||
|
# Licensed under the Apache License, Version 2.0 (the "License"); |
||||
|
# you may not use this file except in compliance with the License. |
||||
|
# You may obtain a copy of the License at |
||||
|
# |
||||
|
# http://www.apache.org/licenses/LICENSE-2.0 |
||||
|
# |
||||
|
# Unless required by applicable law or agreed to in writing, software |
||||
|
# distributed under the License is distributed on an "AS IS" BASIS, |
||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||
|
# See the License for the specific language governing permissions and |
||||
|
# limitations under the License. |
||||
|
|
||||
|
from .filter_tiny_segments import FilterTinySegments |
||||
|
|
||||
|
|
||||
|
def filter_tiny_segments(filter_s_thresh: float, segment_len_rate: float): |
||||
|
return FilterTinySegments(filter_s_thresh, segment_len_rate) |
@ -0,0 +1,32 @@ |
|||||
|
from typing import List, Tuple, Optional |
||||
|
from towhee.operator.base import Operator |
||||
|
from towhee import register |
||||
|
|
||||
|
|
||||
|
@register(output_schema=['vec']) |
||||
|
class FilterTinySegments(Operator): |
||||
|
""" |
||||
|
FilterTinySegments |
||||
|
""" |
||||
|
|
||||
|
def __init__(self, filter_s_thresh: float, segment_len_rate: float = 0.8): |
||||
|
super().__init__() |
||||
|
self.filter_s_thresh = filter_s_thresh |
||||
|
self.segment_len_rate = segment_len_rate |
||||
|
|
||||
|
def __call__(self, pred_value: List[Optional[List]], sim_hw: Tuple = None) -> List: |
||||
|
res_pred_list = [] |
||||
|
for time_info in pred_value: |
||||
|
filterable = True |
||||
|
if ((time_info[2] - time_info[0]) + (time_info[3] - time_info[1])) / 2.0 > self.filter_s_thresh: |
||||
|
filterable = False |
||||
|
if sim_hw is not None: |
||||
|
sim_h, sim_w = sim_hw |
||||
|
if (time_info[2] - time_info[0]) > sim_h * self.segment_len_rate or ( |
||||
|
time_info[3] - time_info[1]) > sim_w * self.segment_len_rate: |
||||
|
filterable = False |
||||
|
if not filterable: |
||||
|
res_pred_list.append(time_info) |
||||
|
return res_pred_list |
||||
|
|
||||
|
|
After Width: | Height: | Size: 11 KiB |
Loading…
Reference in new issue