|
15 | 15 | import requests |
16 | 16 | from botocore.exceptions import ClientError |
17 | 17 | from lib.app.analytics.aggregators import DataAggregator |
18 | | -from lib.app.analytics.common import aggregate_image_annotations_as_df |
19 | 18 | from lib.app.analytics.common import consensus |
20 | | -from lib.app.analytics.common import consensus_plot |
21 | 19 | from lib.core.conditions import Condition |
22 | 20 | from lib.core.conditions import CONDITION_EQ as EQ |
23 | 21 | from lib.core.entities import FolderEntity |
@@ -320,99 +318,6 @@ def execute(self): |
320 | 318 | return self._response |
321 | 319 |
|
322 | 320 |
|
323 | | -class BenchmarkUseCase(BaseUseCase): |
324 | | - def __init__( |
325 | | - self, |
326 | | - project: ProjectEntity, |
327 | | - ground_truth_folder_name: str, |
328 | | - folder_names: list, |
329 | | - export_dir: str, |
330 | | - image_list: list, |
331 | | - annotation_type: str, |
332 | | - show_plots: bool, |
333 | | - ): |
334 | | - super().__init__() |
335 | | - self._project = project |
336 | | - self._ground_truth_folder_name = ground_truth_folder_name |
337 | | - self._folder_names = folder_names |
338 | | - self._export_dir = export_dir |
339 | | - self._image_list = image_list |
340 | | - self._annotation_type = annotation_type |
341 | | - self._show_plots = show_plots |
342 | | - |
343 | | - def execute(self): |
344 | | - project_df = aggregate_image_annotations_as_df(self._export_dir) |
345 | | - gt_project_df = project_df[ |
346 | | - project_df["folderName"] == self._ground_truth_folder_name |
347 | | - ] |
348 | | - benchmark_dfs = [] |
349 | | - for folder_name in self._folder_names: |
350 | | - folder_df = project_df[project_df["folderName"] == folder_name] |
351 | | - project_gt_df = pd.concat([folder_df, gt_project_df]) |
352 | | - project_gt_df = project_gt_df[project_gt_df["instanceId"].notna()] |
353 | | - |
354 | | - if self._image_list is not None: |
355 | | - project_gt_df = project_gt_df.loc[ |
356 | | - project_gt_df["itemName"].isin(self._image_list) |
357 | | - ] |
358 | | - |
359 | | - project_gt_df.query("type == '" + self._annotation_type + "'", inplace=True) |
360 | | - |
361 | | - project_gt_df = project_gt_df.groupby( |
362 | | - ["itemName", "instanceId", "folderName"] |
363 | | - ) |
364 | | - |
365 | | - def aggregate_attributes(instance_df): |
366 | | - def attribute_to_list(attribute_df): |
367 | | - attribute_names = list(attribute_df["attributeName"]) |
368 | | - attribute_df["attributeNames"] = len(attribute_df) * [ |
369 | | - attribute_names |
370 | | - ] |
371 | | - return attribute_df |
372 | | - |
373 | | - attributes = None |
374 | | - if not instance_df["attributeGroupName"].isna().all(): |
375 | | - attrib_group_name = instance_df.groupby("attributeGroupName")[ |
376 | | - ["attributeGroupName", "attributeName"] |
377 | | - ].apply(attribute_to_list) |
378 | | - attributes = dict( |
379 | | - zip( |
380 | | - attrib_group_name["attributeGroupName"], |
381 | | - attrib_group_name["attributeNames"], |
382 | | - ) |
383 | | - ) |
384 | | - |
385 | | - instance_df.drop( |
386 | | - ["attributeGroupName", "attributeName"], axis=1, inplace=True |
387 | | - ) |
388 | | - instance_df.drop_duplicates( |
389 | | - subset=["itemName", "instanceId", "folderName"], inplace=True |
390 | | - ) |
391 | | - instance_df["attributes"] = [attributes] |
392 | | - return instance_df |
393 | | - |
394 | | - project_gt_df = project_gt_df.apply(aggregate_attributes).reset_index( |
395 | | - drop=True |
396 | | - ) |
397 | | - unique_images = set(project_gt_df["itemName"]) |
398 | | - all_benchmark_data = [] |
399 | | - for image_name in unique_images: |
400 | | - image_data = image_consensus( |
401 | | - project_gt_df, image_name, self._annotation_type |
402 | | - ) |
403 | | - all_benchmark_data.append(pd.DataFrame(image_data)) |
404 | | - benchmark_project_df = pd.concat(all_benchmark_data, ignore_index=True) |
405 | | - benchmark_project_df = benchmark_project_df[ |
406 | | - benchmark_project_df["folderName"] == folder_name |
407 | | - ] |
408 | | - benchmark_dfs.append(benchmark_project_df) |
409 | | - benchmark_df = pd.concat(benchmark_dfs, ignore_index=True) |
410 | | - if self._show_plots: |
411 | | - consensus_plot(benchmark_df, self._folder_names) |
412 | | - self._response.data = benchmark_df |
413 | | - return self._response |
414 | | - |
415 | | - |
416 | 321 | class ConsensusUseCase(BaseUseCase): |
417 | 322 | def __init__( |
418 | 323 | self, |
|
0 commit comments