AMMICO/misinformation/objects.py
xiaohemaikoo fdcb228294
M objdect (#23)
* colors expression by KMean algorithm

* object detection by imageai

* object detection by cvlib

* add encapsulation of object detection

* remove encapsulation of objdetect v0

* objects expression to dict

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* added imageai to requirements

* add objects to dictionary

* update for AnalysisMethod baseline

* add objects dection support explore_analysis display

* extend python version of misinf to allow imageai

* account for older python

* use global functionality for dict to csv convert

* update for docker build

* docker will build now but ipywidgets still not working

* test code

* include test data folder in repo

* add some sample images

* load cvs labels to dict

* add test data

* retrigger checks

* add map to human coding

* get orders from dict, missing dep

* add module to test accuracy

* retrigger checks

* retrigger checks

* now removing imageai

* removed imageai

* move labelmanager to analyse

* multiple faces in mydict

* fix pre-commit issues

* map mydict

* hide imageai

* objects default using cvlib, isolate and disable imageai

* correct python version

* refactor faces tests

* refactor objects tests

* sonarcloud issues

* refactor utils tests

* address code smells

* update readme

* update notebook without imageai

Co-authored-by: Ma Xianghe <825074348@qq.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: iulusoy <inga.ulusoy@uni-heidelberg.de>
2022-10-04 11:34:44 +02:00

53 строки
1.5 KiB
Python

from misinformation.utils import AnalysisMethod
from misinformation.objects_cvlib import ObjectCVLib
from misinformation.objects_cvlib import init_default_objects
# from misinformation.objects_imageai import ObjectImageAI
class ObjectDetectorClient(AnalysisMethod):
def __init__(self):
# The detector is default to CVLib
self.detector = ObjectCVLib()
def set_client_to_imageai(self):
# disable imageai temporarily
# self.detector = ObjectImageAI()
# maybe reactivate if new imageai release comes out
pass
def set_client_to_cvlib(self):
self.detector = ObjectCVLib()
def analyse_image(self, subdict=None):
"""Localize objects in the local image.
Args:
subdict: The dictionary for an image expression instance.
"""
return self.detector.analyse_image(subdict)
class ObjectDetector(AnalysisMethod):
od_client = ObjectDetectorClient()
def __init__(self, subdict: dict):
super().__init__(subdict)
self.subdict.update(self.set_keys())
def set_keys(self):
return init_default_objects()
def analyse_image(self):
self.subdict = ObjectDetector.od_client.analyse_image(self.subdict)
return self.subdict
@staticmethod
def set_client_to_cvlib():
ObjectDetector.od_client.set_client_to_cvlib()
@staticmethod
def set_client_to_imageai():
ObjectDetector.od_client.set_client_to_imageai()