Jayce-Ping commited on
Commit
436c9ff
·
verified ·
1 Parent(s): 7dda0ef

Add files using upload-large-folder tool

Browse files
Files changed (50) hide show
  1. annotator/__pycache__/utils.cpython-312.pyc +0 -0
  2. annotator/annotate.py +237 -0
  3. annotator/data/extended_data_summary_v2.jsonl +0 -0
  4. annotator/templates/index.html +255 -0
  5. annotator/test.ipynb +130 -0
  6. annotator/utils.py +13 -0
  7. images_divided/0005/1_0.png +3 -0
  8. images_divided/0005/1_4.png +3 -0
  9. images_divided/0005/2_0.png +3 -0
  10. images_divided/0005/2_3.png +3 -0
  11. images_divided/0005/3_3.png +3 -0
  12. images_divided/0006/1_1.png +3 -0
  13. images_divided/0006/1_2.png +3 -0
  14. images_divided/0006/2_0.png +3 -0
  15. images_divided/0006/2_1.png +3 -0
  16. images_divided/0006/2_2.png +3 -0
  17. images_divided/0006/3_0.png +3 -0
  18. images_divided/0006/3_1.png +3 -0
  19. images_divided/0006/3_2.png +3 -0
  20. images_divided/0007/0_0.png +3 -0
  21. images_divided/0007/0_1.png +3 -0
  22. images_divided/0007/0_2.png +3 -0
  23. images_divided/0007/0_3.png +3 -0
  24. images_divided/0007/0_4.png +3 -0
  25. images_divided/0007/1_0.png +3 -0
  26. images_divided/0007/1_1.png +3 -0
  27. images_divided/0007/1_2.png +3 -0
  28. images_divided/0007/1_3.png +3 -0
  29. images_divided/0007/2_0.png +3 -0
  30. images_divided/0007/2_1.png +3 -0
  31. images_divided/0007/2_2.png +3 -0
  32. images_divided/0007/2_3.png +3 -0
  33. images_divided/0007/2_4.png +3 -0
  34. images_divided/0007/3_0.png +3 -0
  35. images_divided/0007/3_1.png +3 -0
  36. images_divided/0007/3_3.png +3 -0
  37. images_divided/0007/3_4.png +3 -0
  38. images_divided/0008/0_0.png +3 -0
  39. images_divided/0008/0_1.png +3 -0
  40. images_divided/0008/0_3.png +3 -0
  41. images_divided/0008/1_0.png +3 -0
  42. images_divided/0008/1_2.png +3 -0
  43. images_divided/0008/2_1.png +3 -0
  44. images_divided/0008/2_3.png +3 -0
  45. images_divided/0008/3_0.png +3 -0
  46. images_divided/0008/3_1.png +3 -0
  47. images_divided/0008/3_3.png +3 -0
  48. images_divided/0009/0_0.png +3 -0
  49. images_divided/0009/0_1.png +3 -0
  50. images_divided/0009/2_0.png +3 -0
annotator/__pycache__/utils.cpython-312.pyc ADDED
Binary file (835 Bytes). View file
 
