@@ -17,16 +17,16 @@ def _softmax(x: list[float]) -> list[float]:
17
17
18
18
def _exp (x ):
19
19
"""Compute e^x for a given x. A simple implementation of the exponential function."""
20
- return 2.718281828459045 ** x # Using an approximation of Euler's number e
20
+ return 2.718281828459045 ** x # Using an approximation of Euler's number e
21
21
22
22
23
23
class ImageWithMasksAndAttributes :
24
24
def __init__ (
25
- self ,
26
- image : np .ndarray ,
27
- masks : dict [str , np .ndarray ],
28
- attributes : dict [str , float ],
29
- categories_and_attributes : CategoriesAndAttributes ,
25
+ self ,
26
+ image : np .ndarray ,
27
+ masks : dict [str , np .ndarray ],
28
+ attributes : dict [str , float ],
29
+ categories_and_attributes : CategoriesAndAttributes ,
30
30
):
31
31
self .image : np .ndarray = image
32
32
self .masks : dict [str , np .ndarray ] = masks
@@ -41,7 +41,7 @@ def __init__(
41
41
42
42
self .selective_attribute_dict : dict [str , dict [str , float ]] = {}
43
43
for category in sorted (
44
- list (self .categories_and_attributes .selective_attributes .keys ())
44
+ list (self .categories_and_attributes .selective_attributes .keys ())
45
45
):
46
46
self .selective_attribute_dict [category ] = {}
47
47
temp_list : list [float ] = []
@@ -51,7 +51,7 @@ def __init__(
51
51
temp_list .append (self .attributes [attribute ])
52
52
softmax_list = _softmax (temp_list )
53
53
for i , attribute in enumerate (
54
- self .categories_and_attributes .selective_attributes [category ]
54
+ self .categories_and_attributes .selective_attributes [category ]
55
55
):
56
56
self .selective_attribute_dict [category ][attribute ] = softmax_list [i ]
57
57
@@ -67,17 +67,17 @@ def _max_value_tuple(some_dict: dict[str, float]) -> tuple[str, float]:
67
67
68
68
class ImageOfPerson (ImageWithMasksAndAttributes ):
69
69
def __init__ (
70
- self ,
71
- image : np .ndarray ,
72
- masks : dict [str , np .ndarray ],
73
- attributes : dict [str , float ],
74
- categories_and_attributes : CategoriesAndAttributes ,
70
+ self ,
71
+ image : np .ndarray ,
72
+ masks : dict [str , np .ndarray ],
73
+ attributes : dict [str , float ],
74
+ categories_and_attributes : CategoriesAndAttributes ,
75
75
):
76
76
super ().__init__ (image , masks , attributes , categories_and_attributes )
77
77
78
78
@classmethod
79
79
def from_parent_instance (
80
- cls , parent_instance : ImageWithMasksAndAttributes
80
+ cls , parent_instance : ImageWithMasksAndAttributes
81
81
) -> "ImageOfPerson" :
82
82
"""
83
83
Creates an instance of ImageOfPerson using the properties of an
@@ -156,7 +156,7 @@ def describe(self) -> str:
156
156
hair_colour_str = "gray"
157
157
158
158
if (
159
- male
159
+ male
160
160
): # here 'male' is only used to determine whether it is confident to decide whether the person has beard
161
161
if not facial_hair [0 ] == "No_Beard" :
162
162
description += "and has beard. "
@@ -180,7 +180,7 @@ def describe(self) -> str:
180
180
if necktie [0 ]:
181
181
wearables .append ("a necktie" )
182
182
description += (
183
- ", " .join (wearables [:- 2 ] + [" and " .join (wearables [- 2 :])]) + ". "
183
+ ", " .join (wearables [:- 2 ] + [" and " .join (wearables [- 2 :])]) + ". "
184
184
)
185
185
186
186
if description == "This customer has " :
@@ -209,17 +209,17 @@ def describe(self) -> str:
209
209
210
210
class ImageOfCloth (ImageWithMasksAndAttributes ):
211
211
def __init__ (
212
- self ,
213
- image : np .ndarray ,
214
- masks : dict [str , np .ndarray ],
215
- attributes : dict [str , float ],
216
- categories_and_attributes : CategoriesAndAttributes ,
212
+ self ,
213
+ image : np .ndarray ,
214
+ masks : dict [str , np .ndarray ],
215
+ attributes : dict [str , float ],
216
+ categories_and_attributes : CategoriesAndAttributes ,
217
217
):
218
218
super ().__init__ (image , masks , attributes , categories_and_attributes )
219
219
220
220
@classmethod
221
221
def from_parent_instance (
222
- cls , parent_instance : ImageWithMasksAndAttributes
222
+ cls , parent_instance : ImageWithMasksAndAttributes
223
223
) -> "ImageOfCloth" :
224
224
"""
225
225
Creates an instance of ImageOfCloth using the properties of an
@@ -240,24 +240,31 @@ def describe(self) -> str:
240
240
"down" : self .attributes ["down" ] > self .categories_and_attributes .thresholds_pred ["down" ],
241
241
"outwear" : self .attributes ["outwear" ] > self .categories_and_attributes .thresholds_pred ["outwear" ],
242
242
"dress" : self .attributes ["dress" ] > self .categories_and_attributes .thresholds_pred ["dress" ],
243
-
244
- "short sleeve top" : self .attributes ["short sleeve top" ] > self .categories_and_attributes .thresholds_pred ["short sleeve top" ],
245
- "long sleeve top" : self .attributes ["long sleeve top" ] > self .categories_and_attributes .thresholds_pred ["long sleeve top" ],
246
- "short sleeve outwear" : self .attributes ["short sleeve outwear" ] > self .categories_and_attributes .thresholds_pred ["short sleeve outwear" ],
247
- "long sleeve outwear" : self .attributes ["long sleeve outwear" ] > self .categories_and_attributes .thresholds_pred ["long sleeve outwear" ],
243
+
244
+ "short sleeve top" : self .attributes ["short sleeve top" ] >
245
+ self .categories_and_attributes .thresholds_pred ["short sleeve top" ],
246
+ "long sleeve top" : self .attributes ["long sleeve top" ] > self .categories_and_attributes .thresholds_pred [
247
+ "long sleeve top" ],
248
+ "short sleeve outwear" : self .attributes ["short sleeve outwear" ] >
249
+ self .categories_and_attributes .thresholds_pred ["short sleeve outwear" ],
250
+ "long sleeve outwear" : self .attributes ["long sleeve outwear" ] >
251
+ self .categories_and_attributes .thresholds_pred ["long sleeve outwear" ],
248
252
"vest" : self .attributes ["vest" ] > self .categories_and_attributes .thresholds_pred ["vest" ],
249
253
"sling" : self .attributes ["sling" ] > self .categories_and_attributes .thresholds_pred ["sling" ],
250
254
"outwear" : self .attributes ["outwear" ] > self .categories_and_attributes .thresholds_pred ["outwear" ],
251
255
"shorts" : self .attributes ["shorts" ] > self .categories_and_attributes .thresholds_pred ["shorts" ],
252
256
"trousers" : self .attributes ["trousers" ] > self .categories_and_attributes .thresholds_pred ["trousers" ],
253
257
"skirt" : self .attributes ["skirt" ] > self .categories_and_attributes .thresholds_pred ["skirt" ],
254
- "short sleeve dress" : self .attributes ["short sleeve dress" ] > self .categories_and_attributes .thresholds_pred ["short sleeve dress" ],
255
- "long sleeve dress" : self .attributes ["long sleeve dress" ] > self .categories_and_attributes .thresholds_pred ["long sleeve dress" ],
256
- "vest dress" : self .attributes ["vest dress" ] > self .categories_and_attributes .thresholds_pred ["vest dress" ],
257
- "sling dress" : self .attributes ["sling dress" ] > self .categories_and_attributes .thresholds_pred ["sling dress" ],
258
+ "short sleeve dress" : self .attributes ["short sleeve dress" ] >
259
+ self .categories_and_attributes .thresholds_pred ["short sleeve dress" ],
260
+ "long sleeve dress" : self .attributes ["long sleeve dress" ] >
261
+ self .categories_and_attributes .thresholds_pred ["long sleeve dress" ],
262
+ "vest dress" : self .attributes ["vest dress" ] > self .categories_and_attributes .thresholds_pred [
263
+ "vest dress" ],
264
+ "sling dress" : self .attributes ["sling dress" ] > self .categories_and_attributes .thresholds_pred [
265
+ "sling dress" ],
258
266
},
259
267
"description" : "this descrcription will be completed if we find out it is better to do it here." ,
260
268
}
261
269
262
270
return result
263
-
0 commit comments