mucahitkantepe commited on
Commit
35e2465
Β·
1 Parent(s): 1b285c4

outfits: more slots, set-aware contrast, anchor-aware scandi, tighter rationale

Browse files

- PAIRING_RULES: add outerwear to top/bottom anchors; add accessory to
dress/outerwear/swimwear. Documents the order-matters rationale.
- _OutfitState now tracks axes_covered (the set of axes the outfit has
pushed past +/-0.3) and anchor_scandi.
- _contrast_score rewards two paths: classic flips against running mean,
AND extending to a fresh axis the outfit hasn't expressed. Fixes the
late-pick dilution where mean-based contrast undervalued a 4th item
bringing in a brand-new dimension.
- Anchor-aware scandi floor: 0.85 for strongly-Scandi anchors (don't
drag in non-Scandi picks), 0.5 for weakly-Scandi (don't reject
Continental complements), 0.7 default in the middle band.
- Rationale capped at ~3 bits; flip-axis takes priority over color
harmony when both are present.
- Outfit palette dedups near-identical colors (delta_e < 8) so two beige
items show one chip with merged source list.

Files changed (1) hide show
  1. taste/outfits.py +116 -33
taste/outfits.py CHANGED
@@ -45,15 +45,20 @@ from taste.scandi import bias as scandi_bias
45
 
46
  # Pairing rules: anchor bucket β†’ ordered list of complement buckets to fill.
47
  # `dress` notably has no `bottom` since it's already a one-piece.
 
 
 
 
 
48
  PAIRING_RULES: dict[str, list[str]] = {
49
- "dress": ["shoes", "bag", "outerwear"],
50
- "top": ["bottom", "shoes", "bag"],
51
- "bottom": ["top", "shoes", "bag"],
52
- "outerwear": ["dress", "shoes", "bag"],
53
  "shoes": ["dress", "bag"],
54
  "bag": ["dress", "shoes"],
55
  "intimates": [], # not stylist-pairable; suppress
56
- "swimwear": ["bag"],
57
  "accessory": [],
58
  "unknown": [],
59
  }
@@ -195,6 +200,22 @@ def _row_scandi(row: dict) -> float:
195
  return float(s) if s is not None else 0.5
196
 