annotator/annotate.py ADDED
@@ -0,0 +1,237 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import json
3
+ from datetime import datetime
4
+ from utils import divide_prompt
5
+ from flask import Flask, render_template, request, send_from_directory, jsonify
6
+
7
+ app = Flask(__name__)
8
+
9
+ # 设置图像目录路径
10
+ IMAGE_DIR = "../images_divided"
11
+ ITEMS_PER_PAGE = 1 # 每页显示的 data 项目数
12
+ DATA_FILE = "data/annotation.jsonl" # 保存排序结果的文件
13
+ PROMPT_DATA_FILE = 'data/extended_data_summary_v2.jsonl'
14
+
15
+ with open(PROMPT_DATA_FILE, 'r', encoding='utf-8') as f:
16
+ PROMPT_DATA = [json.loads(line) for line in f if line.strip()]
17
+ PROMPT_DATA = {item['idx']: item for item in PROMPT_DATA}
18
+
19
+ @app.route('/')
20
+ def index():
21
+ # 读取所有文件夹
22
+ folders = sorted([
23
+ f for f in os.listdir(IMAGE_DIR)
24
+ if os.path.isdir(os.path.join(IMAGE_DIR, f)) and not f.startswith('.')
25
+ ])
26
+ data = []
27
+
28
+ # 加载已有的标注记录
29
+ existing_records = load_existing_records()
30
+ existing_dict = {}
31
+ for record in existing_records:
32
+ folder = record.get('folder')
33
+ ref_image = record.get('ref_image')
34
+ compare_images = tuple(sorted(record.get('compare_images', []))) # 使用排序后的元组作为键的一部分
35
+ key = (folder, ref_image, compare_images)
36
+ existing_dict[key] = {
37
+ 'compare_images': record.get('compare_images', []),
38
+ 'rank_images': record.get('rank_images', [])
39
+ }
40
+
41
+ for cnt, idx in enumerate(folders):
42
+ folder_path = os.path.join(IMAGE_DIR, idx)
43
+ images = sorted([img for img in os.listdir(folder_path) if img.endswith('.png')])
44
+ first_indices, second_indices = zip(*[
45
+ list(map(int, img.split('.')[0].split('_')))
46
+ for img in images
47
+ ])
48
+ first_indices = sorted(set(first_indices))
49
+ second_indices = sorted(set(second_indices))
50
+
51
+ for i in first_indices:
52
+ for j in second_indices:
53
+ ref_img = f"{i}_{j}.png"
54
+ candidates = [
55
+ [
56
+ f"{x}_{y}.png"
57
+ for x in first_indices
58
+ ]
59
+ for y in second_indices if y != j
60
+ ]
61
+
62
+ items = [
63
+ {
64
+ 'ref_image': f"/images/{idx}/{ref_img}",
65
+ 'compare_images': [f"/images/{idx}/{cand_img}" for cand_img in cand], # 待比较的图像列表
66
+ 'folder': idx,
67
+ 'ref_index': (i, j),
68
+ 'candidate_column': y,
69
+ 'prompt': divide_prompt(PROMPT_DATA[idx]['prompt'])[0] if idx in PROMPT_DATA and 'prompt' in PROMPT_DATA[idx] else '',
70
+ 'existing_compare_images': [], # 临时占位,后面会更新
71
+ 'existing_rank_images': [], # 临时占位,后面会更新
72
+ 'is_annotated': False, # 临时占位,后面会更新
73
+ } for y, cand in zip([y for y in second_indices if y != j], candidates)
74
+ ]
75
+
76
+ # 对每个 item 检查是否已有标注
77
+ for item in items:
78
+ # 从完整路径中提取文件名
79
+ current_compare_images = [img.split('/')[-1] for img in item['compare_images']]
80
+
81
+ # 检查是否已有标注(使用 ref_image 和 compare_images 一起判定)
82
+ ref_filename = item['ref_image'].split('/')[-1]
83
+ lookup_key = (idx, ref_filename, tuple(sorted(current_compare_images)))
84
+ existing_data = existing_dict.get(lookup_key, {})
85
+
86
+ # 更新 item 的标注信息
87
+ item['existing_compare_images'] = existing_data.get('compare_images', [])
88
+ item['existing_rank_images'] = existing_data.get('rank_images', [])
89
+ item['is_annotated'] = len(existing_data.get('rank_images', [])) > 0
90
+
91
+ data.extend(items)
92
+
93
+ # 分页逻辑
94
+ page = int(request.args.get('page', 1))
95
+ start = (page - 1) * ITEMS_PER_PAGE
96
+ end = start + ITEMS_PER_PAGE
97
+ paginated_data = data[start:end]
98
+
99
+ return render_template(
100
+ 'index.html',
101
+ data=paginated_data,
102
+ page=page,
103
+ total_pages=(len(data) + ITEMS_PER_PAGE - 1) // ITEMS_PER_PAGE
104
+ )
105
+
106
+ @app.route('/sort', methods=['POST'])
107
+ def sort_images():
108
+ try:
109
+ # 获取排序后的数据
110
+ sorted_images = request.form.getlist('sorted_images')
111
+
112
+ if not sorted_images:
113
+ return jsonify({'status': 'error', 'message': '没有排序数据'}), 400
114
+
115
+ # 解析排序数据
116
+ ranking = []
117
+ for item in sorted_images:
118
+ rank, image_path = item.split(':', 1)
119
+ ranking.append({
120
+ 'rank': int(rank),
121
+ 'image_path': image_path
122
+ })
123
+
124
+ # 排序以确保顺序正确
125
+ ranking.sort(key=lambda x: x['rank'])
126
+
127
+ # 提取有用信息
128
+ if ranking:
129
+ first_image = ranking[0]['image_path']
130
+ parts = first_image.split('/')
131
+ folder = parts[2] # folder_name
132
+
133
+ # 获取参考图像信息(从表单中)
134
+ ref_image = request.form.get('ref_image', '')
135
+
136
+ # 解析参考图像文件名
137
+ ref_filename = ref_image.split('/')[-1] # x_y.png
138
+
139
+ # 获取原始的 compare_images(所有候选图像的原始顺序)
140
+ all_compare_images = request.form.get('all_compare_images', '')
141
+ if all_compare_images:
142
+ all_compare_images = json.loads(all_compare_images)
143
+ else:
144
+ all_compare_images = []
145
+
146
+ # 解析排序图像的文件名 - 这是用户的排序结果
147
+ ranked_filenames = []
148
+ for item in ranking:
149
+ filename = item['image_path'].split('/')[-1]
150
+ ranked_filenames.append(filename)
151
+
152
+ # 创建唯一的数据记录
153
+ record = {
154
+ 'folder': folder,
155
+ 'ref_image': ref_filename,
156
+ 'compare_images': all_compare_images, # 原始顺序的所有候选图像
157
+ 'rank_images': ranked_filenames, # 用户的排序结果
158
+ 'timestamp': datetime.now().isoformat()
159
+ }
160
+
161
+ # 读取现有数据以检查唯一性
162
+ existing_records = load_existing_records()
163
+
164
+ # 检查是否已存在相同的记录(基于 folder, ref_image 和 compare_images)
165
+ updated = False
166
+ for i, existing in enumerate(existing_records):
167
+ existing_compare_sorted = tuple(sorted(existing.get('compare_images', [])))
168
+ current_compare_sorted = tuple(sorted(all_compare_images))
169
+
170
+ if (existing.get('folder') == folder and
171
+ existing.get('ref_image') == ref_filename and
172
+ existing_compare_sorted == current_compare_sorted):
173
+ # 更新现有记录
174
+ existing_records[i] = record
175
+ updated = True
176
+ break
177
+
178
+ if not updated:
179
+ # 添加新记录
180
+ existing_records.append(record)
181
+
182
+ # 保存到文件
183
+ save_records(existing_records)
184
+
185
+ print(f"{'更新' if updated else '添加'}排序记录:", record)
186
+
187
+ return jsonify({
188
+ 'status': 'success',
189
+ 'message': f"排序已{'更新' if updated else '保存'}!",
190
+ 'record': record
191
+ })
192
+
193
+ except Exception as e:
194
+ print(f"错误: {str(e)}")
195
+ import traceback
196
+ traceback.print_exc()
197
+ return jsonify({'status': 'error', 'message': str(e)}), 500
198
+
199
+ def load_existing_records():
200
+ """加载现有的记录"""
201
+ if not os.path.exists(DATA_FILE):
202
+ return []
203
+
204
+ records = []
205
+ with open(DATA_FILE, 'r', encoding='utf-8') as f:
206
+ for line in f:
207
+ line = line.strip()
208
+ if line:
209
+ records.append(json.loads(line))
210
+ return records
211
+
212
+ def save_records(records):
213
+ """保存记录到JSONL文件"""
214
+ # 确保目录存在
215
+ os.makedirs(os.path.dirname(DATA_FILE), exist_ok=True)
216
+
217
+ with open(DATA_FILE, 'w', encoding='utf-8') as f:
218
+ for record in records:
219
+ f.write(json.dumps(record, ensure_ascii=False) + '\n')
220
+
221
+ # 添加一个路由来提供图片文件
222
+ @app.route('/images/<path:filename>')
223
+ def serve_images(filename):
224
+ return send_from_directory(IMAGE_DIR, filename)
225
+
226
+ # 添加一个查看已保存数据的路由
227
+ @app.route('/view_data')
228
+ def view_data():
229
+ """查看已保存的排序数据"""
230
+ records = load_existing_records()
231
+ return jsonify({
232
+ 'total': len(records),
233
+ 'records': records
234
+ })
235
+
236
+ if __name__ == '__main__':
237
+ app.run(debug=True)
annotator/data/extended_data_summary_v2.jsonl ADDED
The diff for this file is too large to render. See raw diff
 
