Skip to content

Commit 5c31d92

Browse files
author
Vuk Manojlovic
committed
Merge branch 'develop' into CTX-4070
* develop: CTX-4079: Redesigned terminate condition for experiment worker process - Added log file output for experiment worker process for debugging purposes CTX-4251: Update "model-queue/custom" to "run" endpoint Version bump CTX-4219: Make root not private to make it available outside the class - Name starts with an underscore to mark it as internally used don't touch CTX-4083: Moved heartbeat to the metrics worker process - Renamed metrics worker process to experiment worker Version bump CTX-4102: Fix terminating metrics process on experiment process kill CTX-4166: Implemented Sequence sample import CTX-3890: Changed division to // CTX-3890: Converted wider code to be compatible with int based bounding boxes CTX-3890: Changed width and height variables from float to int Update README.md
2 parents 620fac0 + 9415689 commit 5c31d92

31 files changed

+604
-224
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ if __name__ == "__main__":
4444
initializeProject(main)
4545
```
4646

47-
(Read the documentation and learn how you can migrate your project to the Coretex platform -> [Migrate your project to Coretex](https://app.gitbook.com/o/6QxmEiF5ygi67vFH3kV1/s/YoN0XCeop3vrJ0hyRKxx/getting-started/demo-experiments/migrate-your-project-to-coretex))
47+
Read the documentation and learn how you can migrate your project to the Coretex platform -> [Migrate your project to Coretex](https://app.gitbook.com/o/6QxmEiF5ygi67vFH3kV1/s/YoN0XCeop3vrJ0hyRKxx/getting-started/demo-experiments/migrate-your-project-to-coretex)
4848

4949
## Key Features
5050

coretex/coretex/annotation/image/bbox.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,49 +28,49 @@ class BBox(Codable):
2828
2929
Properties
3030
----------
31-
minX : float
31+
minX : int
3232
top left x coordinate
33-
minY : float
33+
minY : int
3434
top left y coordinate
35-
width : float
35+
width : int
3636
width of the bounding box
37-
height : float
37+
height : int
3838
height of the bounding box
3939
"""
4040

41-
def __init__(self, minX: float = 0, minY: float = 0, width: float = 0, height: float = 0) -> None:
41+
def __init__(self, minX: int = 0, minY: int = 0, width: int = 0, height: int = 0) -> None:
4242
self.minX: Final = minX
4343
self.minY: Final = minY
4444

4545
self.width: Final = width
4646
self.height: Final = height
4747

4848
@property
49-
def maxX(self) -> float:
49+
def maxX(self) -> int:
5050
"""
5151
Returns
5252
-------
53-
float -> bottom right x coordinate
53+
int -> bottom right x coordinate
5454
"""
5555

5656
return self.minX + self.width
5757

5858
@property
59-
def maxY(self) -> float:
59+
def maxY(self) -> int:
6060
"""
6161
Returns
6262
-------
63-
float -> bottom right y coordinate
63+
int -> bottom right y coordinate
6464
"""
6565

6666
return self.minY + self.height
6767

6868
@property
69-
def polygon(self) -> List[float]:
69+
def polygon(self) -> List[int]:
7070
"""
7171
Returns
7272
-------
73-
List[float] -> Bounding box represented as a polygon (x, y) values
73+
List[int] -> Bounding box represented as a polygon (x, y) values
7474
"""
7575

7676
return [
@@ -91,20 +91,20 @@ def _keyDescriptors(cls) -> Dict[str, KeyDescriptor]:
9191
return descriptors
9292

9393
@classmethod
94-
def create(cls, minX: float, minY: float, maxX: float, maxY: float) -> Self:
94+
def create(cls, minX: int, minY: int, maxX: int, maxY: int) -> Self:
9595
"""
9696
Utility constructor which has maxX and maxY as parameters instead
9797
of width and height
9898
9999
Parameters
100100
----------
101-
minX : float
101+
minX : int
102102
top left x coordinate
103-
minY : float
103+
minY : int
104104
top left y coordinate
105-
maxX : float
105+
maxX : int
106106
bottom right x coordinate
107-
maxY : float
107+
maxY : int
108108
bottom right y coordinate
109109
110110
Returns
@@ -115,15 +115,15 @@ def create(cls, minX: float, minY: float, maxX: float, maxY: float) -> Self:
115115
return cls(minX, minY, maxX - minX, maxY - minY)
116116

117117
@classmethod
118-
def fromPoly(cls, polygon: List[float]) -> Self:
118+
def fromPoly(cls, polygon: List[int]) -> Self:
119119
"""
120120
Creates bounding box from a polygon, by finding
121121
the minimum x and y coordinates and calculating
122122
width and height of the polygon
123123
124124
Parameters
125125
----------
126-
polygon : List[float]
126+
polygon : List[int]
127127
list of x, y points - length must be even
128128
129129
Returns
@@ -140,8 +140,8 @@ def fromPoly(cls, polygon: List[float]) -> Self:
140140
"minX: 0, minY: 0, width: 4, height: 3"
141141
"""
142142

143-
x: List[float] = []
144-
y: List[float] = []
143+
x: List[int] = []
144+
y: List[int] = []
145145

146146
for index, value in enumerate(polygon):
147147
if index % 2 == 0:

coretex/coretex/annotation/image/coretex_format.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@
2929
from ....codable import Codable, KeyDescriptor
3030

3131

32-
SegmentationType = List[float]
32+
SegmentationType = List[int]
3333

3434

35-
def toPoly(segmentation: List[float]) -> List[Tuple[float, float]]:
36-
points: List[Tuple[float, float]] = []
35+
def toPoly(segmentation: List[int]) -> List[Tuple[int, int]]:
36+
points: List[Tuple[int, int]] = []
3737

3838
for index in range(0, len(segmentation) - 1, 2):
3939
points.append((segmentation[index], segmentation[index + 1]))
@@ -145,42 +145,42 @@ def extractBinaryMask(self, width: int, height: int) -> np.ndarray:
145145

146146
return binaryMask
147147

148-
def centroid(self) -> Tuple[float, float]:
148+
def centroid(self) -> Tuple[int, int]:
149149
"""
150150
Calculates centroid of segmentations
151151
152152
Returns
153153
-------
154-
Tuple[float, float] -> x, y coordinates of centroid
154+
Tuple[int, int] -> x, y coordinates of centroid
155155
"""
156156

157157
flattenedSegmentations = [element for sublist in self.segmentations for element in sublist]
158158

159159
listCX = [value for index, value in enumerate(flattenedSegmentations) if index % 2 == 0]
160-
centerX = fsum(listCX) / len(listCX)
160+
centerX = sum(listCX) // len(listCX)
161161

162162
listCY = [value for index, value in enumerate(flattenedSegmentations) if index % 2 != 0]
163-
centerY = fsum(listCY) / len(listCY)
163+
centerY = sum(listCY) // len(listCY)
164164

165165
return centerX, centerY
166166

167-
def centerSegmentations(self, newCentroid: Tuple[float, float]) -> None:
167+
def centerSegmentations(self, newCentroid: Tuple[int, int]) -> None:
168168
"""
169169
Centers segmentations to the specified center point
170170
171171
Parameters
172172
----------
173-
newCentroid : Tuple[float, float]
173+
newCentroid : Tuple[int, int]
174174
x, y coordinates of centroid
175175
"""
176176

177177
newCenterX, newCenterY = newCentroid
178178
oldCenterX, oldCenterY = self.centroid()
179179

180-
modifiedSegmentations: List[List[float]] = []
180+
modifiedSegmentations: List[List[int]] = []
181181

182182
for segmentation in self.segmentations:
183-
modifiedSegmentation: List[float] = []
183+
modifiedSegmentation: List[int] = []
184184

185185
for i in range(0, len(segmentation), 2):
186186
x = segmentation[i] + (newCenterX - oldCenterX)
@@ -203,7 +203,7 @@ def rotateSegmentations(self, degrees: int) -> None:
203203
degree of rotation
204204
"""
205205

206-
rotatedSegmentations: List[List[float]] = []
206+
rotatedSegmentations: List[List[int]] = []
207207
centerX, centerY = self.centroid()
208208

209209
# because rotations with image and segmentations doesn't go in same direction
@@ -212,14 +212,14 @@ def rotateSegmentations(self, degrees: int) -> None:
212212
cosang, sinang = cos(theta), sin(theta)
213213

214214
for segmentation in self.segmentations:
215-
rotatedSegmentation: List[float] = []
215+
rotatedSegmentation: List[int] = []
216216

217217
for i in range(0, len(segmentation), 2):
218218
x = segmentation[i] - centerX
219219
y = segmentation[i + 1] - centerY
220220

221-
newX = (x * cosang - y * sinang) + centerX
222-
newY = (x * sinang + y * cosang) + centerY
221+
newX = int(x * cosang - y * sinang) + centerX
222+
newY = int(x * sinang + y * cosang) + centerY
223223

224224
rotatedSegmentation.append(newX)
225225
rotatedSegmentation.append(newY)
@@ -238,17 +238,17 @@ class CoretexImageAnnotation(Codable):
238238
----------
239239
name : str
240240
name of annotation class
241-
width : float
241+
width : int
242242
width of annotation
243-
height : float
243+
height : int
244244
height of annotation
245245
instances : List[CoretexSegmentationInstance]
246246
list of SegmentationInstance objects
247247
"""
248248

249249
name: str
250-
width: float
251-
height: float
250+
width: int
251+
height: int
252252
instances: List[CoretexSegmentationInstance]
253253

254254
@classmethod
@@ -262,8 +262,8 @@ def _keyDescriptors(cls) -> Dict[str, KeyDescriptor]:
262262
def create(
263263
cls,
264264
name: str,
265-
width: float,
266-
height: float,
265+
width: int,
266+
height: int,
267267
instances: List[CoretexSegmentationInstance]
268268
) -> Self:
269269
"""
@@ -273,9 +273,9 @@ def create(
273273
----------
274274
name : str
275275
name of annotation class
276-
width : float
276+
width : int
277277
width of annotation
278-
height : float
278+
height : int
279279
height of annotation
280280
instances : List[CoretexSegmentationInstance]
281281
list of SegmentationInstance objects

coretex/coretex/conversion/converters/create_ml_converter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ def _extractLabels(self) -> Set[str]:
5353

5454
return labels
5555

56-
def __extractBBox(self, bbox: Dict[str, float]) -> BBox:
56+
def __extractBBox(self, bbox: Dict[str, int]) -> BBox:
5757
return BBox(
58-
bbox["x"] - bbox["width"] / 2,
59-
bbox["y"] - bbox["height"] / 2,
58+
bbox["x"] - bbox["width"] // 2,
59+
bbox["y"] - bbox["height"] // 2,
6060
bbox["width"],
6161
bbox["height"]
6262
)

coretex/coretex/conversion/converters/human_segmentation_converter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def _dataSource(self) -> List[str]:
6565
def _extractLabels(self) -> Set[str]:
6666
return set(["background", "human"])
6767

68-
def __extractPolygons(self, annotationPath: str, imageWidth: int, imageHeight: int) -> List[List[float]]:
68+
def __extractPolygons(self, annotationPath: str, imageWidth: int, imageHeight: int) -> List[List[int]]:
6969
maskImage = Image.open(annotationPath)
7070
if maskImage is None:
7171
return []
@@ -81,7 +81,7 @@ def __extractPolygons(self, annotationPath: str, imageWidth: int, imageHeight: i
8181

8282
contours = skimage.measure.find_contours(subMaskArray, 0.5)
8383

84-
segmentations: List[List[float]] = []
84+
segmentations: List[List[int]] = []
8585
for contour in contours:
8686
for i in range(len(contour)):
8787
row, col = contour[i]

coretex/coretex/conversion/converters/label_me_converter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def __extractInstance(self, shape: Dict[str, Any]) -> Optional[CoretexSegmentati
6262
logging.getLogger("coretexpylib").info(f">> [Coretex] Class: ({label}) is not a part of dataset")
6363
return None
6464

65-
points: List[float] = np.array(shape["points"]).flatten().tolist()
65+
points: List[int] = np.array(shape["points"]).flatten().tolist()
6666
bbox = BBox.fromPoly(points)
6767

6868
return CoretexSegmentationInstance.create(coretexClass.classIds[0], bbox, [points])

coretex/coretex/conversion/converters/pascal/instance_extractor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from ....dataset import ImageDataset
3232

3333

34-
ContourPoints = List[List[float]]
34+
ContourPoints = List[List[int]]
3535
SegmentationPolygon = List[ContourPoints]
3636

3737

coretex/coretex/conversion/converters/pascal/pascal_2012_converter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import glob
2222
import xml.etree.ElementTree as ET
2323

24-
from .shared import getTag, toFloat
24+
from .shared import getTag, toInt
2525
from .instance_extractor import InstanceExtractor
2626
from ...base_converter import BaseConverter
2727
from .....coretex import CoretexImageAnnotation
@@ -84,7 +84,7 @@ def __extractImageAnnotation(self, root: ET.Element) -> None:
8484
if size is None:
8585
return
8686

87-
width, height = toFloat(size, "width", "height")
87+
width, height = toInt(size, "width", "height")
8888
if width is None or height is None:
8989
return
9090

coretex/coretex/conversion/converters/pascal/shared.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ def toFloat(rootEl: ET.Element, firstEl: str, secondEl: str) -> Tuple[Optional[f
3838
return (float(firstVal), float(secondVal))
3939

4040

41+
def toInt(rootEl: ET.Element, firstEl: str, secondEl: str) -> Tuple[Optional[int], Optional[int]]:
42+
firstVal = getTag(rootEl, firstEl)
43+
secondVal = getTag(rootEl, secondEl)
44+
45+
if firstVal is None or secondVal is None:
46+
return (None, None)
47+
48+
return (int(firstVal), int(secondVal))
49+
50+
4151
def getBoxes(bndbox: ET.Element) -> Optional[Dict[str, float]]:
4252
xmin, ymin = toFloat(bndbox, "xmin", "ymin")
4353
xmax, ymax = toFloat(bndbox, "xmax", "ymax")

coretex/coretex/conversion/converters/voc_converter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import glob
2323
import xml.etree.ElementTree as ET
2424

25-
from .pascal.shared import getTag, getBoxes, toFloat
25+
from .pascal.shared import getTag, getBoxes, toInt
2626
from ..base_converter import BaseConverter
2727
from ...annotation import CoretexImageAnnotation, CoretexSegmentationInstance, BBox
2828

@@ -91,7 +91,7 @@ def _extractImageAnnotation(self, root: ET.Element) -> None:
9191
if size is None:
9292
return
9393

94-
width, height = toFloat(size, "width", "height")
94+
width, height = toInt(size, "width", "height")
9595
if width is None or height is None:
9696
return
9797

0 commit comments

Comments
 (0)