197
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
198
  def _color_score(
199
  cand_dom: np.ndarray | None,
200
  outfit_doms: list[np.ndarray],
@@ -222,14 +243,27 @@ def _color_score(
222
  return de_score
223
 
224
 
225
- def _contrast_score(cand_axes: dict[str, float], running_axes: dict[str, float]) -> tuple[float, list[str]]:
226
- """Reward outfits where the candidate adds new contrast.
227
-
228
- Returns (score, list of axes the candidate flips). The score saturates
229
- quickly because adding 2 contrast axes is plenty β€” 3+ tends to look
230
- incoherent ("kitchen-sink styling").
 
 
 
 
 
 
 
 
 
 
 
 
231
  """
232
  flipped: list[str] = []
 
233
  for a in AXES:
234
  p = running_axes.get(a, 0.0)
235
  c = cand_axes.get(a, 0.0)
@@ -237,9 +271,11 @@ def _contrast_score(cand_axes: dict[str, float], running_axes: dict[str, float])
237
  continue
238
  if (p > 0.1 and c < -0.1) or (p < -0.1 and c > 0.1):
239
  flipped.append(a)
240
- n = len(flipped)
 
 
241
  score = min(1.0, 0.4 + 0.3 * n) # 0β†’0.4, 1β†’0.7, 2β†’1.0
242
- return score, flipped
243
 
244
 
245
  def _make_rationale(
@@ -249,19 +285,39 @@ def _make_rationale(
249
  cand_scandi: float,
250
  cand_dom: np.ndarray | None,
251
  ) -> str:
 
 
 
 
 
 
 
 
 
 
 
 
 
252
  bits: list[str] = []
253
  if cand_dom is not None:
254
  bits.append(_color_name(cand_dom))
255
- if color_score > 0.85:
 
 
 
 
 
 
 
256
  bits.append("color-harmonious")
257
  elif color_score > 0.6:
258
  bits.append("complementary tones")
259
- for a in flipped[:2]: # cap rationale length β€” 2 axes is the sweet spot
260
- sign = "pos" if cand_axes.get(a, 0.0) > 0 else "neg"
261
- label = _AXIS_LABELS[a][0 if sign == "pos" else 1]
262
- bits.append(f"adds {label}")
263
- if cand_scandi >= 0.7:
264
  bits.append("scandi-fit")
 
 
 
265
  return " Β· ".join(bits)
266
 
267
 
@@ -279,8 +335,11 @@ class _OutfitState:
279
  self.anchor_emb: np.ndarray | None = anchor_emb
280
  self.dom_labs: list[np.ndarray] = [dom] if dom is not None else []
281
  self.has_neutral: bool = bool(dom is not None and is_neutral(dom))
282
- self.axes_mean: dict[str, float] = _row_axes(anchor)
283
- self.scandi: list[float] = [_row_scandi(anchor)]
 
 
 
284
  self.n: int = 1
285
 
286
  def anchor_centroid(self) -> np.ndarray | None:
@@ -299,7 +358,11 @@ class _OutfitState:
299
  self.dom_labs.append(dom)
300
  if is_neutral(dom):
301
  self.has_neutral = True
302
- self.axes_mean = merge(self.axes_mean, _row_axes(prod), self.n)
 
 
 
 
303
  self.scandi.append(_row_scandi(prod))
304
  self.n += 1
305
 
@@ -363,7 +426,7 @@ def _pick_complement(
363
  _color_score(cand_dom, state.dom_labs, cand_neutral, state.has_neutral)
364
  )
365
 
366
- cscore, flipped = _contrast_score(_row_axes(c), state.axes_mean)
367
  contrast_raw.append(cscore)
368
  flipped_per.append(flipped)
369
 
@@ -372,6 +435,13 @@ def _pick_complement(
372
  # Color and contrast are already in [0, 1] β€” no min-max (would wash out
373
  # absolute differences and overweight tiny pool variation).
374
 
 
 
 
 
 
 
 
375
  best_idx, best_blend = -1, -1.0
376
  for i, c in enumerate(candidates):
377
  blend = (
@@ -379,7 +449,7 @@ def _pick_complement(
379
  + _W_SIM * norm_sim[i]
380
  + _W_COLOR * color_raw[i]
381
  + _W_CONTRAST * contrast_raw[i]
382
- ) * scandi_bias(_row_scandi(c))
383
  if blend > best_blend:
384
  best_idx, best_blend = i, blend
385
 
@@ -484,21 +554,34 @@ def compose_outfit(anchor_url: str, conn) -> dict | None:
484
  def _outfit_palette(anchor: dict, complements: list[dict]) -> list[dict]:
485
  """Merge dominant LABs across the outfit into a small swatch list.
486
 
487
- Each entry: `{source: "anchor"|<bucket>, lab: [L,a,b], hex: "#rrggbb", name: <color>}`
488
- The `source` field labels which slot the color came from so UIs can map
489
- swatches back to garments.
 
 
 
 
 
490
  """
491
  out: list[dict] = []
492
  for label, prod in [("anchor", anchor)] + [(c["bucket"], c["product"]) for c in complements]:
493
  dom = _row_dom(prod)
494
  if dom is None:
495
  continue
496
- out.append({
497
- "source": label,
498
- "lab": [float(v) for v in dom],
499
- "hex": lab_to_hex(dom),
500
- "name": _color_name(dom),
501
- })
 
 
 
 
 
 
 
 
502
  return out
503
 
504
 
 
45
 
46
  # Pairing rules: anchor bucket β†’ ordered list of complement buckets to fill.
47
  # `dress` notably has no `bottom` since it's already a one-piece.
48
+ #
49
+ # Order matters: each pick is scored against the running outfit state, so
50
+ # silhouette-shaping items (outerwear) come before finish items (shoes, bag,
51
+ # accessory). Accessory comes last on purpose β€” small pool (~24 in stock),
52
+ # and the rest of the outfit informs whether a belt/scarf adds anything.
53
  PAIRING_RULES: dict[str, list[str]] = {
54
+ "dress": ["shoes", "outerwear", "bag", "accessory"],
55
+ "top": ["bottom", "outerwear", "shoes", "bag"],
56
+ "bottom": ["top", "outerwear", "shoes", "bag"],
57
+ "outerwear": ["dress", "shoes", "bag", "accessory"],
58
  "shoes": ["dress", "bag"],
59
  "bag": ["dress", "shoes"],
60
  "intimates": [], # not stylist-pairable; suppress
61
+ "swimwear": ["bag", "accessory"],
62
  "accessory": [],
63
  "unknown": [],
64
  }
 
200
  return float(s) if s is not None else 0.5
201
 
202
 
203
+ def _scandi_floor_for_anchor(anchor_scandi: float) -> float:
204
+ """Choose the per-pick scandi-bias floor based on the anchor's score.
205
+
206
+ Anchor strongly Scandi (>=0.7) β†’ tighter floor (0.85): non-Scandi picks
207
+ can still surface only if they're far better on every other axis.
208
+ Anchor weakly Scandi (<0.4) β†’ looser floor (0.5): the anchor itself isn't
209
+ asking for Scandi, so don't penalize Continental complements that match
210
+ the anchor's actual style.
211
+ """
212
+ if anchor_scandi >= 0.7:
213
+ return 0.85
214
+ if anchor_scandi < 0.4:
215
+ return 0.5
216
+ return 0.7
217
+
218
+
219
  def _color_score(
220
  cand_dom: np.ndarray | None,
221
  outfit_doms: list[np.ndarray],
 
243
  return de_score
244
 
245
 
246
+ def _contrast_score(
247
+ cand_axes: dict[str, float],
248
+ running_axes: dict[str, float],
249
+ axes_covered: set[str],
250
+ ) -> tuple[float, list[str]]:
251
+ """Reward outfits where the candidate adds new contrast OR a fresh axis.
252
+
253
+ Two ways the candidate adds dimension:
254
+ - **flip**: candidate sits on the opposite side of the running mean for
255
+ an axis the outfit has already taken a stance on. Classic Bornstein
256
+ contrast (structure vs ease, masc vs fem).
257
+ - **extend**: candidate pushes a *new* axis past Β±0.3 that the outfit
258
+ hasn't expressed yet (covered set is empty for it). This matters for
259
+ late picks β€” running_axes dilutes as the outfit grows, so a 4th item
260
+ that introduces a new contrast axis would otherwise be invisible.
261
+
262
+ Returns (score, axes the candidate adds). Score saturates fast β€” 2
263
+ contributions is the styled sweet spot, 3+ reads as kitchen-sink.
264
  """
265
  flipped: list[str] = []
266
+ extended: list[str] = []
267
  for a in AXES:
268
  p = running_axes.get(a, 0.0)
269
  c = cand_axes.get(a, 0.0)
 
271
  continue
272
  if (p > 0.1 and c < -0.1) or (p < -0.1 and c > 0.1):
273
  flipped.append(a)
274
+ elif a not in axes_covered:
275
+ extended.append(a)
276
+ n = len(flipped) + len(extended)
277
  score = min(1.0, 0.4 + 0.3 * n) # 0β†’0.4, 1β†’0.7, 2β†’1.0
278
+ return score, flipped + extended
279
 
280
 
281
  def _make_rationale(
 
285
  cand_scandi: float,
286
  cand_dom: np.ndarray | None,
287
  ) -> str:
288
+ """Compose a short, prioritized rationale for a pick.
289
+
290
+ Order of importance, capped at 3 segments total to keep tile labels
291
+ glanceable:
292
+ 1. color name (anchors recognition: "is this beige? camel?")
293
+ 2. one strongest signal β€” the most informative bit. Flipped axis if
294
+ present (it's the rarest/most editorial), else color harmony.
295
+ 3. one secondary signal: scandi-fit, OR a second axis if there are
296
+ two flips and color harmony isn't loud.
297
+
298
+ The previous version stacked color + harmony + 2 axes + scandi (5 bits),
299
+ which read as noise. Concision improves trust in the pick.
300
+ """
301
  bits: list[str] = []
302
  if cand_dom is not None:
303
  bits.append(_color_name(cand_dom))
304
+
305
+ flipped_bits = [
306
+ f"adds {_AXIS_LABELS[a][0 if cand_axes.get(a, 0.0) > 0 else 1]}"
307
+ for a in flipped
308
+ ]
309
+ if flipped_bits:
310
+ bits.append(flipped_bits[0])
311
+ elif color_score > 0.85:
312
  bits.append("color-harmonious")
313
  elif color_score > 0.6:
314
  bits.append("complementary tones")
315
+
316
+ if cand_scandi >= 0.7 and len(bits) < 3:
 
 
 
317
  bits.append("scandi-fit")
318
+ elif len(flipped_bits) > 1 and len(bits) < 3:
319
+ bits.append(flipped_bits[1])
320
+
321
  return " Β· ".join(bits)
322
 
323
 
 
335
  self.anchor_emb: np.ndarray | None = anchor_emb
336
  self.dom_labs: list[np.ndarray] = [dom] if dom is not None else []
337
  self.has_neutral: bool = bool(dom is not None and is_neutral(dom))
338
+ anchor_axes = _row_axes(anchor)
339
+ self.axes_mean: dict[str, float] = anchor_axes
340
+ self.axes_covered: set[str] = {a for a, v in anchor_axes.items() if abs(v) > 0.3}
341
+ self.anchor_scandi: float = _row_scandi(anchor)
342
+ self.scandi: list[float] = [self.anchor_scandi]
343
  self.n: int = 1
344
 
345
  def anchor_centroid(self) -> np.ndarray | None:
 
358
  self.dom_labs.append(dom)
359
  if is_neutral(dom):
360
  self.has_neutral = True
361
+ prod_axes = _row_axes(prod)
362
+ self.axes_mean = merge(self.axes_mean, prod_axes, self.n)
363
+ for a, v in prod_axes.items():
364
+ if abs(v) > 0.3:
365
+ self.axes_covered.add(a)
366
  self.scandi.append(_row_scandi(prod))
367
  self.n += 1
368
 
 
426
  _color_score(cand_dom, state.dom_labs, cand_neutral, state.has_neutral)
427
  )
428
 
429
+ cscore, flipped = _contrast_score(_row_axes(c), state.axes_mean, state.axes_covered)
430
  contrast_raw.append(cscore)
431
  flipped_per.append(flipped)
432
 
 
435
  # Color and contrast are already in [0, 1] β€” no min-max (would wash out
436
  # absolute differences and overweight tiny pool variation).
437
 
438
+ # Anchor-aware scandi floor. If the anchor is strongly Scandi (>=0.7),
439
+ # tighten to 0.85 so we don't drag in obviously non-Scandi picks; if the
440
+ # anchor reads weakly Scandi (<0.4), loosen to 0.5 so we don't reject
441
+ # Continental complements that genuinely match the anchor's style. The
442
+ # default 0.7 floor is preserved in the middle band.
443
+ floor = _scandi_floor_for_anchor(state.anchor_scandi)
444
+
445
  best_idx, best_blend = -1, -1.0
446
  for i, c in enumerate(candidates):
447
  blend = (
 
449
  + _W_SIM * norm_sim[i]
450
  + _W_COLOR * color_raw[i]
451
  + _W_CONTRAST * contrast_raw[i]
452
+ ) * scandi_bias(_row_scandi(c), floor=floor)
453
  if blend > best_blend:
454
  best_idx, best_blend = i, blend
455
 
 
554
  def _outfit_palette(anchor: dict, complements: list[dict]) -> list[dict]:
555
  """Merge dominant LABs across the outfit into a small swatch list.
556
 
557
+ Each entry: `{source: "anchor"|<bucket>+", "+<bucket>, lab: [L,a,b], hex,
558
+ name}`. Near-identical colors (Ξ”E2000 < 8) are collapsed into a single
559
+ swatch β€” two beige items shouldn't show two beige chips. The merged
560
+ `source` field lists every slot that contributed, so the UI tooltip can
561
+ still tell the wearer what part of the outfit each color came from.
562
+
563
+ Anchor wins ties: when an anchor color and a complement color collapse,
564
+ the anchor's hex/name are kept (so the chip reads as "the look's beige").
565
  """
566
  out: list[dict] = []
567
  for label, prod in [("anchor", anchor)] + [(c["bucket"], c["product"]) for c in complements]:
568
  dom = _row_dom(prod)
569
  if dom is None:
570
  continue
571
+ merged = False
572
+ for entry in out:
573
+ existing = np.asarray(entry["lab"], dtype=np.float32)
574
+ if delta_e(dom, existing) < 8.0:
575
+ entry["source"] = f"{entry['source']}, {label}"
576
+ merged = True
577
+ break
578
+ if not merged:
579
+ out.append({
580
+ "source": label,
581
+ "lab": [float(v) for v in dom],
582
+ "hex": lab_to_hex(dom),
583
+ "name": _color_name(dom),
584
+ })
585
  return out
586
 
587