annotator/templates/index.html ADDED
@@ -0,0 +1,255 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Image Ranking</title>
7
+ <style>
8
+ body {
9
+ font-family: Arial, sans-serif;
10
+ padding: 20px;
11
+ }
12
+
13
+ .rank-btn {
14
+ padding: 5px 15px;
15
+ cursor: pointer;
16
+ border: 2px solid #4CAF50;
17
+ background-color: white;
18
+ color: #4CAF50;
19
+ border-radius: 4px;
20
+ font-weight: bold;
21
+ min-width: 60px;
22
+ }
23
+ .rank-btn.ranked {
24
+ background-color: #4CAF50;
25
+ color: white;
26
+ border-color: #4CAF50;
27
+ }
28
+ .rank-btn:hover {
29
+ opacity: 0.8;
30
+ }
31
+ .submit-btn {
32
+ margin-top: 20px;
33
+ padding: 10px 30px;
34
+ background-color: #2196F3;
35
+ color: white;
36
+ border: none;
37
+ border-radius: 4px;
38
+ cursor: pointer;
39
+ font-size: 16px;
40
+ }
41
+ .submit-btn:hover {
42
+ background-color: #0b7dda;
43
+ }
44
+ .submit-btn:disabled {
45
+ background-color: #cccccc;
46
+ cursor: not-allowed;
47
+ }
48
+ .show-annotation-btn {
49
+ margin-top: 10px;
50
+ padding: 8px 20px;
51
+ background-color: #FF9800;
52
+ color: white;
53
+ border: none;
54
+ border-radius: 4px;
55
+ cursor: pointer;
56
+ font-size: 14px;
57
+ }
58
+ .show-annotation-btn:hover {
59
+ background-color: #F57C00;
60
+ }
61
+ .annotation-status {
62
+ display: inline-block;
63
+ margin-left: 15px;
64
+ padding: 5px 12px;
65
+ background-color: #4CAF50;
66
+ color: white;
67
+ border-radius: 4px;
68
+ font-size: 14px;
69
+ font-weight: bold;
70
+ }
71
+ /* 消息提示样式 */
72
+ .message-box {
73
+ position: fixed;
74
+ top: 20px;
75
+ right: 20px;
76
+ padding: 15px 25px;
77
+ border-radius: 4px;
78
+ font-size: 16px;
79
+ font-weight: bold;
80
+ box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
81
+ z-index: 1000;
82
+ display: none;
83
+ animation: slideIn 0.3s ease-out;
84
+ }
85
+ .message-box.success {
86
+ background-color: #4CAF50;
87
+ color: white;
88
+ }
89
+ .message-box.error {
90
+ background-color: #f44336;
91
+ color: white;
92
+ }
93
+ .message-box.show {
94
+ display: block;
95
+ }
96
+ @keyframes slideIn {
97
+ from {
98
+ transform: translateX(100%);
99
+ opacity: 0;
100
+ }
101
+ to {
102
+ transform: translateX(0);
103
+ opacity: 1;
104
+ }
105
+ }
106
+ @keyframes slideOut {
107
+ from {
108
+ transform: translateX(0);
109
+ opacity: 1;
110
+ }
111
+ to {
112
+ transform: translateX(100%);
113
+ opacity: 0;
114
+ }
115
+ }
116
+ .message-box.hiding {
117
+ animation: slideOut 0.3s ease-out;
118
+ }
119
+
120
+ /* 固定在右上角的分页条 */
121
+ .page-control {
122
+ position: fixed;
123
+ top: 20px;
124
+ right: 20px;
125
+ background: rgba(255,255,255,0.9);
126
+ border: 1px solid #ddd;
127
+ padding: 8px 12px;
128
+ border-radius: 6px;
129
+ box-shadow: 0 2px 6px rgba(0,0,0,0.1);
130
+ z-index: 999;
131
+ display: flex;
132
+ align-items: center;
133
+ gap: 8px;
134
+ font-size: 14px;
135
+ }
136
+ .page-control input {
137
+ width: 60px;
138
+ padding: 3px 5px;
139
+ border: 1px solid #ccc;
140
+ border-radius: 4px;
141
+ }
142
+ .page-control button {
143
+ padding: 4px 8px;
144
+ background-color: #2196F3;
145
+ color: white;
146
+ border: none;
147
+ border-radius: 4px;
148
+ cursor: pointer;
149
+ }
150
+ .page-control button:hover {
151
+ background-color: #0b7dda;
152
+ }
153
+ </style>
154
+ <script>
155
+ let rankCounter = 1;
156
+ const rankedImages = new Map();
157
+ let allCompareImages = [];
158
+
159
+ function initializeCompareImages() {
160
+ allCompareImages = [];
161
+ const rankButtons = document.querySelectorAll('.rank-btn');
162
+ rankButtons.forEach(btn => {
163
+ const imagePath = btn.getAttribute('data-image');
164
+ const filename = imagePath.split('/').pop();
165
+ if (!allCompareImages.includes(filename)) {
166
+ allCompareImages.push(filename);
167
+ }
168
+ });
169
+ }
170
+ window.addEventListener('DOMContentLoaded', function() {
171
+ initializeCompareImages();
172
+ });
173
+
174
+ /* 这里省略 rankImage、loadExistingAnnotation、showMessage、submitRanking 的原有实现 */
175
+ /* ... 你的原始脚本保持不变 ... */
176
+
177
+ // 新增跳转函数
178
+ function jumpToPage(event) {
179
+ event.preventDefault();
180
+ const input = document.getElementById('pageInput');
181
+ let page = parseInt(input.value);
182
+ if (isNaN(page) || page < 1) page = 1;
183
+ if (page > {{ total_pages }}) page = {{ total_pages }};
184
+ window.location.href = "/?page=" + page;
185
+ return false;
186
+ }
187
+ </script>
188
+ </head>
189
+ <body>
190
+ <!-- 消息提示框 -->
191
+ <div id="messageBox" class="message-box"></div>
192
+
193
+ <!-- 固定在右上角的分页控制条 -->
194
+ <div class="page-control">
195
+ <span>{{ page }}/{{ total_pages }}</span>
196
+ <form id="pageJumpForm" onsubmit="return jumpToPage(event)" style="display:inline;">
197
+ <input type="number" id="pageInput" min="1" max="{{ total_pages }}" value="{{ page }}">
198
+ <button type="submit">跳转</button>
199
+ </form>
200
+ </div>
201
+
202
+ <h1>Image Ranking</h1>
203
+ <form id="rankingForm" action="/sort" method="POST" onsubmit="return submitRanking(event)">
204
+ {% for item in data %}
205
+ <div>
206
+ {% if item.prompt %}
207
+ <div style="background-color: #f0f0f0; padding: 15px; margin-bottom: 20px; border-radius: 4px; border-left: 4px solid #2196F3;">
208
+ <h2 style="margin-top: 0; color: #333;">Prompt:</h2>
209
+ <p style="font-size: 16px; line-height: 1.6; margin-bottom: 0; color: #555;">{{ item.prompt }}</p>
210
+ </div>
211
+ {% endif %}
212
+ <h3>Reference Image: {{ item.ref_image }}
213
+ {% if item.is_annotated %}
214
+ <span class="annotation-status">已标注</span>
215
+ {% endif %}
216
+ </h3>
217
+ <p>Folder: {{ item.folder }}</p>
218
+ <img src="{{ item.ref_image }}" alt="ref_image" width="200">
219
+ <input type="hidden" name="ref_image" value="{{ item.ref_image }}">
220
+ {% if item.is_annotated %}
221
+ <button type="button" class="show-annotation-btn"
222
+ data-loaded="false"
223
+ onclick='loadExistingAnnotation(this, "{{ item.folder }}", "{{ item.ref_image.split("/")[-1] }}", {{ item.existing_rank_images|tojson|safe }})'>
224
+ 显示已有标注
225
+ </button>
226
+ {% endif %}
227
+ <h4>Compare Images:</h4>
228
+ <div style="display: flex; gap: 15px; flex-wrap: wrap; align-items: flex-start;">
229
+ {% for compare_image in item.compare_images %}
230
+ <div class="image-item" style="display: flex; flex-direction: column; align-items: center; gap: 5px;">
231
+ <img src="{{ compare_image }}" alt="compare_image" width="100">
232
+ <button type="button"
233
+ class="rank-btn"
234
+ data-image="{{ compare_image }}"
235
+ onclick="rankImage(this, '{{ compare_image }}')">
236
+ 排序
237
+ </button>
238
+ </div>
239
+ {% endfor %}
240
+ </div>
241
+ </div>
242
+ {% endfor %}
243
+ <button type="submit" class="submit-btn">提交排序</button>
244
+ </form>
245
+
246
+ <div style="margin-top: 20px;">
247
+ {% if page > 1 %}
248
+ <a href="/?page={{ page - 1 }}" style="margin-right: 10px;">上一页</a>
249
+ {% endif %}
250
+ {% if page < total_pages %}
251
+ <a href="/?page={{ page + 1 }}">下一页</a>
252
+ {% endif %}
253
+ </div>
254
+ </body>
255
+ </html>
annotator/test.ipynb ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 16,
6
+ "id": "5bdfe87c",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "import os\n",
11
+ "import json\n",
12
+ "from itertools import combinations\n",
13
+ "IMAGE_DIR = \"/root/siton-tmp/images_divided\""
14
+ ]
15
+ },
16
+ {
17
+ "cell_type": "code",
18
+ "execution_count": null,
19
+ "id": "fb8c9036",
20
+ "metadata": {},
21
+ "outputs": [],
22
+ "source": [
23
+ "folders = sorted([\n",
24
+ " f for f in os.listdir(IMAGE_DIR)\n",
25
+ " if os.path.isdir(os.path.join(IMAGE_DIR, f)) and not f.startswith('.')\n",
26
+ "])\n",
27
+ "data = []\n",
28
+ "for cnt, idx in enumerate(folders):\n",
29
+ " folder_path = os.path.join(IMAGE_DIR, idx)\n",
30
+ " images = sorted([img for img in os.listdir(folder_path) if img.endswith('.png')])\n",
31
+ " first_indices, second_indices = zip(*[\n",
32
+ " list(map(int, img.split('.')[0].split('_')))\n",
33
+ " for img in images\n",
34
+ " ])\n",
35
+ " first_indices = sorted(set(first_indices))\n",
36
+ " second_indices = sorted(set(second_indices))\n",
37
+ " \n",
38
+ " for i in first_indices:\n",
39
+ " for j in second_indices:\n",
40
+ " ref_img = f\"{i}_{j}.png\"\n",
41
+ " candidates = [\n",
42
+ " [\n",
43
+ " f\"{x}_{y}.png\"\n",
44
+ " for x in first_indices\n",
45
+ " ]\n",
46
+ " for y in second_indices if y != j\n",
47
+ " ]\n",
48
+ " items = [\n",
49
+ " {\n",
50
+ " 'ref_image': ref_img,\n",
51
+ " 'rank_images': cand,\n",
52
+ " 'idx': idx,\n",
53
+ " } for cand in candidates\n",
54
+ " ]\n",
55
+ " data.extend(items)\n"
56
+ ]
57
+ },
58
+ {
59
+ "cell_type": "code",
60
+ "execution_count": 19,
61
+ "id": "36e0603b",
62
+ "metadata": {},
63
+ "outputs": [
64
+ {
65
+ "data": {
66
+ "text/plain": [
67
+ "[{'ref_image': '0_0.png',\n",
68
+ " 'rank_images': ['0_1.png', '1_1.png', '2_1.png', '3_1.png'],\n",
69
+ " 'idx': '0000'},\n",
70
+ " {'ref_image': '0_0.png',\n",
71
+ " 'rank_images': ['0_2.png', '1_2.png', '2_2.png', '3_2.png'],\n",
72
+ " 'idx': '0000'},\n",
73
+ " {'ref_image': '0_1.png',\n",
74
+ " 'rank_images': ['0_0.png', '1_0.png', '2_0.png', '3_0.png'],\n",
75
+ " 'idx': '0000'},\n",
76
+ " {'ref_image': '0_1.png',\n",
77
+ " 'rank_images': ['0_2.png', '1_2.png', '2_2.png', '3_2.png'],\n",
78
+ " 'idx': '0000'},\n",
79
+ " {'ref_image': '0_2.png',\n",
80
+ " 'rank_images': ['0_0.png', '1_0.png', '2_0.png', '3_0.png'],\n",
81
+ " 'idx': '0000'},\n",
82
+ " {'ref_image': '0_2.png',\n",
83
+ " 'rank_images': ['0_1.png', '1_1.png', '2_1.png', '3_1.png'],\n",
84
+ " 'idx': '0000'},\n",
85
+ " {'ref_image': '1_0.png',\n",
86
+ " 'rank_images': ['0_1.png', '1_1.png', '2_1.png', '3_1.png'],\n",
87
+ " 'idx': '0000'},\n",
88
+ " {'ref_image': '1_0.png',\n",
89
+ " 'rank_images': ['0_2.png', '1_2.png', '2_2.png', '3_2.png'],\n",
90
+ " 'idx': '0000'},\n",
91
+ " {'ref_image': '1_1.png',\n",
92
+ " 'rank_images': ['0_0.png', '1_0.png', '2_0.png', '3_0.png'],\n",
93
+ " 'idx': '0000'},\n",
94
+ " {'ref_image': '1_1.png',\n",
95
+ " 'rank_images': ['0_2.png', '1_2.png', '2_2.png', '3_2.png'],\n",
96
+ " 'idx': '0000'}]"
97
+ ]
98
+ },
99
+ "execution_count": 19,
100
+ "metadata": {},
101
+ "output_type": "execute_result"
102
+ }
103
+ ],
104
+ "source": [
105
+ "data[:10]"
106
+ ]
107
+ }
108
+ ],
109
+ "metadata": {
110
+ "kernelspec": {
111
+ "display_name": "pytorch-env",
112
+ "language": "python",
113
+ "name": "python3"
114
+ },
115
+ "language_info": {
116
+ "codemirror_mode": {
117
+ "name": "ipython",
118
+ "version": 3
119
+ },
120
+ "file_extension": ".py",
121
+ "mimetype": "text/x-python",
122
+ "name": "python",
123
+ "nbconvert_exporter": "python",
124
+ "pygments_lexer": "ipython3",
125
+ "version": "3.12.11"
126
+ }
127
+ },
128
+ "nbformat": 4,
129
+ "nbformat_minor": 5
130
+ }
annotator/utils.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+
3
+
4
+ def divide_prompt(prompt):
5
+ # seqis like ". [TOP-LEFT]:"
6
+ match_sep = re.compile(r"\.\s+[A-Z0-9-\[\]]+:")
7
+ seps = match_sep.findall(prompt)
8
+ # Add '.' for each sentence
9
+ sub_prompts = [
10
+ p + '.' if p.strip()[-1] != '.' else p
11
+ for p in re.split('|'.join(map(re.escape, seps)), prompt)
12
+ ]
13
+ return sub_prompts
images_divided/0005/1_0.png ADDED

