Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/training/metaclip_wds.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ def __iter__(self):
shard_id = self._get_next_shard_id(shard_id)
continue

if hasattr(self.args, "online_curation"):
with open(f"{self.args.online_curation}/{shard_id % 100}/{shard_id}.json") as f:
online_txts = json.load(f)

with tarfile.open(tarball_path) as tar:
members = tar.getmembers()

Expand All @@ -75,19 +79,28 @@ def __iter__(self):
for member in members:
if member.name.endswith(".json"):
json_uuid = member.name[:-len(".json")]
if json_uuid.startswith("./"):
json_uuid = json_uuid[len('./'):]
with tar.extractfile(member) as f:
text_json = json.load(f)

if member.name.endswith(".jpeg"):
img_uuid = member.name[:-len(".jpeg")]
if img_uuid.startswith("./"):
img_uuid = img_uuid[len('./'):]
with tar.extractfile(member) as f:
img = f.read()

if img_uuid != json_uuid:
# assume uuid is json even and img ord;
continue

txt = random.choice(text_json["texts"])[1]
if hasattr(self.args, "online_curation"):
txt, prob = random.choice(online_txts[json_uuid])
if prob < random.random():
continue
else:
txt = random.choice(text_json["texts"])[1]
txt = self.tokenizer([txt])[0]

with Image.open(BytesIO(img)) as img:
Expand Down