Datasets:
Tasks:
Image Classification
Formats:
imagefolder
Sub-tasks:
multi-class-classification
Languages:
English
Size:
1K - 10K
License:
File size: 1,227 Bytes
222d39c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
import json
import re
def sort_pairs_by_ai_image(input_path, output_path):
# '..._<์ซ์1>_<์ซ์2>.jpg' ํจํด: prefix๋ ์ซ์1 ์ ๊น์ง ์ ๋ถ
pattern = re.compile(r"(.+)_(\d+)_(\d+)\.jpg$")
entries = []
# 1. ์ฝ์ด์ (prefix, num1, num2, entry)๋ก ์ ์ฅ
with open(input_path, 'r', encoding='utf-8') as infile:
for line in infile:
entry = json.loads(line)
ai_img = entry.get('ai_image', '')
m = pattern.match(ai_img)
if m:
prefix, num1, num2 = m.groups()
entries.append((prefix, int(num1), int(num2), entry))
else:
# ํจํด ์ ๋ง์ผ๋ฉด ๋งจ ๋ค๋ก
entries.append((ai_img, float('inf'), float('inf'), entry))
# 2. (prefix, num1, num2) ์์๋ก ์ ๋ ฌ
entries.sort(key=lambda x: (x[0], x[1], x[2]))
# 3. new_pairs.jsonl์ ๊ธฐ๋ก
with open(output_path, 'w', encoding='utf-8') as outfile:
for _, _, _, entry in entries:
outfile.write(json.dumps(entry, ensure_ascii=False) + '\n')
if __name__ == "__main__":
sort_pairs_by_ai_image("pairs.jsonl", "new_pairs.jsonl")
print("โ
new_pairs.jsonl ์์ฑ ์๋ฃํ์ด! ๐") |