Git LFS Details

  • SHA256: 2a2d8808f6008724f82e6824b8ae64d44aa3021cdba269173bf823119bc60916
  • Pointer size: 131 Bytes
  • Size of remote file: 342 kB
images_divided/0005/1_4.png ADDED

Git LFS Details

  • SHA256: 3c2ac47ef0313a5645e33a3ec62f04c8306fac86847c43f1535dba9bdc1394f2
  • Pointer size: 131 Bytes
  • Size of remote file: 364 kB
images_divided/0005/2_0.png ADDED

Git LFS Details

  • SHA256: 7e71dc0181d91cc6ecc287f6a5ecc62c59ea56be0687555d01670547baf98f86
  • Pointer size: 131 Bytes
  • Size of remote file: 345 kB
images_divided/0005/2_3.png ADDED

Git LFS Details

  • SHA256: 1be993aca391ee3ecc949ad3d5805fedacec2f1848010a7ee867f32193e1c648
  • Pointer size: 131 Bytes
  • Size of remote file: 377 kB
images_divided/0005/3_3.png ADDED

Git LFS Details

  • SHA256: 9a856438fac471a6a730abfc0f3f2474c41173a13663b68ffa566af17329b5cf
  • Pointer size: 131 Bytes
  • Size of remote file: 291 kB
