Coretex
converter_processor_factory.py
1 # Copyright (C) 2023 Coretex LLC
2 
3 # This file is part of Coretex.ai
4 
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License as
7 # published by the Free Software Foundation, either version 3 of the
8 # License, or (at your option) any later version.
9 
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU Affero General Public License for more details.
14 
15 # You should have received a copy of the GNU Affero General Public License
16 # along with this program. If not, see <https://www.gnu.org/licenses/>.
17 
18 from typing import Final
19 
20 from .base_converter import ConverterProcessorType, BaseConverter
21 from .converters import *
22 
23 
25  """
26  Factory class used to create different types
27  of BaseConverter objects based on the convertProcessorType
28  property of the class
29 
30  Properties
31  ----------
32  convertProcessorType : ConverterProcessorType
33  type of converter for convertin dataset
34  """
35 
36  def __init__(self, convertProcessorType: ConverterProcessorType):
37  self.typetype: Final = convertProcessorType
38 
39  def create(self, datasetName: str, projectId: int, datasetPath: str) -> BaseConverter:
40  """
41  Creates BaseConverter based on the convertProcessorType
42  property of the class
43 
44  Parameters
45  ----------
46  datasetName : str
47  name of dataset
48  projectId : int
49  id of Coretex Project
50  datasetPath : str
51  path to dataset
52 
53  Returns
54  -------
55  Appropriate BaseConverter object based on
56  convertProcessorType
57  """
58 
59  if self.typetype == ConverterProcessorType.coco:
60  return COCOConverter(datasetName, projectId, datasetPath)
61 
62  if self.typetype == ConverterProcessorType.yolo:
63  return YoloConverter(datasetName, projectId, datasetPath)
64 
65  if self.typetype == ConverterProcessorType.createML:
66  return CreateMLConverter(datasetName, projectId, datasetPath)
67 
68  if self.typetype == ConverterProcessorType.voc:
69  return VOCConverter(datasetName, projectId, datasetPath)
70 
71  if self.typetype == ConverterProcessorType.labelMe:
72  return LabelMeConverter(datasetName, projectId, datasetPath)
73 
74  if self.typetype == ConverterProcessorType.pascalSeg:
75  return PascalSegConverter(datasetName, projectId, datasetPath)
76 
77  if self.typetype == ConverterProcessorType.humanSegmentation:
78  return HumanSegmentationConverter(datasetName, projectId, datasetPath)
79 
80  if self.typetype == ConverterProcessorType.cityScape:
81  return CityScapeConverter(datasetName, projectId, datasetPath)
82 
83  raise RuntimeError()
BaseConverter create(self, str datasetName, int projectId, str datasetPath)