A pretext task draws its training signal from recorded inputs. Its views must preserve the facts needed by the later decision.
Self-supervised objectives and valid views
Start at the decision
A warehouse model predicts whether a parcel image needs manual damage review. Unlabeled photographs are plentiful; confirmed damage labels are scarce. Pretraining may teach an encoder useful visual structure, but the goal is better review decisions on later parcels, not a low pretext loss. Define the review clock, parcel identity and target before creating views. The target contract keeps the downstream test honest.
Write an invariance rule
Two crops of one parcel can form a positive pair only when each retains evidence relevant to damage. A crop that removes a crushed corner changes the answer, so forcing its embedding to match a full photograph can teach the model to ignore the defect. Background color may be harmless for one camera but carry a site cue for another. Inspect pairs by damage type and depot rather than accepting a generic augmentation menu.
Separate identity from similarity
Two photographs of the same parcel are related, yet their relationship can be weaker than two views of the same photograph when a handler rotates or repacks the parcel. Persist parcel IDs, capture time and transformation settings with every pair. This lets auditors distinguish actual invariance from memorized scanner marks. Group and time splits must keep one parcel together.
Budget the unlabeled pool
Unlabeled does not mean unrestricted. Remove unusable images, enforce retention and consent rules, and record the collection period. A pool dominated by one depot can yield a polished pretext metric and poor transfer elsewhere. Compare the later test distribution before paying for long pretraining runs.
Use a small visual audit first
Generate a fixed sample of paired views and ask whether damage evidence survives in both. A simple metadata gate catches known destructive crops; humans still need to inspect hard cases. Only then compare contrastive and masked objectives. Pair construction and masking impose different invariances.
Implementation
view_pairs = [
{"parcel_id": "dock-47", "left_has_damage": True, "right_has_damage": True,
"left_capture": "frame-47a", "right_capture": "frame-47b"},
{"parcel_id": "dock-62", "left_has_damage": True, "right_has_damage": False,
"left_capture": "frame-62a", "right_capture": "crop-62a"},
]
def eligible_pairs(pairs):
accepted, rejected = [], []
for pair in pairs:
if pair["left_has_damage"] != pair["right_has_damage"]:
rejected.append(pair["parcel_id"])
else:
accepted.append((pair["left_capture"], pair["right_capture"]))
return accepted, rejected
accepted, rejected = eligible_pairs(view_pairs)
assert accepted == [("frame-47a", "frame-47b")]
assert rejected == ["dock-62"]Performance and operating cost
The metadata check costs O(P) time for P pairs and O(P) output storage. Producing two image views roughly doubles augmentation work and may double encoder passes per batch. The expensive check is semantic: evidence survival needs sampled human review and slice-specific failure counts.
Common Mistakes
- Do not treat every random crop as label-preserving.
- Do not place different views of one parcel across train and test.
- Do not equate improved pretext loss with improved damage decisions.