images_divided/0006/1_1.png ADDED

Git LFS Details

  • SHA256: a1ef250ffd671c617c8dbef4ca9fa480657e6f6049897d03ba4516d46fb9596f
  • Pointer size: 131 Bytes
  • Size of remote file: 403 kB
images_divided/0006/1_2.png ADDED

Git LFS Details

  • SHA256: a410629da4843793005a0a49064ba9dbc2f75af4a75abdd2db613b20c8d9f999
  • Pointer size: 131 Bytes
  • Size of remote file: 394 kB
images_divided/0006/2_0.png ADDED

Git LFS Details

  • SHA256: 2fbb79fa7cb63eb6056392823740af9c95292cac2796365f83bba1fce554648c
  • Pointer size: 131 Bytes
  • Size of remote file: 320 kB
images_divided/0006/2_1.png ADDED

Git LFS Details

  • SHA256: 8ce41e5b21ff64b3985624076ba0291a4cc21044a2ede4285ededcd3c2b62e42
  • Pointer size: 131 Bytes
  • Size of remote file: 412 kB
images_divided/0006/2_2.png ADDED

Git LFS Details

  • SHA256: 492ea894c51c239e68e52a262ea9cb40ac2b3916212eb854a95fd4374641ce6f
  • Pointer size: 131 Bytes
  • Size of remote file: 381 kB
images_divided/0006/3_0.png ADDED

Git LFS Details

  • SHA256: 015eca21c98c2f4b50e6fcceb412c99906d39d1de712f7342e7ecb8073bb62d2
  • Pointer size: 131 Bytes
  • Size of remote file: 339 kB
images_divided/0006/3_1.png ADDED

Git LFS Details

  • SHA256: 4997cd4e341740242c7696da8a0739c703cf8d1aa3511334322ea96661b42dc6
  • Pointer size: 131 Bytes
  • Size of remote file: 417 kB
images_divided/0006/3_2.png ADDED

Git LFS Details

  • SHA256: 81f15af816f2508588b18a4c05eeb3a69ad98a9a134fb9db284096f4ddf1cb8a
  • Pointer size: 131 Bytes
  • Size of remote file: 391 kB
images_divided/0007/0_0.png ADDED

Git LFS Details

  • SHA256: 9243696222bf4fd76bb3bbb29bb49241d5f47a23a1107240cbb18edabbe4e4cd
  • Pointer size: 131 Bytes
  • Size of remote file: 378 kB
images_divided/0007/0_1.png ADDED

Git LFS Details

  • SHA256: 0ab74a630cc0cee624acba11418a0500334e5935e3eedc2c70f2398f4cc07bed
  • Pointer size: 131 Bytes
  • Size of remote file: 398 kB
images_divided/0007/0_2.png ADDED

Git LFS Details

  • SHA256: 08f0fd209fa50601ee8ef72949d695184bbab7d23edd2e629c1e46892889be99
  • Pointer size: 131 Bytes
  • Size of remote file: 340 kB
images_divided/0007/0_3.png ADDED

Git LFS Details

  • SHA256: 0d26df36eb6be812d9e18ccdad7ca9d5cba3b9679eca351c6034a8834ee0f9b6
  • Pointer size: 131 Bytes
  • Size of remote file: 327 kB
images_divided/0007/0_4.png ADDED

Git LFS Details

  • SHA256: fd7b0324ba0ed481e5f9c648801d3a21cefd23bbe75f63287778e1bee1d0a4a4
  • Pointer size: 131 Bytes
  • Size of remote file: 377 kB
images_divided/0007/1_0.png ADDED

Git LFS Details

  • SHA256: aaa2954a966a0b5c06be32aae931353896f4d51541d8912db6ad255a20273bb4
  • Pointer size: 131 Bytes
  • Size of remote file: 411 kB
images_divided/0007/1_1.png ADDED

Git LFS Details

  • SHA256: fe45decd991d108bb7853f0788108299742d0cd2952282ff8334549ec0c17082
  • Pointer size: 131 Bytes
  • Size of remote file: 386 kB
images_divided/0007/1_2.png ADDED

Git LFS Details

  • SHA256: c3092a457d1e2f00e89cdad5e194ebd95c1a61429537e4699d96805ac63f366d
  • Pointer size: 131 Bytes
  • Size of remote file: 382 kB
images_divided/0007/1_3.png ADDED

Git LFS Details

  • SHA256: a1794ab74bc3939908698f7f71a14cebf487322dbfd0f01dfdced83cf8d9a0a7
  • Pointer size: 131 Bytes
  • Size of remote file: 344 kB
images_divided/0007/2_0.png ADDED

Git LFS Details

  • SHA256: 7bd431151ed46fd00537f014d8b7827e98adf151e9f37142913c2c71a026c6b6
  • Pointer size: 131 Bytes
  • Size of remote file: 397 kB
images_divided/0007/2_1.png ADDED

Git LFS Details

  • SHA256: 7f139043da4ebb301a3cbcd094abb591bc76731478a4bf994df9aca5c65704aa
  • Pointer size: 131 Bytes
  • Size of remote file: 408 kB
images_divided/0007/2_2.png ADDED

Git LFS Details

  • SHA256: 7165724003783129bffe9a880691c6a3962795c0f97168eccbd6d9d6a8fdc4a3
  • Pointer size: 131 Bytes
  • Size of remote file: 363 kB
images_divided/0007/2_3.png ADDED

Git LFS Details

  • SHA256: 902b475a7f5e91366827a949ab226fc78bdc6130405732544ecd7402c1bebace
  • Pointer size: 131 Bytes
  • Size of remote file: 327 kB
images_divided/0007/2_4.png ADDED

Git LFS Details

  • SHA256: a26d3c69b9053f24de8b27447b052dcd2104d6474c5c559d4cb2f203b279a670
  • Pointer size: 131 Bytes
  • Size of remote file: 341 kB
images_divided/0007/3_0.png ADDED

Git LFS Details

  • SHA256: ed07931d2810cf5bfb6a9ecbbb1ab5832ded8eb92ee7cde0f33f7424300153ee
  • Pointer size: 131 Bytes
  • Size of remote file: 426 kB
images_divided/0007/3_1.png ADDED

Git LFS Details

  • SHA256: 66ae05c0c0ec0baf6acc7d188feb77514fc6fcf6aead87366c9f526414f7dfd6
  • Pointer size: 131 Bytes
  • Size of remote file: 395 kB
images_divided/0007/3_3.png ADDED

Git LFS Details

  • SHA256: d28909e05341688b398b459daf61e1bb89fe46ac176f769476030367729b69c5
  • Pointer size: 131 Bytes
  • Size of remote file: 381 kB
images_divided/0007/3_4.png ADDED

Git LFS Details

  • SHA256: 46584e9dde9a631e922755609a1de9b82242bf5fa1e8585e687f5edb32cfc4e9
  • Pointer size: 131 Bytes
  • Size of remote file: 373 kB
images_divided/0008/0_0.png ADDED

Git LFS Details

  • SHA256: 365b272326577c2c261aea6858fbc0c1b19226a90ac6f27dc79f96a4dda4bf3f
  • Pointer size: 131 Bytes
  • Size of remote file: 405 kB
images_divided/0008/0_1.png ADDED

Git LFS Details

  • SHA256: 782eef82736865130770242821727d9f77de6be4719e42173fb55b8a12b95135
  • Pointer size: 131 Bytes
  • Size of remote file: 382 kB
images_divided/0008/0_3.png ADDED

Git LFS Details

  • SHA256: 7f53e6e8fa394c11db6fbb9043f788e91daa70824ce5a5035961d4d78364e9d7
  • Pointer size: 131 Bytes
  • Size of remote file: 370 kB
images_divided/0008/1_0.png ADDED

Git LFS Details

  • SHA256: 12b70982e62075ca3fe10af7cc8324b40548bfb20d57029384cf5fe0b34479b0
  • Pointer size: 131 Bytes
  • Size of remote file: 386 kB
images_divided/0008/1_2.png ADDED

Git LFS Details

  • SHA256: a90d77cd87b4d10b351a1f7235c3dd5ec346737d00e95121703f409b4c82c648
  • Pointer size: 131 Bytes
  • Size of remote file: 352 kB
images_divided/0008/2_1.png ADDED

Git LFS Details

  • SHA256: 300dddbfc7d3475842959811c6099b3449b4b89bc28524672e2a50ce3f407a34
  • Pointer size: 131 Bytes
  • Size of remote file: 397 kB
images_divided/0008/2_3.png ADDED

Git LFS Details

  • SHA256: e90143e1f3b9c1694e44c2f6214e53d436d18ce3f65bf008031ac37454d96453
  • Pointer size: 131 Bytes
  • Size of remote file: 343 kB
images_divided/0008/3_0.png ADDED

Git LFS Details

  • SHA256: e558a5a3f55c61eadcb06f9f00aba210c97981b025e244df452fc8be586ef161
  • Pointer size: 131 Bytes
  • Size of remote file: 388 kB
images_divided/0008/3_1.png ADDED

Git LFS Details

  • SHA256: 3a220e30104554952785b445aea75c10bbcefcf07c2888e37e96b9a4c7aab74a
  • Pointer size: 131 Bytes
  • Size of remote file: 382 kB
images_divided/0008/3_3.png ADDED

Git LFS Details

  • SHA256: e64183faadf2e73329587c4bbe35ab3c825f46a847d5f712dbc229c7bbb9c3f4
  • Pointer size: 131 Bytes
  • Size of remote file: 380 kB
images_divided/0009/0_0.png ADDED

Git LFS Details

  • SHA256: 38a9bd9e7e8c50e7d19e2f5183f29225f3ff28312655f45d0580dc0134e7e355
  • Pointer size: 131 Bytes
  • Size of remote file: 316 kB
images_divided/0009/0_1.png ADDED

Git LFS Details

  • SHA256: a8fa01afb3f1f1747fb260c5ae0c74d356d8ce44157d9a26ee7457cd95afdcbd
  • Pointer size: 131 Bytes
  • Size of remote file: 324 kB
images_divided/0009/2_0.png ADDED

Git LFS Details

  • SHA256: 8c738d61e6d05f3575704ca51541fb2c6903ddb60cf3c4fe03a9b59de26f2265
  • Pointer size: 131 Bytes
  • Size of remote file: 308 kB