Coretex
converter.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 Optional
19 
20 from .converter_processor_factory import ConverterProcessorFactory
21 from .base_converter import ConverterProcessorType
22 from ..dataset import ImageDataset
23 
24 
25 def convert(type: ConverterProcessorType, datasetName: str, projectId: int, datasetPath: str) -> Optional[ImageDataset]:
26  """
27  Converts and uploads the given dataset to Coretex Format
28 
29  Parameters
30  ----------
31  type : ConverterProcessorType
32  dataset format type (coco, yolo, createML, voc, labelMe, pascalSeg)
33  datasetName : str
34  name of dataset
35  projectId : str
36  id of Coretex Project
37  datasetPath : str
38  path to dataset
39 
40  Returns
41  -------
42  Optional[ImageDataset] -> The converted ImageDataset object
43 
44  Example
45  -------
46  >>> from coretex import convert, ConverterProcessorType
47  \b
48  >>> dataset = convert(
49  type = ConvertProcessorType.coco,
50  datasetName = "coretex_dataset",
51  projectId = 1023,
52  datasetPath = "path/to/dataset"
53  )
54  >>> if dataset is not None:
55  print("Dataset converted successfully")
56  """
57 
58  return ConverterProcessorFactory(type).create(datasetName, projectId, datasetPath).convert()