Given an imbalanced multi-label dataset of image tags, write a data pipeline to reweight or sample instances for balanced mini-batch training.
Use PostgreSQL and return a deterministic mini-batch of six tagged images. Compute each image's sampling weight from the frequency of its associated tags, excluding images without a valid tag.
image_id, image_name, sampling_weight, and batch_rankimage_id ascendingbatch_rank ascending| Column | Type | Description |
|---|---|---|
| image_idPK | INT | Unique image identifier |
| image_name | VARCHAR(100) | Image file name |
| Column | Type | Description |
|---|---|---|
| image_tag_idPK | INT | Unique image-tag relationship identifier |
| image_id | INT | Referenced image identifier |
| tag_id | INT | Image tag identifier; null indicates an invalid or missing tag |