• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

georgia-tech-db / eva / #758

04 Sep 2023 08:37PM UTC coverage: 0.0% (-78.3%) from 78.333%
#758

push

circle-ci

hershd23
Increased underline length in at line 75 in text_summarization.rst
	modified:   docs/source/benchmarks/text_summarization.rst

0 of 11303 relevant lines covered (0.0%)

0.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/evadb/udfs/fastrcnn_object_detector.py
1
# coding=utf-8
2
# Copyright 2018-2023 EvaDB
3
#
4
# Licensed under the Apache License, Version 2.0 (the "License");
5
# you may not use this file except in compliance with the License.
6
# You may obtain a copy of the License at
7
#
8
#     http://www.apache.org/licenses/LICENSE-2.0
9
#
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
15
from typing import List
×
16

17
import numpy as np
×
18
import pandas as pd
×
19

20
from evadb.catalog.catalog_type import NdArrayType
×
21
from evadb.udfs.abstract.pytorch_abstract_udf import PytorchAbstractClassifierUDF
×
22
from evadb.udfs.decorators.decorators import forward, setup
×
23
from evadb.udfs.decorators.io_descriptors.data_types import (
×
24
    PandasDataframe,
25
    PyTorchTensor,
26
)
27
from evadb.utils.generic_utils import try_to_import_torch, try_to_import_torchvision
×
28

29

30
class FastRCNNObjectDetector(PytorchAbstractClassifierUDF):
×
31
    """
32
    Arguments:
33
        threshold (float): Threshold for classifier confidence score
34

35
    """
36

37
    @property
×
38
    def name(self) -> str:
×
39
        return "fastrcnn"
×
40

41
    @setup(cacheable=True, udf_type="object_detection", batchable=True)
×
42
    def setup(self, threshold=0.85):
×
43
        try_to_import_torch()
×
44
        try_to_import_torchvision()
×
45
        import torchvision
×
46

47
        self.threshold = threshold
×
48
        self.model = torchvision.models.detection.fasterrcnn_resnet50_fpn(
×
49
            weights="COCO_V1", progress=False
50
        )
51
        self.model.eval()
×
52

53
    @property
×
54
    def labels(self) -> List[str]:
×
55
        return [
×
56
            "__background__",
57
            "person",
58
            "bicycle",
59
            "car",
60
            "motorcycle",
61
            "airplane",
62
            "bus",
63
            "train",
64
            "truck",
65
            "boat",
66
            "traffic light",
67
            "fire hydrant",
68
            "N/A",
69
            "stop sign",
70
            "parking meter",
71
            "bench",
72
            "bird",
73
            "cat",
74
            "dog",
75
            "horse",
76
            "sheep",
77
            "cow",
78
            "elephant",
79
            "bear",
80
            "zebra",
81
            "giraffe",
82
            "N/A",
83
            "backpack",
84
            "umbrella",
85
            "N/A",
86
            "N/A",
87
            "handbag",
88
            "tie",
89
            "suitcase",
90
            "frisbee",
91
            "skis",
92
            "snowboard",
93
            "sports ball",
94
            "kite",
95
            "baseball bat",
96
            "baseball glove",
97
            "skateboard",
98
            "surfboard",
99
            "tennis racket",
100
            "bottle",
101
            "N/A",
102
            "wine glass",
103
            "cup",
104
            "fork",
105
            "knife",
106
            "spoon",
107
            "bowl",
108
            "banana",
109
            "apple",
110
            "sandwich",
111
            "orange",
112
            "broccoli",
113
            "carrot",
114
            "hot dog",
115
            "pizza",
116
            "donut",
117
            "cake",
118
            "chair",
119
            "couch",
120
            "potted plant",
121
            "bed",
122
            "N/A",
123
            "dining table",
124
            "N/A",
125
            "N/A",
126
            "toilet",
127
            "N/A",
128
            "tv",
129
            "laptop",
130
            "mouse",
131
            "remote",
132
            "keyboard",
133
            "cell phone",
134
            "microwave",
135
            "oven",
136
            "toaster",
137
            "sink",
138
            "refrigerator",
139
            "N/A",
140
            "book",
141
            "clock",
142
            "vase",
143
            "scissors",
144
            "teddy bear",
145
            "hair drier",
146
            "toothbrush",
147
        ]
148

149
    @forward(
×
150
        input_signatures=[
151
            PyTorchTensor(
152
                name="input_col",
153
                is_nullable=False,
154
                type=NdArrayType.FLOAT32,
155
                dimensions=(1, 3, 540, 960),
156
            )
157
        ],
158
        output_signatures=[
159
            PandasDataframe(
160
                columns=["labels", "bboxes", "scores"],
161
                column_types=[
162
                    NdArrayType.STR,
163
                    NdArrayType.FLOAT32,
164
                    NdArrayType.FLOAT32,
165
                ],
166
                column_shapes=[(None,), (None,), (None,)],
167
            )
168
        ],
169
    )
170
    def forward(self, frames) -> pd.DataFrame:
×
171
        """
172
        Performs predictions on input frames
173
        Arguments:
174
            frames (np.ndarray): Frames on which predictions need
175
            to be performed
176

177
        Returns:
178
            tuple containing predicted_classes (List[List[str]]),
179
            predicted_boxes (List[List[BoundingBox]]),
180
            predicted_scores (List[List[float]])
181

182
        """
183
        predictions = self.model(frames)
×
184
        outcome = []
×
185
        for prediction in predictions:
×
186
            pred_class = [
×
187
                str(self.labels[i]) for i in list(self.as_numpy(prediction["labels"]))
188
            ]
189
            pred_boxes = [
×
190
                [i[0], i[1], i[2], i[3]]
191
                for i in list(self.as_numpy(prediction["boxes"]))
192
            ]
193
            pred_score = list(self.as_numpy(prediction["scores"]))
×
194
            valid_pred = [pred_score.index(x) for x in pred_score if x > self.threshold]
×
195

196
            if valid_pred:
×
197
                pred_t = valid_pred[-1]
×
198
            else:
199
                pred_t = -1
×
200

201
            pred_boxes = np.array(pred_boxes[: pred_t + 1])
×
202
            pred_class = np.array(pred_class[: pred_t + 1])
×
203
            pred_score = np.array(pred_score[: pred_t + 1])
×
204
            outcome.append(
×
205
                {"labels": pred_class, "scores": pred_score, "bboxes": pred_boxes}
206
            )
207
        return pd.DataFrame(outcome, columns=["labels", "scores", "bboxes"])
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc